Why does the FILTFILT documentation not mention the effects of truncation

Illustration
Lincoln - 2021-03-17T11:48:23+00:00
Question: Why does the FILTFILT documentation not mention the effects of truncation

Why does the FILTFILT  documentation not mention the effects of truncation, while providing a short input sequence to an IIR filter ? I am using the FILTFILT function to  plot the magnitude response. I observe a truncated output when using a short delta sequence.   However, if I increase the filter order or the length of the input sequence, I get an improved response. The documentation does not provide any information regarding this.

Expert Answer

Profile picture of John Michell John Michell answered . 2025-11-20

Documentation on the FILTFILT function is missing important information regarding its performance.
 
Here is additional information on the FILTFILT function.
 
The length of the input 'x' must be more than three times the filter order, defined as max(length(b)-1,length(a)-1). The input should be sufficiently large so that the impulse is correctly represented.
 
As an example, for a fifth order filter, if the input sequence is a delta sequence, the '1' should appear anywhere within the first 15 samples.
 
close all;

[b,a] = butter(5,0.5); 
% a = 1;
delta = [zeros(2,1);1;zeros(100,1)]; % Short Input vector
y_short = filtfilt(b,a,delta);
Y_short = fft(y_short,2048);

delta_long = [zeros(1024,1);1;zeros(1023,1)]; %Long Input vector
y_long = filtfilt(b,a,delta_long);
Y_long = fft(y_long,2048);

figure; impz(b,a,length(delta)); hold on; plot(sqrt(abs(y_short)),'r'); 
figure; impz(b,a,length(delta_long));hold on; plot(sqrt(abs(y_long)),'r');

w = linspace(0,2*pi,length(delta));
wl = linspace(0,2*pi,length(delta_long));
h1 = freqz(b,a,wl);
figure; plot(wl,abs(h1)); hold on; plot(wl,sqrt(abs(Y_short)),'r'); hold off;
h_long = freqz(b,a,wl);
figure; plot(wl,abs(h_long)); hold on; plot(wl,sqrt(abs(Y_long)),'r'); hold off;


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!