I need a Matlab code to plot a rectangular wave function with a constant period and normalized amplitude. Please see the attached exponential Fourier series. Thank you in advance.
If you want to plot a rectangular wave function in Matlab, you can use the Matlab command: rectpuls(·). For a sampled aperiodic rectangle of constant period gamma and amplitude in the range [-do do]:
>> t=[-gamma/2:1/fs:gamma/2]; % fs represents the sampling frequency
>>pulse=2*do*rectpuls(t,T) - do; % T is the width of the pulse centered around 0
In case you want to generate a rectangular pulse train, you can use the Matlab function pulstran(·).
Thank you Poza for your answer. What if i want a pulse train with varying period (say a rate r) with a staring period of say 18? How can I introduce the rate so that i have an aperiodic function?
You can use the following Matlab code to generate a pulse train with: amplitude ranging between [-do do], a varying period of r, a pulse width of T and an initial offset of To:
>> t = [0 : 1/fs : tend]; % fs represents the sampling frequency