【发布时间】:2017-07-01 09:49:34
【问题描述】:
我正在尝试在 Matlab 中使用 fir2 函数设计一个 FIR,我正在努力获得与我试图实现的幅度函数相对应的滤波器频率响应。
这是我用于滤波器设计的代码,x 是如图所示的幅度响应
fs = 48000; %sample rate
fny = fs/2; %Nyquist frequency
tabs = 512; %tabs
%frequency resolution 1/3 octave, length=28
f = [0 63 80 100 125 160 200 250 315 400 500 630 800 1000 1250 1600
2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000 fny];
fn = f/(fny);
coeffs = fir2(tabs,fn,x);
figure(1);
[freq_response,fc] = freqz(coeffs,tabs);
H = abs(freq_response);
subplot(2,1,1);
semilogx(fc*fny,H, 'r');
hold on;
xlim([20 20000]);
title('frequency response of fir2 filter');
xlabel('frequency [Hz]');
ylabel('magnitude [dB]');
grid on;
set(gca,'XTick',[20 50 100 200 500 1000 2000 5000 10000 20000]);
subplot(2,1,2);
semilogx(f,20*log10(x),'b');
title('desired magnitude function');
xlabel('frequency [Hz]');
ylabel('fir coefficients');
grid on;
xlim([20 20000]);
set(gca,'XTick',[20 50 100 200 500 1000 2000 5000 10000 20000]);
我做错了什么?
【问题讨论】:
标签: matlab audio filter signal-processing