Designing a fir filter with Parks-McClellan method
5 次查看(过去 30 天)
显示 更早的评论
Hello, I have a task to designs a bandstop fir filter using parks-mcclellan method, apply it to a signal and show the results. The cutoff frequencys are fp1=0.15 and fp2=0.3 and the signal is x(n)=sin(2*pi*0.2*n)+sin(2*pi*0.1*n), 0<n<128. So far I have wrote this:
clear all;
fs = 10;
fp1 = 0.15;
fp2 = 0.3;
f1 = 0.2;
f2 = 0.1;
t = 128;
n = 0:1/fs:t;
x = sin(2*pi*f1*n) + sin(2*pi*f2*n);
F = [0 0.05 0.15 0.3 0.4 1];
A = [1 1 0 0 1 1];
B = firpm(10, F, A);
[H, w] = freqz(B);
y = filtfilt(B, 1, x);
figure(1)
subplot(2,1,1)
plot(n, x);
subplot(2,1,2)
plot(n, y);
dB = mag2db(abs(H));
figure(2)
subplot(2,1,1)
plot(F, A ,w, abs(H));
subplot(2,1,2)
plot(w, dB);
But I am not getting the output that I want. If anyone knows what I am doing wrong any help would be greatly appreciated.
0 个评论
采纳的回答
Sai Sri Pathuri
2020-7-8
I assume you are expecting a graph like this
You may obtain this by changing w to w/pi while plotting
figure(2)
subplot(2,1,1)
plot(F, A ,w/pi, abs(H));
subplot(2,1,2)
plot(w/pi, dB);
2 个评论
Sai Sri Pathuri
2020-7-9
When you use the frequencies f1 = 0.2 and f2 = 0.1,
normFreq = freq/(fs/2))
then the corresponding normal frequencies are 0.04 and 0.02 respectively. Due to this, when the bandstop filter filters the 0.2 frequency, there is no change in filtered signal because no such frequency existed in your signal.
Try changing the f1, f2 values to
f1 = 1;
f2 = 0.5;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!