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

1 次查看(过去 30 天)
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 !

采纳的回答

Andy Bartlett
Andy Bartlett 2021-6-30

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with DSP System Toolbox 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by