(理解主要就是,将频率滤波的带宽从数字转换到模拟信号,再将相应的技术指标从模拟高通到模拟低通,然后设计一个相应的低通的模拟滤波器,再使用双线性映射到数字低通滤波器)
这里2详细介绍了矩形函数、三角函数与高斯函数的傅立叶变换的推导过程。
设计工具:画出幅度谱与频谱图
N = 512;
H = fft(b,N)./fft(a,N); % H矩阵
mag = 20*log10(abs(H)); % get magnitude of spectrum in dB 幅值
phase = angle(H)*2*pi; % get phase in deg.相位
faxis = fs/2*linspace(0,1,N/2); % the axis of frequency
figure,
subplot(2,1,1),plot(faxis,mag(1:N/2))
xlabel('Frequency (Hz)'),ylabel('Magnitude (dB)')
grid on
subplot(2,1,2),plot(faxis,phase(1:N/2),'r')
xlabel('Frequency (Hz)'),ylabel('Phase (deg.)')
grid on
figure;freqz(b,a) %%这个画出来的信号坐标轴应该乘一个fs采样率
Rp =3; Rs =30 ;%%设计一个带通椭圆数字滤波器 , 通带为 100 ~200 H z,过渡带均为 50 H z,
% 通带波纹小于 3 db ,阻带衰减为 30 db
Wp =2 *[ 100 200] /fs;
Ws = 2 *[ 80 220] /fs;
[ n , Wn] = ellipord (Wp , Ws , Rp , Rs);
[ b , a] = ellip(n , Rp, Rs,Wn);
dataOut = filter(b,a,yc);
figure;NN = length(yc);plot((-NN/2+1:NN/2)/NN*fs,20*log10(abs(fftshift(fft(yc)))),'LineWidth',2);axis([-inf,inf,-inf,inf]);xlabel('fs Hz');ylabel('幅度谱 dB');hold on;
N = length(dataOut);x = (-N/2+1:N/2)/N*fs;semilogy(x , abs(fftshift(fft(dataOut))) ,'r');legend 采样后 滤波后
一、FIR滤波器
加窗过程是对FIR滤波器系数b矩阵进行计算:
w = kaiser(N,beta);
h = b.*w';% 设计的滤波器
mag = freqz(h,[1],omega);
b矩阵相当于“系统的单位冲激响应(时域上)”,而利用freqz函数可以转换到频域上观察幅度谱与相位谱,可以清晰看到滤波器的抖动有所改善。
下面讨论了为什么可以对滤波器系数a、b矩阵进行fft处理。freqz函数的作用是将传递函数/z函数转换成为频域的单位冲激响应。以及为什么需要对h(t)进行加窗。
因此,FIR的系数常常以sinc函数的形式呈现,其傅立叶变换之后在频域上的信号便为类似一个矩阵的形状。
二、IIR滤波器
认为IIR滤波器会有不一样的表现形式。因为其系数是在分母的位置。
H = fft(b,N)./fft(a,N);
import scipy.signal as sig
fs = 44100 # sampling frequency
fc = 1000 # corner frequency of the lowpass
# coefficients of analog lowpass filter 模拟低通滤波器系数
Qinf = 0.8
sinf = 2*np.pi*fc
C = 1e-6
L = 1/(sinf**2*C)
R = sinf*L/Qinf
B = [0, 0, 1]
A = [L*C, R*C, 1]
# cofficients of digital filter
T = 1/fs
b = [T**2, 2*T**2, T**2]
a = [(4*L*C+2*T*R*C+T**2), (-8*L*C+2*T**2), (4*L*C-2*T*R*C+T**2)]
fs2 = 64100
T2 = 1/fs2
b2 = [T2**2, 2*T2**2, T2**2]
a2 = [(4*L*C+2*T2*R*C+T2**2), (-8*L*C+2*T2**2), (4*L*C-2*T2*R*C+T2**2)]
# compute frequency responses
Om, Hd = sig.freqz(b, a, worN=1024)#离散的
Om2, Hd2 = sig.freqz(b2, a2, worN=1024)#离散的
tmp, H = sig.freqs(B, A, worN=fs*Om)# 连续的模拟信号
# plot results
f = Om*fs/(2*np.pi)
plt.figure(figsize=(10, 4))
plt.semilogx(f, 20*np.log10(np.abs(H)),
label=r'$|H(j \omega)|$ of analog filter')
plt.semilogx(f, 20*np.log10(np.abs(Hd)),
label=r'$|H_d(e^{j \Omega})|$ of digital filter fs = 44100')
plt.semilogx(f, 20*np.log10(np.abs(Hd2)),
label=r'$|H_d(e^{j \Omega})|$ of digital filter fs = 64100')
plt.xlabel(r'$f$ in Hz')
plt.ylabel(r'dB')
plt.axis([100, fs/2, -70, 3])
plt.legend()
plt.grid()
可以看到模拟电路的滤波器与数字电路的滤波器有如下的对应关系。此外,当采样频率越高(如下采样率为64100Hz时),其滤波器与模拟电路滤波器越接近。
博客 - 数据处理与滤波器性质 ↩︎
https://blog.csdn.net/qq_22943397/article/details/80301398 ↩︎
参考开源项目digital-signal-processing-lecture-master ↩︎