lowpass() not working

20 次查看(过去 30 天)
J B
J B 2020-7-31
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.

请先登录,再进行评论。

类别

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