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 !
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with DSP System Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!