Running data through a filter multiple times

7 visualizaciones (últimos 30 días)
Elliot Jones
Elliot Jones el 29 de Jun. de 2020
Respondida: Star Strider el 29 de Jun. de 2020
I'm trying write a function that will run data through a chebyshev type 2 filter a number of times. I currently have written this which doesn't work and I'm currently struggling with how to fix it or wether I'm attacking this completely wrong. To build the filter im using [bd,ad]=cheby2(N,R,Wst). I also need to have each stage of the dataout saved.
function [datafiltered]casfilter(bd,ad,data,nfilters)
% CASFILTER - pass data through a filter defined bd and ad n number of
% times and give datafiltered. n>1.
%
% useage: [datafiltered]=casfilter(bd,ad,data,nfilters)
%
% Elliot Jones, 21st June 2020
[dataout1,zout1]=filter(bd,ad,data);
for n=1:(nfilters-1)
[dataout"n+1",zout"n+1"]=filter(bd,ad,dataout"n",zout"n");
end
dataout"n"=datafiltered
end

Respuesta aceptada

Star Strider
Star Strider el 29 de Jun. de 2020
It is not easy to follow what you are doing here, especially with respect to your using the strings as part of the subscript (that will absolutely not work).
I would do something like this:
dataout(:,1) = filtfilt(bd,ad,data(:)); % Convert To Column Vector, Then Filter
for n=2:nfilters
dataout(:,n) = filtfilt(bd,ad,dataout(:,n-1)); % Store Sucessive Column Vectors
end
datafiltered = dataout; % Define ‘datafiltered’ As ‘dataout’ Matrix
If you do not want to save the entire matrix of intermediate results, do not subscript them.
If you only want to output the final result, do this instead:
datafiltered = dataout(:,end); % Define :datafiltered, As Last Column Of 'dataput' Matrix
Make appropriate changes to get the result you want.
See the documentation section on: Matrix Indexing to understand how to do it correctly.
Also consider preallocating the matrix, so before the loop set it to:
dataout = zeros(numel(data), nfilters);
to execute the loop faster.
.

Más respuestas (0)

Categorías

Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by