Lab # 1 Plotting of Basic Signals
Lab # 1 Plotting of Basic Signals
UNIT IMPULSE:
One of the simplest discrete time signals is the unit impulse or unit sample,
which is defined as
0 n≠0
δ[n]
1 n=1
0 n
1 n=no
no n
Any discrete time signal can be broken down into a series of individual impulses
which when added together give back the original discrete time signal.
-2 -1 0 3
MATLAB IMPLEMENTATION:
1
Example 1:
Write and save the following function in matlab.
Example 2:
Now call the above function with the value of L=5 & no=2; You will see
the following result.
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
-3 -2 -1 0 1 2 3
2
So we can implement the above function by another method.
Function [x, n] =dui2funct (L, no)
n= -L: L;
x=[zeros(1, (L+no)) 1 zeros(1,(L-no))];
Now call the given function another time by the same values as you have used before
for L& no and write down the results below.
…………………………………………………………………………………………
…………………………………………………………………………………………
…………………………………………………………………………………………
………………
UNIT STEP:
The following relation gives a discrete unit step function.
1 n>=0
U[n-no] =
0 n<0
0 1 2 3 4 5
The following relation gives the general form of a delayed unit step
function
1 n>=no
U [n-no] =
0 n< no
no
MATLAB IMPLITATION:
Example # 3:
Function [x,n]=dusfunct(L,no)
n= -L:L;
len=length(n);
x=zeros(1,len);
x(L+no+1:len)=1;
Example#4:
Function [x,n]=dusfunct(L,no)
n= -L:L;
len=length(n);
x=[zeros(1,l+no) 1 ones(1,L-no)]
3
% x=[zeros(1,l+no) ones(1,L-no+1)]
Example 4 & example 5 are basically the some implementation ( I.e. they perform the
same task of creating a discrete unit step function) CONTINUOUS SIGNALS: In the case of
continuous signals the independent variable is continuous, and thus their signals are defined
for a continuum of values of time e.g. a speech signal that has values defined for all time.
0 o.w
-3 -2 -1 0 1 2 3 Shifted impulse
definition is given by.
1 t-to
δ (t −to)
0 Ow
-3 -2 -1 0 1 2 3
here no=3;
MATLAB IMPLITATION:
Example #5:
Function [x,t]=cuifunct(L,no,inc)
t= -L:inc:L;
x=zeros(1,length(t));
x((L+no)/inc+1)=1;
Example #6:
Function [x,t]=cuifunct(L,no,inc)
t= -L:inc:L;
x=[zeros(1, L+no)/inc) 1 zeros(1, (L-no)/inc)];
Example 5 & 6 perform some task but in a deferent way of MATLAB
implementation.
4
UNIT STEP in Continuous time unit step function is defined in a manner similar to it s
discrete time counterpart i.e.
1 t>=0
u (t)
0 t<0
The delayed singles general form will be
t>=to
u (t − to )
0< t0
MATLAB IMPLIMENTATION:
Example #7
Function [x,t]=cusfunct(L,no,inc)
t=-L:inc:L;
Len=length(t); x=zeros(1,len);
x(((L+no)/inc+1:len)=1;
Example #8
Function[x,t]=cusfunct(L,no,inc)
t=-L:inc:L;
x=[zeros(1,(L+no)/inc) 1 ones(1,(L-no)/inc)];
5
EXERCISE:
E.1. Implement the function y[n] given by the relation
y[n] 2δ[n 3] [ n −1] 5δ[n] 6δ[n 5] −7δ[ n −2]
take L=6
E.2. Implement the continuous time function y(t) y(t)=3u(t)
+t*u(t)-(t-1)*u(t)-5u(t-2)
E.3. Shown below is the graph for discrete function Use “for” loop to implement the below
graph. You can use function of “example 1 or Example 2”.
30
20
10
-10
-20
-30
-40
-40 -30 -20 -10 0 10 20 30 40
E.4. Implement the function shown in the graph below Take L=6
1.8
1.6
1.4
1.2
0.8
0.6
0.4
0.2
6
PERIODICITY & HARMONICS
A very common class of signals that we encounter is the class of periodic signals. A
periodic continuous time signal has the property that there is a positive value of ‘t’ for which
X(t) = x(t + aT) A (continuous time)
Since sin(Q) = sin(Q + 2π) therefore the signal is periodic with the period ‘2π’.
A periodic signal in discrete time is defined similarly to continuous time periodic
signal. Specifically a discrete time periodic signal.
Specifically a discrete time signal x[n] is periodic with period ‘N’ where ‘N’ is
positive integer, i:e if it is unchanged by a time shift of ‘N’ i:e.
X[n] = x[n + bN] B (discrete time)
Where b = 0,1,2,3,4,-----------
FUNDAMENTAL PERIOD
The fundamental period is the smallest positive value of ‘T’(continuous) or ‘N’
(discrete) for which the equations of periodicity held. Consider the example of a sine
function. In that case the signal is periodic on 2π, 4π, 6π and so on but the fundamental
time period of the signal is 2π.
Example # 1
t=0:0.01:6; f=0.5;
x=sin(2*pi*f*t);
plot(t,x);
7
HARMONICS:
Harmonics are integral multiples of a signal. Consider the signal cos (wot). its
harmonics are cos(2 wot), cos (3 wot)is the fundamental harmonic.
Example # 2
inc 0.01;
t 0 : inc : 4;
f 0.25;
w 2 * pi * f ;
fundamental=sin(w*t);
harmaonic2=sin(2*w*t);
harmaonic3=sin(3*w*t);
harmaonic4=sin(4*w*t);
hold on;
plot(t,fundamental,'ro');
plot(t,harmonic2,'k--');
plot(t,harmonic3,'m:');
plot(t,harmonic4,'y');
hold off
8
For square wave generation by ‘cos’ functions odd harmonics we
use.
X(t)=4/π; (Cos (wt) – 1/3 Cos (3 wt) + 1/5 Cos (5 wt)+…….
Example#3
t 0 : 0.01: 6
f 0.5
w 2* pi * f
% plot function x(t)
EXERCISE:
E.1. Write MATLAB function for plotting the 5 harmonics of a signal x(t)=cos(wt) with
a fundamental frequency of f = 0.5 Hz. Take t = 0:0.01:2
E.2. What are the frequencies and Time periods at the all 5 harmonics in questions E.1.
E.3. If the frequency of x(t) = sin(2πft) is f = o.2hz what will be the time period of the 4rth
harmonic of the above signal x(t). plot x(t) and its 4rth harmonic and check the time period of
4rth harmonic in MATLAB. Do result agree with your theoretical calculation of time period
of 4rth harmonic?