dsp.SineWave in Matlab function block not generating sine wave on the scope

When the plot function is called it generates the desired wave. However when a scope is used to observe this , constant values are rather observed. The same output is observed when the dispaly block is used - all values are generated at once even for a single step. What could I be doing wrongly here?
It also takes a long time to complete simulation when used in Simulink compared to Matlab.
See below the code.
function y = fcn()
sine1 = dsp.SineWave('Amplitude',1,'Frequency',60,'PhaseOffset',0,'SamplesPerFrame',1000,'OutputDataType','double');
y = sine1();
The idea is to later make the amplitude an argument(input) to the block so it can be varied.The application will be to make a closed loop control that uses over modulaton of SPWM..

Réponses (1)

Hi!
Why do not you use sinWave block available in dsp system simulink library instead of writing a MATLAB function for that ? You will be able to change block parameters Check out the link below to learn about dsp system toolbox signal generation capabilities:
Hope this helps

5 commentaires

Andrew
Andrew le 28 Juil 2022
Modifié(e) : Andrew le 28 Juil 2022
Hello Abderrahim. Thank you for your quick response and the suggestion.
As I mentioned earlier in the description, I wish to vary the amplitude of the sinewave based on the output voltage measured for the controller (closed loop) I am designing. The Matlab function allows me to include an input port so I can vary easily the parameters.
The sinewave block will not be helpful in my case. It will always be constant since it is not a block with parameters that can be specified by an input port.
I attempted using it for my open loop controller and it was kind of ok.
Is there a way to specify the parameters of the block as an input port? I see it has only an output port from the documentation.
Hi Andrew,
There are control components in Simulink that you can use for this purpose. I build a small demo using slider to control sine wave amplitude (see picture attached).
Hope you find this reply helpful
Hi Abderrahim.
Thank you for this suggestion..
The slider wouldn't be the appropriate block for this application.
I will keep checking for other alternatives.
Hi Andrew,
Varying the amplitude of the sine wave is probably easier than you think.
This is the equation:
x(t) = Amp*[1*sin(2*pi*Freq*t)]
where you can define how the Amplitude should behave, perhaps as a function of time, t. For example, in the MATLAB Function block,
Amp = V/(1 + exp(- k*(t - t0))) + Offset.
Then, multiply Amp with the output of the Sine wave block.
Thanks Sam.
Your solution gave a clue.
Using the Sinewave block from simulink & product block together with a constant/ varying input works.

Connectez-vous pour commenter.

Produits

Version

R2022a

Question posée :

le 28 Juil 2022

Commenté :

le 4 Août 2022

Community Treasure Hunt

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

Start Hunting!

Translated by