I'm trying to breakdown how bandpass function makes the filtering and stumped upon this line (after the filter is created).
y = signal.internal.filteringfcns.filterData(x,opts);
x is the data and opts has the filter structure.
I've been looking around and haven't been able to find anything about signal.internal.filteringfcns.filterData
function. I compared that output with filter(opts.FilterObject,x)
and they are not the same.
Next is a minimal working example (data2.txt).
load('data2.txt')
srate=64;
freqrange=[0.4 3.5];
var{1}=freqrange;
var{2}=srate;
m=numel(data2);
x=data2;
R=0.1;%10% of signal
Nr=50;
NR=min(round(m*R),Nr);%At most 50 points
x1=2*x(1)-flipud(x(2:NR+1));%maintain continuity in level and slope
x2=2*x(end)-flipud(x(end-NR:end-1));
x=[x1;x;x2];
opts=signal.internal.filteringfcns.parseAndValidateInputs(x,'bandpass',var);
opts = designFilter(opts);
xx = signal.internal.filteringfcns.filterData(x,opts);
x_fil=xx(NR+1:end-NR);
xx = filter(opts.FilterObject,x);
x_fil2=xx(NR+1:end-NR);
plot([data x_fil x_fil2])
legend('raw','filterData','filter')
Here is the plot:
And here are the psd plot of both filtered signal (filtData first).
So, any help on this ...filtData
function or I doing something wrong in my analysis?
Hi again :) If you type edit signal.internal.filteringfcns.filterData
, you can even look at what is inside this filterData
function. You will see that this function (depending on the options opts
) will either,
N/2
zeros and call filter
filtfilt
with the signalThis is also described in the docs of bandpass
. So probably this zero padding explains why your output of filter(opts.FilterObject,x)
is different.
You cannot find this function described in the documentation of Matlab since it is part of the internal functions of the signal processing toolbox.