# Trapezoidal pulse generation using gensig() function

17 views (last 30 days)
Amit Kumar on 15 Oct 2019
Hi
I am trying to generate a trapezoidal pulse using gensig() function with rise time = fall time = 1s, time period = 5s, sampling time = 0.01s, and simulation time = 40s?
Is it possible to do so, since I can see only three options as 'sine', 'square' and 'pulse' when I studied about this fucntion in MATLAB help section.
Also kindly suggest if 'siggen()' is also some function in MATLAB or not?
Thanks

Praveen Iyyappan Valsala on 15 Oct 2019
The answer is No! .I am not aware of any function which can do that for you. Try to adapt my function for your needs or write your own.
%Does this work for you?
[t,p]=Trapezoidal_pulse(1,3,0.01,1,1,5,8);
figure,plot(t,p)
The function:
%%
% All times are of same units
% DwellTime-1/Sampling rate or raster time
%Repetitions -Number of Trapezoidal pulses
if(RiseTime<DwellTime)
warn('RiseTime<DwellTime: No Ramp up samples')
rampup_samples=[];
else
rampup_samples= linspace(0,Amplitude,ceil(RiseTime/DwellTime));
end
if(FallTime<DwellTime)
warn('FallTime<DwellTime: No Ramp down samples')
rampdown_samples=[];
else
rampdown_samples= linspace(Amplitude,0,ceil(FallTime/DwellTime));
end
%bipolar
% pulse_train=repmat(pulse,[Repetitions 1]).'.*(-1*ones(length(pulse),1)).^(0:Repetitions-1);
%unipolar
pulse_train=repmat(pulse,[Repetitions 1]).';
pulse_train=pulse_train(:);
%time
t=(0:(length(pulse_train)-1))*DwellTime;
end
Use doc or edit command to see the ownership and year at which the function is added to matlab.