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

조회 수: 1 (최근 30일)
Guilhem Schena
Guilhem Schena 2021년 6월 29일
답변: Andy Bartlett 2021년 6월 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