MATLAB: Why failed to called filtfilt using design.bandpass result

filtfilt

Dear,
I am trying to build a bandstop filter to get ride of 50Hz, below is my code:
%% build filter
N = 20; % Order
F3dB1 = 49; % First
F3dB2 = 51; % Second
Fs = 1000; % Sampling Frequency
h = fdesign.bandstop('n,f3db1,f3db2', N, F3dB1, F3dB2, Fs);
Hd = design(h,'butter');
%[B, A] = sos2tf(Hd.sosMatrix,Hd.scaleValues);
fvtool(Hd);
%% test data
fs = 1000;
t = 0:1/fs:5-1/fs;
x = cos(2*pi*50*t)+cos(2*pi*100*t);
fdata=filtfilt(Hd,double(x)); % call filtfilt failed. use filter() instead.
When I run the last statement, I got some error message:
Error using filtfilt (line 17)
Not enough input arguments.
If I change it to filter(HD, double(x)), then everything all right.
what's going on here? why I can't call filtfilt?

Best Answer

The filtfilt function is working correctly, and will do what you want with the correct inputs:
fdata=filtfilt(Hd.sosMatrix,1,double(x));
In context:
%% build filter
N = 20; % Order
F3dB1 = 49; % First
F3dB2 = 51; % Second
Fs = 1000; % Sampling Frequency
h = fdesign.bandstop('n,f3db1,f3db2', N, F3dB1, F3dB2, Fs);
Hd = design(h,'butter');
%[B, A] = sos2tf(Hd.sosMatrix,Hd.scaleValues);
% fvtool(Hd);
%% test data
fs = 1000;
t = 0:1/fs:5-1/fs;
x = cos(2*pi*50*t)+cos(2*pi*100*t);
fdata=filtfilt(Hd.sosMatrix,1,double(x)); % call filtfilt failed. use filter() instead.
figure
plot(t, x, t, fdata)
grid
.