lowpass() not working

조회 수: 20 (최근 30일)
J B
J B 2020년 7월 31일
댓글: Star Strider 2023년 8월 22일
The title says it all. I have the following code:
Tend = 10e-3;
dt = 100e-9;
t = 0:dt:Tend-dt;
fsig = 500;
sig = 100*sin(2*pi*fsig*t) + 20*sin(2*pi*fsig*100*t);
[sig_filt filter] = lowpass(sig, 1000, 1/dt);
When I plot the signals sig and sig_filt the two curves are almost the same. I tried to reduce the corner frequency from 1000 as above to 10 to 1, it's always the same result. Doint an fft of the signals shows, that the filter only cuts away frequencies above ca. 500 kHz. Using
fvtool(filter)
gives my the same transfer function for the filter, independent of the corner frequency I chose.
This is a bug right? Or do I overlook something? I'm using matlab 2018b.

답변 (1개)

Star Strider
Star Strider 2020년 8월 6일
편집: Star Strider 2020년 8월 6일
A low passband with a very high sampling frequency is asking a lot of any filter. I am somewhat surprised that lowpass used a FIR design in that instance, when a IIR design is more appropriate. (I could not get a FIR filter to work with those constraints, either.)
This one works:
Tend = 10e-3;
dt = 100e-9;
t = 0:dt:Tend-dt;
fsig = 500;
sig = 100*sin(2*pi*fsig*t) + 20*sin(2*pi*fsig*100*t);
% [sig_filt filter] = lowpass(sig, 1000, 1/dt);
Fs = 1/dt;
Fn = Fs/2;
Wp = 950/Fn;
Ws = 1050/Fn;
Rp = 1;
Rs = 60;
[n,Wn] = ellipord(Wp,Ws,Rp,Rs);
[z,p,k] = ellip(n,Rp,Rs,Wp,'low');
[sos,g] = zp2sos(z,p,k);
sig_filt = filtfilt(sos,g,sig);
[h,f] = freqz(sos, 2^16, 1/dt);
Fs = 1/dt;
Fn = Fs/2;
L = numel(sig);
FTsig = fft(sig)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
loglog(Fv, abs(FTsig(Iv))*2)
hold on
plot(f, abs(h), 'LineWidth',1.5)
hold off
xlim([0 5E+6])
grid
legend('Signal','Filter Characteristic', 'Location','S')
EDIT — (6 Aug 2020 at 13:35)
Consider forcing an IIR design:
[sig_filt filter] = lowpass(sig, 1000, 1/dt, 'ImpulseResponse','iir');
When I tried this, I got much better results than with the default FIR design.
.
  댓글 수: 2
PRABHAT PRADHAN
PRABHAT PRADHAN 2023년 8월 22일
Thanks Star Strider. Nice, I also getting some error with default "lowpass()" filter with high sampling frequency, but that is resolved by using 'iir' Impulse response.
Star Strider
Star Strider 2023년 8월 22일
My pleasure!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Digital and Analog Filters에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by