This is an example of how to do this with filter
:
filter_state = []; % start with empty filter history
while not_stopped()
x = get_one_input_sample();
[y, filter_state] = filter(B, A, x, filter_state);
process_one_output_sample(y);
end;
Note that you need to use the extended form of filter, in which you pass the history of the filter from one iteration to the next using the variable filter_state
. The B
and A
are the coefficients of your discrete filter. If your filter is continuous, you need to transform it to a discrete filter first using c2d
or so. Note that if your filter is very complex, you might need to split up the filtering in several steps (e.g. one second-order-stage per filter) to avoid numerical problems.