Need PWM Signal for Sinusoid input

7 views (last 30 days)
Goody
Goody on 31 Jul 2023
Answered: Sabin on 5 Feb 2025
Hi all,
I need a matlab script that converts sinusoid input to corresponding PWM signal with adjustable duty cycle. I understand there is PWM generator in Simulink but my version does not have it.
The environment is simulink and my input is sine wave block with sinusoid signal with specified sampling time and frequency. I want to connect the sine wave block to matlab function block that converts the sinusoid to pwm. I find it challenging to do as pwm is usually between 0 and 1 but the sinusoid has negative values too. Also the pwm frequency should be lower than the sampling frequency I believe.
A picture similar to what I need is attached.
Thank you.

Answers (1)

Sabin
Sabin on 5 Feb 2025
PWM block was released in version R2020b: https://mathworks.com/help/simulink/slref/pwm.html
There are other blocks that can be used as well in Simscape Electrical: https://mathworks.com/help/sps/pulse-width-modulation.html
It is also possible to implement a simple one by comparing the modulation waveform (sinusoid) with a triangular carier (using a Repeating Sequence for instance https://mathworks.com/help/simulink/slref/repeatingsequence.html).

Community Treasure Hunt

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

Start Hunting!