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 Center および File ExchangeGet 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