我正在使用 Kaiser 窗口在 Matlab 中设计 FIR 滤波器。我需要用 x 轴作为频率(以赫兹为单位)绘制滤波器的幅度和相位响应,而不是用归一化的角频率绘制它们。这样做,返回的 wn 等于 0.34 (由kaiserord()
)返回,当我将其转换为赫兹时,它会根据需要为我提供 42.5 Hz。
我的问题是,当我绘制幅度响应时,-3dB 点出现在 100 Hz 以上的频率处,这意味着截止频率不等于 42.5 Hz。那么我的代码有什么问题?这是代码(具有所需的过滤器规格):
fs=250;
fcuts=[40 45]; % passband and stopband frequencies
mags=[1 0]; % The required filter amplitude in these bands (Absolute value not in dB)
devs=[0.23 0.23];% Passband and stopband ripples (Absolute value not in dB)
[N,wn,beta,ftype]=kaiserord(fcuts,mags,devs,fs); % using kaiser window for designing the fir filter . This function will return the cuttoff freq. , order of the filter , filter type and betta according to the design specs.
x=fir1(N,wn,ftype,kaiser(N+1,beta)); % designing the corresponding fir filter ( note that fir1 takes an even filter order so we wrote N+1)
[h w]=freqz(x)
f=[w*fs]/2
subplot(2,1,1);
plot(f,20*log10(abs(h))); % we will use 20log10() for ploting the mag. response in dB . abs(h) is the magnitude response
title('magnitude response')
grid on % turning the grid on
set(gca,'YTick',-80:5:0)
xlabel('Frequency(Hz)')
ylabel('Magnitude(dB)')
subplot(2,1,2);
plot(f,rad2deg(angle(h)));
title('phase response')
grid on
%set(gca,'YTick',-100:5:0)
xlabel('Frequency(Hz)')
ylabel('phase(degree)')
编辑:首先 wn=0.34 是否对应于 42.5 Hz?我计算的对吗?
freqz() 有一种形式,它采用采样率并以赫兹而不是弧度为单位返回频率采样点,因此而不是......
[h w]=freqz(x)
f=[w*fs]/2
...你可以做:
[h,f] = freqz(x,1,[],fs)
如果我只是对您的代码进行更改,幅度响应图会显示 -3dB 点。
但是您的原始代码中的问题在于从弧度 (w) 到赫兹 (f) 的转换;你用过:
f=[w*fs]/2
...正确的转换是:
f=[w*fs]/(2*pi)
过滤愉快!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句