What is the equivalent of Discrete Filter bloc in a matlab code ?

1 visualización (últimos 30 días)
I am trying to convert a simulink model into a matlab code, but I don't know how I can write the Discrete Filter bloc (DSP System toolbox).
I have made a Matlab class to run my code through a simulation to compare the code I wrote with the Discrete Filter bloc, here are the stepImpl() and resetImpl() methods of it :
function u = stepImpl(obj, s)
obj.s_vect = circshift(obj.s_vect, 1);
obj.s_vect(1) = s;
obj.u = conv(obj.s_vect, obj.w, 'same');
u = obj.u(1);
end
function resetImpl(obj)
% Initialize / reset discrete-state properties
obj.w = [1 2 3 4 5 6];
obj.u = [0 0 0 0 0 0];
obj.s_vect = [0 0 0 0 0 0];
end
And here is my simulink model to compare the result :
The coefficients of my vector obj.w is the same as the numerator of the discrete filter :
The result are a sine wave oscillating between -10 and 10 for the matlab class, while it is an sine wave oscillating from -20 to 20 for the bloc. I want my matlab class to provide the same result as the simulink bloc.
I have no idea if the function conv() is made for this, and I am not sure neither if the way to manage input and output signal is correct.
Can you help me ?
Thank you !

Respuesta aceptada

Andy Bartlett
Andy Bartlett el 30 de Jun. de 2021

Más respuestas (0)

Categorías

Más información sobre Get Started with DSP System Toolbox en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by