1
votes

I am feeding a signal q into a MATLAB Function block - for example a sinusoid (it could be something else too). My MATLAB Function block also needs the time derivative of the signal. In Simulink I can do something like this:

enter image description here

However I'd like to forego the Derivative block (to conserve space, my actual model is much bigger than the above) and somehow get the derivative directly inside the MATLAB Function. For this I'd need to know the previous value of q probably... which I can't know without adding a memory block.

Question : How do I get qdot inside MATLAB Function without using any extra blocks (and removing the Derivative block above obviously)?

Thanks for your help!

1
Do you mean that you want to 'manually' calculate numerical derivatives inside the Matlab block based on delayed values of q? Bad idea.JJM Driessen
No, I want to avoid that too. I just want to know if there is a magic option somewhere to pass in the derivative of a signal to the MATLAB Function block without having to place a Derivative block into the diagram.space_voyager
You could use a mux and put the derivative and signal generator in a subsystem to save space.JJM Driessen
What is the input q? Can you calculate an analytical derivative of it? There is no "magic." If you need the derivative then you need to calculate the derivative one way or another.horchler
For as far as I know, there is no such thing. Use proper signal routing by using (de)muxers, (bus) selectors/creators and subsystems to deal with space problems.JJM Driessen

1 Answers

0
votes

I'm not sure if you can solve it inside the function block, since you need to know the previous values of q, but maybe you can solve this by using a feedback with delay in which you will return the old value of q, like on the image below.

OldQ with delay.

I don't know if this will solve your problem, but it's worth the try. If you use it in this way, you might want to test the entire model a bit (concerning synchronization of sample times and delays and similar things).