开发者

Previous outputs as inputs for an FIR filter

Does anyone know if it is possible to pass previous output valuess to an FIR filter in Matlab开发者_Go百科? I would like to do this because I have masses of data (>300Gb) which I would like to filter and down sample. If I use a standard [b,a] set of coefficients in a an FIR function then the first few samples will be incorrect because they depend on the initial conditions.

This is the problem because I would like to filter my large data set by taking smaller chunks of it but if I do it using the standard way then at the beginning of every chunk there will be error (which will propagate through due to it being an FIR filter).

Any ideas will be much appreciated!


filter command can take initial conditions as input and return final conditions as second output. You need to use these to filter smaller chunks of your data. For example,

b = fir1(10, 0.5);
Zi = zeros(numel(b)-1,1);
while moreData
   [y Zi] = filter(b, 1, data, Zi);
end

If you have DSP System toolbox, you can also dsp.DigitalFilter System object which will manage the states for you. For example, the above code can become

b = fir1(10, 0.5);
h = dsp.DigitalFilter('TransferFunction', 'FIR (all zeros)', 'Structure', 'Direct form transposed', 'Numerator', b);
while moreData
    y = step(h, data);
end


You could use the 'zi', 'zf' features of the 'filter' command: http://www.mathworks.com/help/techdoc/ref/filter.html

This allows you to set the initial conditions of the filter.


In such cases, you can use filtfilt, which implements a zero-phase filtering, i.e., it processes the data once forward and once backward, resulting in no net delay. However, you should note that the effective filter order is double that of what is specified by b.

Here's an example from the documentation (the plot has been modified):

x=ecg(500)'+0.25*randn(500,1); %'#noisy waveform
h=fdesign.lowpass('Fp,Fst,Ap,Ast',0.15,0.2,1,60);
d=design(h,'equiripple'); %#Lowpass FIR filter
y=filtfilt(d.Numerator,1,x); %#zero-phase filtering
y1=filter(d.Numerator,1,x); %#conventional filtering

figure(1)
h=plot([x y y1]);
set(h(1),'color',[0.8,0.8,0.8])
title('Filtered Waveforms');
legend('Original waveform', 'Zero-phase Filtering','Conventional Filtering');

Previous outputs as inputs for an FIR filter

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜