FiltFilt function giving NaN values
46 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I designed a low pass filter of 170 Hz and filtered my signal using 'filtfilt' function. But I am getting NaN values in the output signal. I have checked my original signal and it doesn't contain any NaN or Inf values. I also used the filter function for fitering but still getting NaN values.
[b,a] = ellip(14,5,30,2*(170/srate),'low');
freqz(b,a)
lpfSig = filtfilt(b,a,Sig);
0 comentarios
Respuestas (2)
Star Strider
el 11 de Jun. de 2021
Editada: Star Strider
el 15 de Jun. de 2021
The signal itself (as well as the value of ‘srate’) may be important here. (The factor of 2 is not necessary.)
I have no idea what the problem is, however one possibility is that there could be ‘ringing’ due to transients at one or the other end of the filtered signal. One way to eliminate that is to initially create the signal as:
signal_to_filter = [ones(10,1)*signal(1); signal(:); ones(10,1)*signal(end)];
use filtfilt on ‘signal_to_filter’, then remove the first and last 10 elements from the filtered signal.
The filter appears to be stable with this value of ‘srate’.
Analysis —
srate = 500;
[b,a] = ellip(14,5,30,2*(170/srate),'low');
figure
freqz(b,a, 2^14, srate)
EDIT — (15 Jun 2021 at 14:24)
‘If I reduce the order to 10, then I am not getting NaNs.’
The transfer-function implementation of the filter itself does not appear to be unstable, however using a second-order-section implementation would be worth trying —
srate = 2000;
[z,p,k] = ellip(14,5,30,2*(170/srate),'low');
[sos,g] = zp2sos(z,p,k);
figure
freqz(sos, 2^14, srate)
The filtfilt call would then be:
lpfSig = filtfilt(sos,g,Sig);
.
0 comentarios
Jan
el 11 de Jun. de 2021
I try to run your code guessing some inputs:
srate = 1000;
[b, a] = ellip(14, 5, 30, 2*(170/srate), 'low');
lpfSig = filtfilt(b, a, rand(1, 1000));
any(isnan(lpfSig))
You see, there is no Nan. So it is your turn to determine, where the difference between my guessed inputs and your real inputs is. Based on the given information, I cannot do this for you.
3 comentarios
Ver también
Categorías
Más información sobre Digital Filter Design en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!