我正在学习数字信号处理以实现过滤器,并使用python轻松实现测试思路.所以我刚开始使用scipy.signal库来查找不同滤波器的脉冲响应和频率响应.
目前,我正在阅读"保罗·林恩(1992)的"数字信号,处理器和噪声"一书(并且发现它是学习这些东西的神奇资源).在本书中,他们有一个过滤器,其传递函数如下所示:
我将分子和分母除以 为了得到以下等式:
然后我使用Scipy实现了这个:
NumeratorZcoefs = [1, -1, 1, -1]
DenominatorZcoefs = [1, 0.54048, -0.62519, -0.66354, 0.60317, 0.69341]
FreqResponse = scipy.signal.freqz(NumeratorZcoefs, DenominatorZcoefs)
fig = plt.figure(figsize = [8, 6])
ax = fig.add_subplot(111)
ax.plot(FreqResponse[0], abs(np.array(FreqResponse[1])))
ax.set_xlim(0, 2*np.pi)
ax.set_xlabel("$\Omega$")
Run Code Online (Sandbox Code Playgroud)
并生成如下图:
然而,在本书中,频率响应显示如下:
它们的形状是相同的,但是对于2个地块,在~2.3和0.5处的峰值比率是非常不同的,有人可能会说明为什么会这样吗?
编辑:
为了补充一点,我刚刚实现了一个函数来手动计算频率响应(通过计算函数的极点和零点的距离),并得到与scipy.signal生成的图表类似的比率,但是数字不一样,有谁知道为什么会这样?
实施如下:
def H(omega):
z1 = np.array([0,0]) # zero at 0, 0
z2 = np.array([0,0]) # Another zero at 0, 0
z3 = np.array([0, 1]) # zero at i
z4 = np.array([0, -1]) # zero at -i
z5 = …Run Code Online (Sandbox Code Playgroud) 我想实例化一个 struct 实例,然后在 api 路由中调用该实例的方法。这是我想要的示例,但它会导致错误:
use axum::{http::StatusCode, routing::get, Router, Server};
#[derive(Clone)]
struct Api {
name: String
}
impl Api {
async fn hello(&self) -> Result<String, StatusCode> {
Ok(format!("Hello {}!", self.name))
}
}
#[tokio::main]
async fn main() {
let api = Api { name: "Alice".to_owned() };
let app = Router::new()
.route("/hello-user", get(api.hello));
Server::bind(&([127, 0, 0, 1], 3000).into())
.serve(app.into_make_service())
.await
.unwrap();
}
Run Code Online (Sandbox Code Playgroud)
use axum::{http::StatusCode, routing::get, Router, Server};
#[derive(Clone)]
struct Api {
name: String
}
impl Api {
async fn hello(&self) -> Result<String, …Run Code Online (Sandbox Code Playgroud) 我在使用sympy计算符号表达式的逆拉普拉斯变换时遇到了一些麻烦.在matlab和书中我正在使用表达式s /(s ^ 2 + w ^ 2)转换为cos(wt).
当我尝试使用这样的情感时这样做:
expression = s/(s**2+w**2)
Answer = sympy.inverse_laplace_transform(expression, s, t)
Run Code Online (Sandbox Code Playgroud)
我明白了
Answer = (-I*exp(2*t*im(w))*sin(t*re(w)) + exp(2*t*im(w))*cos(t*re(w)) + I*sin(t*re(w)) + cos(t*re(w)))*exp(-t*im(w))*Heaviside(t)/2
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我在使用 GHDL ( http://ghdl.readthedocs.io/en/latest/ ) 来模拟我的 VHDL 设计时遇到问题。因此,当我使用该命令ghdl -e Averager_tb用 GHDL 编译测试台时,我收到警告:
Averager_tb.VHD:33:3:warning: component instance "uut" is not bound
Averager_tb.VHD:11:14:warning: (in default configuration of averager_tb(behaviour))
Run Code Online (Sandbox Code Playgroud)
要编译用于模拟的测试平台,我使用以下命令:
ghdl -a Averager_tb.VHD # the test bench file is Averager_tb.VHD
ghdl -e Averager_tb # the entity for the test bench is Averager_tb
Run Code Online (Sandbox Code Playgroud)
并且我的设计的输出在整个测试平台中保持不变,我还发现设计中的打印语句没有被执行。
要执行已编译的测试台模拟,我使用以下命令:
ghdl -r Averager_tb
Run Code Online (Sandbox Code Playgroud)
然而,当我使用 Aldec Riviera Pro 2015.06 模拟器在http://www.edaplayground.com上模拟相同的测试平台时,我发现设计中的打印语句被执行并且输出按照我的预期发生变化。
为什么会这样,我该如何解决?
这是我设计中的实体声明
-- Entity Declaration in Design
entity Averager is
port (
clk : in std_logic;
ClockEnable …Run Code Online (Sandbox Code Playgroud) 我有一个随机微分方程 (SDE),我试图使用 Milsteins 方法求解它,但得到的结果与实验不一致。
SDE 是
我已将其分解为 2 个一阶方程:
方程1:
方程2:
然后我使用了 Ito 形式:
所以对于 eq1:
对于 eq2:
我用来尝试解决这个问题的python代码是这样的:
# set constants from real data
Gamma0 = 4000 # defines enviromental damping
Omega0 = 75e3*2*np.pi # defines the angular frequency of the motion
eta = 0 # set eta 0 => no effect from non-linear p*q**2 term
T_0 = 300 # temperature of enviroment
k_b = scipy.constants.Boltzmann
m = 3.1e-19 # mass of oscillator
# set a and b functions …Run Code Online (Sandbox Code Playgroud) 我有一些代码,我从我自己的包运行,程序使用了比它应有的更多的内存(60GB).如何在当前命名空间中打印所有对象的大小(以字节为单位),以便尝试计算出使用此内存的位置?
我尝试了类似的东西
from pympler import asizeof
for objname in dir():
print(asizeof.asizeof(thing)/1024) # print size in kb
Run Code Online (Sandbox Code Playgroud)
但它不起作用,因为它只打印包含命名空间中对象名称的字符串的大小.有没有办法获取对象引用命名空间中的所有内容以便使用此方法,还是有更好的方法来计算使用内存的内容?
我有一些数据,我已经拟合正常分布使用scipy.stats.normal对象拟合函数,如下所示:
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
import matplotlib.mlab as mlab
x = np.random.normal(size=50000)
fig, ax = plt.subplots()
nbins = 75
mu, sigma = norm.fit(x)
n, bins, patches = ax.hist(x,nbins,normed=1,facecolor = 'grey', alpha = 0.5, label='before');
y0 = mlab.normpdf(bins, mu, sigma) # Line of best fit
ax.plot(bins,y0,'k--',linewidth = 2, label='fit before')
ax.set_title('$\mu$={}, $\sigma$={}'.format(mu, sigma))
plt.show()
Run Code Online (Sandbox Code Playgroud)
我现在想要提取拟合mu和sigma值的不确定性/误差.我怎么能这样做?
我按照http://peterdowns.com/posts/first-time-with-pypi.html上的说明将github托管的python包添加到PyPI.但是,当我尝试pip安装它并运行我的setup.py时,我得到了requirements.txt文件丢失.当我从手动下载tarball文件时,https://github.com/<username>/<mypackage>/archive/0.1.tar.gz我发现所有文件都在那里.但是,当我单击我的包的PyPI页面上的下载链接时,它会下载一个.tar.gz存档,该存档只包含python文件,配置文件和它似乎已创建的PKG-INFO文件.
其他文件都不见了,为什么会这样,我该怎么办呢?
python ×6
data-fitting ×1
fpga ×1
gaussian ×1
ghdl ×1
git ×1
github ×1
hdl ×1
memory-leaks ×1
pip ×1
pypi ×1
rust ×1
rust-axum ×1
scipy ×1
size ×1
statistics ×1
stochastic ×1
sympy ×1
vhdl ×1