FiltFilt function giving NaN values
조회 수: 46 (최근 30일)
이전 댓글 표시
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
답변 (2개)
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);
.
댓글 수: 0
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))
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Filter Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!