Professional Documents
Culture Documents
Class 2 Sheet 6
Class 2 Sheet 6
Experiment [6]
Generating Waves (Signals)
There are two ways to generate functions (signals), matrix method and function
method.
1) Unit Impulse Signal:
clc 1.5
clear all
t1=1:10;
1
t=[0 t1];
u=[1 zeros(1,10)];
UNITMPULSE
stem(t,u); 0.5
axis([-10 10 -0.5 1.5])
I
grid on
xlabel('t(time)') 0
ylabel('UNIT_IMPULSE')
-0.5
-10 -8 -6 -4 -2 0 2 4 6 8 10
t(time)
close all
t1=-10:0;
1
t2=0:10;
t=[t1 t2];
UNIT TEP
u=[zeros(1,11) ones(1,11)];
S
0.5
plot(t,u);
axis([-11 11 -0.5 1.5])
grid on 0
xlabel('t(time)')
ylabel('UNIT_STEP')
-0.5
-10 -8 -6 -4 -2 0 2 4 6 8 10
t(time)
We can generate the step signal in function method using a function called hardlim function.
1
SIGNAL AND SYSTEMS LABORATORY
1.5
n=-5:0.01:5;
a=hardlim(n);
1
plot(n,a,'linewidth',2);
axis([0-7 7 -0.5 1.5]);
grid on 0.5
-0.5
-6 -4 -2 0 2 4 6
clc
clear all 3
t1=-10:-3; 2
t2=-3:3; 1.5
t3=3:10;
rectangular-step
plot(t,u) -0.5
grid on -1
axis([-11 11 -2 3]) -1.5
xlabel('t(time)') -2
ylabel('rectangular-step') -10 -8 -6 -4 -2 0
t(time)
2 4 6 8 10
1.5
clear all
close all 1
t=-10:0.1:10;
RAMP IGNAL
y=hardlim(t+3)-hardlim(t-3); 0.5
S
plot(t,y,'linewidth',2)
0
grid on
axis([-11 11 -1 2]) -0.5
xlabel('t(time)')
ylabel(rectangular SIGNAL') -1
-10 -8 -6 -4 -2 0 2 4 6 8 10
t(time)
2
SIGNAL AND SYSTEMS LABORATORY
9
t2=0:10;
8
t=[t1 t2]; 7
u=[zeros(1,11) t2]; 6
RAMP IGNAL
plot(t,u,'linewidth',2) 5
grid on
S
4
axis([-5 10 -1 10]) 3
xlabel('t(time)') 2
ylabel('RAMP_SIGNAL') 1
-1
-5 0 5 10
t(time)
We can generate ramp signal by using satlin function as shown in the figure below:
N=-5:0.1:5;
A=satlin(N);
plot(N,A);
clear all
5
close all
t=-10:10; 4
y=satlin(t)+satlin(t-1)+satlin(t-2)
+satlin(t-3); 3
RAMP IGNAL
plot(t,y)
2
grid on
S
zoom on 1
axis([-5 10 -1 5])
xlabel('t(time)') 0
ylabel('RAMP_SIGNAL')
-1
-5 0 5 10
t(time)
3
SIGNAL AND SYSTEMS LABORATORY
5) Exponential Signal:
The general wave of expwave is
Y=a*exp(c*t) 1.8
1.6
clc
1.4
close all
EXP IGNAL
a=2; 1.2
S
c=-2; 1
t=linspace(0,1,1001); 0.8
y=a*exp(c*t); 0.6
plot(t,y) 0.4
grid on 0.2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
zoom on t (time)
xlabel('t (time)')
ylabel('EXP_SIGNAL')
6) Sinusoidal Signal:
The general wave is sinewave is: Y=a*sin(2*pi*f*t); or: Y=a*sin(w*t);
a=2; 2
f=2; 1.5
t=linspace(0,1,1001); 1
y=a*sin(2*pi*f*t); 0.5
sine IGNAL
plot(t,y) 0
S
grid on -0.5
xlabel('t (time)')
-1
ylabel('sine_SIGNAL')
-1.5
-2
7) Sawtooth and Square Signals: 0 0.1 0.2 0.3 0.4 0.5
t (time)
0.6 0.7 0.8 0.9 1
y=a*sawtooth(2*pi*5*t);
0.5
SAWTOOTH IGNAL
plot(t,y,'linewidth',1.5)
S
grid on
-0.5
xlabel('t (time)')
ylabel('SAWTOOTH_SIGNAL') -1
8) Sinc Function
Y = sinc(x); This function returns an array y the same size as x, whose elements are the
sinc function of the elements of x, where the sinc function is:
This function is the continuous inverse Fourier transform of the rectangular pulse of
width 2π and height 1.
1.2
t=0.2;
k=-5:t:5; 1
a=sinc(k); 0.8
plot(k,a,'o') 0.6
sinc unction
zoom on 0.2
xlabel(‘discrete') 0
ylabel('sinc_function') -0.2
-0.4
-5 -4 -3 -2 -1 0 1 2 3 4 5
discrete
5
SIGNAL AND SYSTEMS LABORATORY
Experiment:
Write the MATLAB program required to generate each of the following signals:
4
4
3.5
3 3
2.5
2
2
1.5
1
1
0 0.5
0
-1
-0.5
-1
-2 -10 -8 -6 -4 -2 0 2 4 6 8 10
-1 0 1 2 3 4 5 6 7 8 9 10
4 6
5
2
4
0
sinc unction
-2
f
-4 1
-6 0
-1
-8 -1 0 1 2 3 4 5 6
-2 0 2 4 6 8 10 discrete
1.5
0.5
-0.5
-1
0 2 4 6 8 10 12