MATLAB: Designing a fir filter with Parks-McClellan method

fir filterparks-mcclellan

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.

Best Answer

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);
Related Question