Designing a fir filter with Parks-McClellan method

조회 수: 8 (최근 30일)
Nediljko Ivisic
Nediljko Ivisic 2020년 7월 5일
댓글: Sai Sri Pathuri 2020년 7월 9일
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.

채택된 답변

Sai Sri Pathuri
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
Nediljko Ivisic
Nediljko Ivisic 2020년 7월 8일
Yes, that was the graph I expected for filter. However, thats not where my problem lies. My problem is the filtered signal. It looks as shown her:
When what I am expecting from filtered signal looks something like this:
Sai Sri Pathuri
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 CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by