필터 지우기
필터 지우기

Digital filter with lowpass, then filtfilt: different output

조회 수: 32 (최근 30일)
Riccardo Sorvillo
Riccardo Sorvillo 2020년 5월 13일
답변: Paul 2024년 6월 8일
Hello world!
Here I am again dealing with digital filters; I am using the latest MATLAB version (R2020a) with DSP system toolbox.
I am manipulating accelerometers data that need to be filtered by a lowpass filter: satisfactory results have been achieved with function lowpass. Since next acquistions have to pass through the very same filter, I extracted the filter built in lowpass writing
[dataflt, Hd] = lowpass(data, cut_off, fs, 'ImpulseResponse', 'fir');
Subsequent steps would be to apply Hd via filtfilt function to all the other acquisitions: as stated in past MathWorks questions, lowpass inherently uses filtfilt function. In order to double-check this statement, I filtered the data used in lowpass with filter Hd writing
dataflt = filtfilt(Hd,data);
I plotted the two outputs to compare them (in the time domain, figure below): it can be concluded that discrepancies arise at the beginning and at the end of the time history.
Why does such a difference exist? Am I neglecting anything fundamental? Is there any way to solve this problem?
I would prefer to use filtfilt (or similar) instead of lowpass because it seems to me the faster way to filter data, given that the filter is precalculated: is this statement true?
Thank you in advance for your wothwhile help.
Riccardo

채택된 답변

Star Strider
Star Strider 2020년 5월 13일
Occasionally, filter transients can appear, such as those you are seeing. The way I deal with those (to my satisfaction at least) is to add a vector of ones multiplied by the initial value of the vector to the beginning (and similarly at the end if necessary) to the vector. I then remove these elements from the filtered signal. The length of the added elements can vary, I usually use 10 samples. Experiment to get the result you want.
  댓글 수: 4
Riccardo Sorvillo
Riccardo Sorvillo 2020년 5월 15일
Thank you very much for your valuable help: your explaination was clear and solved my problem.
Star Strider
Star Strider 2020년 5월 15일
As always, my pleasure!
Thank you! I do my best!

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

추가 답변 (1개)

Paul
Paul 2024년 6월 8일
lowpass calls filtfilt (or executes code equivalent to filtfilt) only if the underlying filter is IIR. If it's FIR, as in the question by @Riccardo Sorvillo, then lowpass "compensates for the delay introduced by the filter" by using the known delay of a FIR filter that depends on its order.
Example:
rng(100);
fs = 1e3;
t = 0:1/fs:1;
x = [1 2]*sin(2*pi*[50 250]'.*t) + randn(size(t))/10;
% lowpass() with IIR filter, same result as filtfilt()
[ylp,d] = lowpass(x,200,fs,'ImpulseResponse','iir','Steepness',0.5);
yff = filtfilt(d,x);
figure
plot(t,ylp-yff)
% lowpass() with FIR filter, different result than filtfilt()
[ylp,d] = lowpass(x,150,fs);
yff = filtfilt(d,x);
figure
plot(t,ylp-yff),grid

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by