Documente Academic
Documente Profesional
Documente Cultură
Instructor:
Semester:
Session:
Handout:
Student Name:
Date:
Ghulam Abbas
Fall 2014
EE-10
3
Signals are broadly classified into analog and discrete signals. An analog is denoted by xa(t),
where t is time is seconds. A discrete-time signal is represented as a sequence of numbers, called
samples. These samples are denoted by x(n), where n is integer-valued and represents discrete
instances in time. An example of a discrete time signal is:
x(n) = {2,1,-1,0,1,4,3,5}
1
0
=0
= ,0,0,0,1,0,0,0,
0
In MATLAB, the function zeros(1,N) is used to generate unit sample sequence over a finite
interval of length N.
u=[1 zeros(1,N-1)];
A unit sample sequence of length N and delayed by samples M, where M < N, can be generated by
ud=[zeros(1,M) 1 zeros(1,N-M-1)];
Program 1:
Generate unit sample sequence for -10 n 20.
>> n=-10:20;
>> u=[zeros(1,10) 1 zeros(1,20)];
>> stem(n,u)
Unit Step Sequence
A unit step sequence is defined by
u(n) =
1 0
= ,0,0,0,1,1,1,1,
0 <0
In MATLAB, the function ones(1,N) is used to generate unit step sequence over a finite interval
of length N.
S=[ones(1,N)];
A unit step sequence of length N delayed by samples M, where M < N, can be generated by
sd=[zeros(1,M) ones(1,N-M)]
Program 2:
Generate unit step sequence u(n) for -10 n 20.
>> n=-10:20;
>> u=[zeros(1,10) ones(1,21)];
>> stem(n,u)
Exponential Signals
Real-valued exponential sequence is given by
x(n)= an, n
In MATLAB an array operator .^ is required to implement a real exponential sequence.
Program 3:
Generate a real-valued exponential sequence x(n)= an , a=1.2 for 0 n 20.
>> n=0:20;
>> a=1.2;
>> x=a.^n;
>> stem(n,x)
x1(n1)= [-2,-6,-7,5,-1,10,11]
x2(n2)=[0,4,5,6,1,-1,-10,9,5,4,3,2,12]
>> x1=[-2,-6,-7,5,-1,10,11];
>> x2=[0,4,5,6,1,-1,-10,9,5,4,3,2,12];
>> n1=-3:3;
>> n2=-6:6;
>> n=min(min(n1),min(n2)):max(max(n1),max(n2));
>> y1=zeros(1,length(n));
>> y2= zeros(1,length(n));
>> y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
>> y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
>> y=y1+y2;
>> subplot(311);
>> stem(n1,x1)
>> subplot(312)
>> stem(n2,x2)
>> subplot(313)
4
>> stem(n,y)
Signal Multiplication
This is a sample by sample multiplication (dot multiplication) given by
{x1(n)}.{x2(n)}={x1(n).x2(n)}
In MATLAB it is implemented by array operator .*. The same restrictions apply for signal multiplication
as for signal addition.
The following MATLAB routine demonstrated these operations
% implement y(n)= x1(n).x2(n)
n=min(min(n1),min(n2)):max(max(n1),max(n2)); %duration of y(n)
y1=zeros(1,length(n)); y2=y1;
%initialization
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
% x1 with duration of y(n)
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
% x2 with duration of y(n)
y=y1.*y2;
% sequence multiplication
Program 7:
Find
where
x1(n1)= [-2,-6,-7,5,-1,10,11]
x2(n2)=[0,4,5,6,1,-1,-10,9,5,4,3,2,12]
>> x1=[-2,-6,-7,5,-1,10,11];
>> x2=[0,4,5,6,1,-1,-10,9,5,4,3,2,12];
>> n1=-3:3;
>> n2=-6:6;
>> n=min(min(n1),min(n2)):max(max(n1),max(n2));
>> y1=zeros(1,length(n));
>> y2=y1;
>> y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
>> y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
>> y=y1.*y2;
>> subplot(311);
>> stem(n1,x1)
>> subplot(312)
>> stem(n2,x2)
>> subplot(313)
>> stem(n,y)
Signal Folding
In this operation each sample of x(n) is flipped around n=0 to obtain a folded sequence
y(n)
y(n) = {x(-n)}
In MATLAB this operation is implemented by fliplr(x) function for sample values and by fliplr(n)
function for sample positions.
Program 8:
Find x(-n) where x(n) = [1,2,5,4,1].
>> n=-1:3;
>> x=[1,2,5,4,1];
>> y=fliplr(x);
>> n1=-fliplr(n);
>> subplot(211);
>> stem(n,x);
>> subplot(212);
>> stem(n1,y);
Signal Scaling
In this operation each sample is multiplied by a scalar .
= {()}
An arithmetic operator * is used to implement the scaling operation in MATLAB.
Program 9
Find 2x(n) where x(n)=[1,2,5,4,1].
>> n=-1:3;
>> x=[1,2,5,4,1];
>> y=2*x;
>> stem(n,y)
Signal Shifting
In this operation each sample of x(n) is shifted by an amount k to obtain a shifted
sequence y(n).
y(n) = {x(n-k)}
If we take m=n-k then n=m+k and the above operation is given by
y(m+k) = {x(m)}
So there is no effect on the vector x, but the vector n is changed by adding k to each element.
Program 10
Find x(n-2) where x(n)=[1,2,5,4,1].
>> n=-1:3;
>> x=[1,2,5,4,1];
>> n1=n+2;
>> subplot(211);
>> stem(n,x)
>> subplot(212);
>> stem(n1,x)
Sample Summation
It adds all sample values of x(n) between n1 and n2.
2
= 1 + (2 )
=1
() = 1 (2 )
1
() =
Where superscript * denotes the operation of complex conjugation. The energy of a finiteduration sequence x(n) can be computed in MATLAB using the following
Program 11
Find energy of x(n) = [0,1,2,2,2].
>> x=[0,1,2,2,2];
>> E=sum(abs(x).^2)
Signal Power
The average power of a periodic sequence with fundamental period N is given by
1
=
Program 12
Find power of x(n) = *,1,0.5,0,1,0.5,0,1,0.5,0,+ having period N=3.
>> x=[1,0.5,0];
>> N=3;
>> P=(sum(abs(x).^2))/N
Even and Odd Signals
A real valued sequence () is called even if
() = ()
Similarly a real valued sequence () is called odd if
= ()
Any arbitrary real valued sequence x(n) can be decomposed into its even and odd components
() = + ()
Where the even and odd parts are given by
=
1
[ + ()]
2
1
[ ()]
2
And
Program 13
Find even and odd parts of x(n)=u(n) for -10 n 10.
>> x1=[zeros(1,10) ones(1,11)];
>> n1=-10:10;
>> x2=fliplr(x1);
>> n2=-fliplr(n1);
>> n=min(min(n1),min(n2)):max(max(n1),max(n2));
>> y1=zeros(1,length(n));
>> y2=zeros(1,length(n));
>> y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
8
>> y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
>> ye=(y1+y2)/2;
>> y0=(y1-y2)/2;
>> subplot(311);
>> stem(n,x1)
>> subplot(312)
>> stem(n,ye)
>> subplot(313)
>> stem(n,y0)
Program 14: Let x=[1,2,3,1,4]
Generate and plot x(1-n).
x=[1,2,3,1,4];
n=-2:2;
x1=fliplr(x);
n1=-fliplr(n);
n2=n1+1;
subplot(311);
stem(n,x);
subplot(312);
stem(n1,x1);
subplot(313);
stem(n2,x1);