MATLAB Answers

FiltFilt function giving NaN values

7 ビュー (過去 30 日間)
Anjali Agarwal
Anjali Agarwal 2021 年 6 月 11 日
編集済み: Star Strider 2021 年 6 月 15 日
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);

回答 (2 件)

Star Strider
Star Strider 2021 年 6 月 11 日
編集済み: Star Strider 2021 年 6 月 15 日
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);
.

Jan
Jan 2021 年 6 月 11 日
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))
ans = logical
0
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 件のコメント
Anjali Agarwal
Anjali Agarwal 2021 年 6 月 15 日
If I reduce the order to 10, then I am not getting NaNs.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by