Monday, 10 February 2014

PERIODIC, APERIODIC, PULSE TRAIN WAVEFORMS IN MATLAB – EXAMPLE CODE


       This example show s how to generate widely used periodic and aperiodic waveforms, sequences (impulse, step, ramp), pulse trains in Matlab.


Periodic Waveforms:
In addition to the sin and cos functions in MATLAB, we can produce periodic signals such as saw tooth and square.

The saw tooth function generates a saw tooth wave with peaks at +/- 1 and a period of 2*pi.  The fractional multiple of '2*pi' specifies the point at which the signal's maximum occurs.

The square function generates a square wave with a period of 2*pi.  The duty cycle can also be adjusted.

fs = 10000; %sampling freq
t = 0:1/fs:1.5; % 0s to 1.5s with Fs sample freq
x1 = sawtooth(2*pi*50*t);  % 2*pi* freq * time duration
x2 = square(2*pi*50*t);
subplot(211),plot(t,x1), axis([0 0.2 -1.2 1.2])
xlabel('Time (sec)');ylabel('Amplitude'); title('Sawtooth Periodic Wave')
subplot(212),plot(t,x2), axis([0 0.2 -1.2 1.2])
xlabel('Time (sec)');ylabel('Amplitude'); title('Square Periodic Wave')


Aperiodic Waveforms:
To generate triangular, rectangular and Gaussian pulses, the toolbox offers the tripuls,  rectpuls and gauspuls functions.

The tripuls function generates a sampled aperiodic, unity-height triangular pulse centered about t = 0 and with a default width of 1.
       tripuls(t,wid); t= time duration, wid=pulse width

The rectpuls function generates a sampled aperiodic, unity-height rectangular pulse centered about t = 0 and with a default width of 1. The interval of non-zero amplitude is defined to be open on the right, that is, rectpuls(-0.5) = 1 while rectpuls(0.5) = 0.
       rectpuls(t,wid); t= time duration, wid=pulse width

fs = 10000; %sampling freq
t = -1:1/fs:1; % -1s to +1s with Fs sample freq
x1 = tripuls(t,20e-3);
x2 = rectpuls(t,20e-3);
subplot(211),plot(t,x1), axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)');ylabel('Amplitude'); title('Triangular Aperiodic Pulse')
subplot(212),plot(t,x2), axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)');ylabel('Amplitude'); title('Rectangular Aperiodic Pulse')
set(gcf,'Color',[1 1 1]),



The gauspuls function generates a Gaussian-modulated sinusoidal pulse with a specified time, center frequency, and fractional bandwidth.
          gauspuls('cutoff',f,bw,[],att)
                    f- cutoff freq
                    bw- bandwith (0 to 1)
                    att- attenuation value (in db)

The sinc function computes the mathematical sinc function for an input vector or matrix. The sinc function is the continuous inverse Fourier transform of the rectangular pulse of width 2*pi and height 1.


%GUASSIAN PULSE
tc = gauspuls('cutoff',50e3,0.6,[],-40);
t1 = -tc : 1e-6 : tc;
y1 = gauspuls(t1,50e3,0.6);

% SINC PULSE
t2 = linspace(-5,5); % linearly spaced vector (LSV)
y2 = sinc(t2); % sinc for LSV
subplot(211),plot(t1*1e3,y1);
xlabel('Time (ms)');ylabel('Amplitude'); title('Gaussian Pulse')
subplot(212),plot(t2,y2);
xlabel('Time (sec)');ylabel('Amplitude'); title('Sinc Function')
set(gcf,'Color',[1 1 1]),



Pulse Trains:
          The pulse trains can be generated using the pulstran function. Below examples shows how to use this function to generate Rectangular & Gaussian pulse train.
%RECTANGULAR PULSE TRAIN
fs = 100E9;                % sample freq 100GHz
D = [2.5 10 17.5]' * 1e-9; % pulse delay times
t = 0 : 1/fs : 25e-9;      % time 0-25ns
w = 1e-9;                  % width of each pulse
yp = pulstran(t,D,@rectpuls,w);

%GUASSIAN PULSE TRAIN
T = 0 : 1/50E3 : 10E-3; % 0-10ms @ 50KHz sample freq
D = [0 : 1/1E3 : 10E-3 ; 0.8.^(0:10)]'; % pulse delay times, repeat every 1ms, optional attenuation factor 0.8 from 0-10ms
Y = pulstran(T,D,@gauspuls,10E3,.5); %10KHz, 50% bandwidth

subplot(211),plot(t*1e9,yp);axis([0 25 -0.2 1.2])
xlabel('Time (ns)'); ylabel('Amplitude'); title('Rectangular Train')
subplot(212),plot(T*1e3,Y)
xlabel('Time (ms)'); ylabel('Amplitude'); title('Gaussian Pulse Train')
set(gcf,'Color',[1 1 1]),





If you enjoyed this post plz let us know your views via comments.
This helps us to do much more better.
Thankyou.


0 comments:

Post a Comment

Search Here...