MATLAB Answers

generating periodic trapezoidal waves with ramps

48 views (last 30 days)
Tae Lim
Tae Lim on 7 Dec 2020
Answered: Amrtanshu Raj on 23 Dec 2020
I want to generate a periodic trapezoidal wave that has 'ramps' on both sides of the wave structure. I was able to generate square waves that does not have ramps using the following codes.
Pwr_avg = 200; % [W] average input power
nu_p = 2e3; % [Hz]=[1/s] pulse repetition frequency
tau_p = 1/nu_p; % [s] pulsed period
f_DC = 0.15; % [%] duty cycle (=fraction of the pulsed period power is on)
tau_on = tau_p * f_DC; % [s] length of time power is on during each pulsed period
tau_ramp = 1e-6; % [s] ramp up/down time
Pwr_max = Pwr_avg * (tau_p/tau_on); % [W] maximum power during the pulsed period during 0<t<=tau_on
Pwr_min = 1e-4; % [W] arbitrary small value during the 'off' period
d = tau_on/2:tau_p:t_max;
Pwr = Pwr_max * pulstran(t_array,d,'rectpuls',tau_on); % generate periodic power input
Pwr(Pwr==0) = Pwr_min; % assign arbitrary small power input during 'off' period
Pwr = Pwr / (pi*r_cyl^2*l_cyl) * 1e3; % [mW/cm3] input power array
The code above use pulse train function to generate periodic structure, which is used to simulate pulsed power. The absolute zero values for the power is not ideal for my application, so I assigned arbitrary small value when the power is 'off'.
Here, I would like to introduce a ramp up/down time as the power increases from zero, and decreases back to zero. So the pulsed waveform will become trapezoid that has steep ramps. I would like to know how to add ramps on this square wave or if Matlab already has inherent function I can use.
Thank you for your time

  1 Comment

Mathieu NOE
Mathieu NOE on 7 Dec 2020
I do not see the trapezoidal signal as being part of the available options in
several options :
implement a rate limiter like described in :
or apply a first order low pass filter (not truly a trapezoidal shape though)

Sign in to comment.

Answers (1)

Amrtanshu Raj
Amrtanshu Raj on 23 Dec 2020
The pulstran function allows you to input custom function handles to generate custom waveforms. You can use this equation to create a trapezoidal wave and pass it to pulstran function to get the trapezoidal waveform and then tune it as per need.
a = 10 %Amplitude
m = 5 %Time Period
l = 5 %Horizontal Spread
c = 2 %Vertical Spread
x = 0:.1:10 %Sample Points
Trapezoidal_Wave = a/pi*(asin(sin((pi/m)*x+l))+acos(cos((pi/m)*x+l)))-a/2+c;


Sign in to comment.


Community Treasure Hunt

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

Start Hunting!