![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/328853/image.png)
Designing a fir filter with Parks-McClellan method
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nediljko Ivisic
am 5 Jul. 2020
Kommentiert: Sai Sri Pathuri
am 9 Jul. 2020
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 Kommentare
Akzeptierte Antwort
Sai Sri Pathuri
am 8 Jul. 2020
I assume you are expecting a graph like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/328853/image.png)
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 Kommentare
Sai Sri Pathuri
am 9 Jul. 2020
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;
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multirate Signal Processing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!