Digital Signal Processing Lab Manual
-
Upload
umamaheswari-venkatasubramanian -
Category
Documents
-
view
187 -
download
8
Transcript of Digital Signal Processing Lab Manual
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
LAB MANUAL
DIGITAL SIGNAL PROCESSING
SUBMITTED TO:
ENGR.USMAN CHEEMA
SUBMITTED BY:
ASAD NAEEM
2006-RCET-EE-22
DEPARTMENT OF ELECTRICAL ENGINEERING (A CONSTITUENT COLLEGE: RACHNA COLLEGE OF ENGINEERING &
TECHNOLOGY GUJRANWALA) UNIVERSITY OF ENGINEERING & TECHNOLOGY LAHORE, PAKISTAN
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
LIST OF EXPERIMENTS
EXP# TITLE 01 Introduction to MATLAB and its basic commands
02 Introduction to different types of discrete time signals and their plotting
03
Introduction to different operations on sequences
04
Generation of sinusoidal signals in MATLAB
05 Generation of complex exponential signals in MATLAB
06 Sampling of discrete time signals in MATLAB
07
Understanding of aliasing effect of discrete time signals in MATLAB
08
Study of Discrete-Time Linear and Non-Linear Systems in MATLAB
09 Study of Convolution Theorem in MATLAB 10 Study of Correlation Theorem in MATLAB 11 Study of Z-Transform in MATLAB
12 Study of frequency response in MATLAB
13 Study of Discrete-Time Fourier Transform in MATLAB 14 Study of Time Shifting Property of Discrete-Time Fourier
Transform in MATLAB 15 Study of Frequency Shifting Property of Discrete-Time Fourier
Transform in MATLAB 16 Study of Convolution Shifting Property of Discrete-Time Fourier
Transform in MATLAB 17 Study of Modulation Shifting Property of Discrete-Time Fourier
Transform in MATLAB
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 01
Introduction to MATLAB and its basic commands
MATLAB:
This is a very important tool used for making long complicated calculations and plotting graphs of different functions depending upon our requirement. Using MATLAB an m-file is created in which the basic operations are performed which leads to simple short and simple computations of some very complicated problems in no or very short time.
Some very important functions performed by MATLAB are given as follows:
• Matrix computations • Vector Analysis • Differential Equations computations • Integration is possible • Computer language programming • Simulation • Graph Plotation • 2-D & 3-D Plotting
Benefits:
Some Benefits of MATLAB are given as follows:
• Simple to use • Fast computations are possible • Wide working range • Solution of matrix of any order • Desired operations are performed in matrices • Different Programming languages can be used • Simulation is possible
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
Basic Commands:
Some basic MATLAB commands are given as follows:
Addition:
A+B
Subtraction:
A-B
Multiplication:
A*B
Division:
A/B
Power:
A^B
Power Of each Element individually:
A.^B
Range Specification:
A:B
Square-Root:
A=sqrt(B)
Where A & B are any arbitrary integers
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
Basic Matrix Operations:
This is a demonstration of some aspects of the MATLAB language.
Creating a Vector:
Let’s create a simple vector with 9 elements called a.
a = [1 2 3 4 6 4 3 4 5] a = 1 2 3 4 6 4 3 4 5
Now let's add 2 to each element of our vector, a, and store the result in a new vector.
Notice how MATLAB requires no special handling of vector or matrix math.
Adding an element to a Vector: b = a + 2 b = 3 4 5 6 8 6 5 6 7
Plots and Graphs:
Creating graphs in MATLAB is as easy as one command. Let's plot the result of our vector addition with grid lines.
Plot (b) grid on
MATLAB can make other graph types as well, with axis
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
labels.
bar(b) xlabel('Sample #') ylabel('Pounds')
MATLAB can use symbols in plots as well. Here is an example using stars to mark the points. MATLAB offers a variety of other symbols and line types.
plot(b,'*') axis([0 10 0 10])
One area in which MATLAB excels is matrix computation.
Creating a matrix:
Creating a matrix is as easy as making a vector, using semicolons (;) to separate the rows of a matrix.
A = [1 2 0; 2 5 -1; 4 10 -1] A = 1 2 0 2 5 -1 4 10 -1 Adding a new Row: B(4,:)=[7 8 9] ans= 1 2 0
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
2 5 -1 4 10 -1 7 8 9 Adding a new Column: C(:,4)=[7 8 9] ans= 1 2 0 7 2 5 -1 8 4 10 -1 9 Transpose:
We can easily find the transpose of the matrix A.
B = A' B = 1 2 4 2 5 10 0 -1 -1 Matrix Multiplication:
Now let's multiply these two matrices together.
Note again that MATLAB doesn't require you to deal with matrices as a collection of numbers. MATLAB knows when you are dealing with matrices and adjusts your calculations accordingly.
C = A * B C = 5 12 24 12 30 59 24 59 117 Matrix Multiplication by corresponding elements: Instead of doing a matrix multiply, we can multiply the corresponding elements of two matrices or vectors using the’.* ‘operator.
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
C = A .* B C = 1 4 0 4 25 -10 0 -10 1 Inverse:
Let's find the inverse of a matrix ...
X = inv(A) X = 5 2 -2 -2 -1 1 0 -2 1 ... and then illustrate the fact that a matrix times its inverse is the identity matrix. I = inv(A) * A I = 1 0 0 0 1 0 0 0 1
MATLAB has functions for nearly every type of common matrix calculation.
Eigen Values:
There are functions to obtain eigenvalues ...
eig(A) ans = 3.7321 0.2679 1.0000
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
Singular Value Decomposition: The singular value decomposition svd(A) ans = 12.3171 0.5149 0.1577 Polynomial coefficients: The "poly" function generates a vector containing the coefficients of the characteristic polynomial.
The characteristic polynomial of a matrix A is
p = round(poly(A))
p = 1 -5 5 -1 We can easily find the roots of a polynomial using the roots function.
These are actually the eigenvalues of the original matrix.
roots(p)
ans = 3.7321 1.0000 0.2679 MATLAB has many applications beyond just matrix computation.
Vector Convolution:
To convolve two vectors ...
q = conv(p,p) q = 1 -10 35 -52 35 -10 1
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
... Or convolve again and plot the result.
r = conv(p,q) plot(r); r = 1 -15 90 -278 480 -480 278 -90 15 -1
Matrix Manipulation:
We start by creating a magic square and assigning it to the variable A.
A = magic(3) A = 8 1 6 3 5 7 4 9 2
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 02
Introduction to different types of discrete time signals and their plotting
Introduction:
Discrete time signals are defined only at certain specific values of time. They can be represented by x[n] where ‘n’ is integer valued and represents discrete instances in time. i.e:
X[n] = {…., x[-1], x[0] ,x[1] ,…..}
Where the up-arrow indicates the sample at n=0.
In MATLAB, we can represent a finite-duration sequence like above by a row of vector of appropriate values. However such a vector does not have any information about sample position n. therefore a correct representation of x[n] would require two vectors, one each for x and n. for example a signal
X[n] = {2,1,-1,0,1,4,3}
>>n=[-3,-2,-1,0,1,2,3];
>>x=[2,1,-1,0,1,4,3];
• An arbitrary infinite duration signal cannot be represented by MATLAB due to finite memory limitations.
Basic Signals:
Unit Sample Sequence
>>function[x, n] =impseq (n0, n1, n2)
% Generates x[n] =delta (n-n0) ; n1<=n<=n2
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
% n1 is lower limit of required sequence;n2 is upper limit of required sequence
>>n=n1:n2;x=(n-n0)==0;
>>stem(n,x);
>>title(‘Delayed Impulse’);
>>xlabel(‘n’);
>>ylabel(‘x[n]’);
Practice:
Use above function to plot unit sample sequence that has a value at n=-9 in a range fro n=-14 to n=-2. Use zeros(1,N) command to generate above unit sample sequence function…
MATLAB CODE:
>> n0=-9;
>> n1=-14;
>> n2=-2;
>> n=n1:n2;
>> x=(n-n0)==0;
>> stem(n,x)
>> title('Delayed Impulse Sequence')
>> xlabel('n')
>> ylabel('x[n]')
PLOT:
>>funct
% Gene
% n1 is
>>n=n1
>>stem
>>title(
>>xlabe
tion[x, n] =
erates x[n]
lower lim
1:n2;x=(n-n
(n,x);
‘Delayed S
el(‘n’);
=stepseq (n
] =u (n-n0)
mit of requ
n0)>=0;
Step Seque
Uni
n0, n1, n2
) ; n1<=n<
ired seque
ence’);
it Step Seq
)
=n2
ence;n2 is u
quence
upper limiit of requi
PREPARASAD N
2006‐RCET‐
red sequen
RED BY NAEEM ‐EE‐22
nce
>>ylabe
Practice
Use aboshifted step seq
MATLA
>> n0=-
>> n1=-
>> n2=1
>> n=n1
>> x=(n
>> stem
>> title(
>> xlab
>> ylab
PLOT:
el(‘x[n]’);
e:
ove functioat n=-3. U
quence fun
AB CODE
-3;
-5;
15;
1:n2;
n-n0)>=0;
m(n,x)
('Delayed
el('n')
el('x[n]')
on to plot Use zeros(1nction…
:
Step Sequ
unit step s1,N) and on
ence')
sequence hnes(1,N) c
having ranommands
nge betweeto genera
PREPARASAD N
2006‐RCET‐
en -5 and ate above u
RED BY NAEEM ‐EE‐22
15, unit
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
Real-valued Exponential Sequence
X[n] = an
In MATLAB, we can write
>>n=0:10; x=(0.9).^n
MATLAB RESULT OF ABOVE COMMAND:
x =
Columns 1 through 7
1.0000 0.9000 0.8100 0.7290 0.6561 0.5905 0.5314
Columns 8 through 11
0.4783 0.4305 0.3874 0.3487
Complex-valued Exponential Sequence
X[n] = e(a+jw0)n , for all n
MATLAB function exp is used to generate exponential sequences. For example to generate
X[n]=exp[(2+3j)n],0<=n<=10, we can write:
>>n=0:10;x=exp((2+3j)*n)
MATLAB RESULT OF ABOVE COMMAND:
x =
1.0e+008 *
Columns 1 through 4
0.00 -0.00+0.00i 0.00-0.00i -0.00+0.00i
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
Columns 5 through 8
0.00-0.00i -0.0002+0.0001i 0.0011-0.0012i -0.0066+0.0101i
Columns 9 through 11
0.0377-0.0805i -0.1918+0.6280i 0.7484-4.7936i
Practice:
Generate a complex exponential given below in MATLAB and also plot the output…
X[n] = 2e(-0.5+(∏/6)j)n
MATLAB CODE:
>> n=0:10;
>> a=2;
>> b=exp((-0.5+(pi/6)*j)*n);
>> x=a*b
>> plot(n,x)
MATLAB RESULT:
x =
Columns 1 through 4
2.000 1.050+0.606i 0.367+0.637i 0.000+0.446i
Columns 5 through 8
-0.135+0.234i -0.142+0.082i -0.099+0.000i -0.052-0.030i
Column
-0.018-
PLOT:
MATLA
Practice
Generaoutput…
>>x[n]=
MATLA
>> n=0:
>> a=3*
>> b=2*
ns 9 throug
0.032i -
AB functio
e:
te a sinuso…
=3cos(0.1n
AB CODE
10;
cos((0.1*n
*sin(0.5*n*p
gh 11
-0.000-0.02
on sin or c
oidal signa
n∏+∏/3)+2
:
*pi)+pi/3);
pi);
22i 0.00
Sinu
X[n]=cos(w
os is used
al given be
2sin(0.5n∏
07-0.012i
usoidal Seq
w0n+Ѳ), fo
to generat
elow in MA
∏)
quence:
or all n
te sinusoid
ATLAB an
dal sequen
nd also plo
PREPARASAD N
2006‐RCET‐
nces.
t the
RED BY NAEEM ‐EE‐22
>> x=a+
>> plot(
PLOT:
Many pthose abcharactstatisticsequencgeneratAbove msequenc
+b;
(n,x)
practical sebove. Thesterized by cal momence whose etes a lengthmentionedces.
equences cse signals aparameter
nts. In MAelements ah N Guassd function
Ra
cannot be are called rs of associ
ATLAB ranare uniformian random
ns can be tr
andom Sig
described random oiated prob
nd (1, N) gemly distribm sequencransforme
gnals:
by mathemr stochasti
bability denenerates a buted betwce with meed to gener
matical exic signals ansity funclength N
ween [0, 1]ean 0 and rate other
PREPARASAD N
2006‐RCET‐
xpressions and are tions or thrandom ].randn (1variance 1random
RED BY NAEEM ‐EE‐22
like
heir
, N) 1.
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXAMPLE:
>> rand(1,5)
RESULT:
ans =
0.0975 0.2785 0.5469 0.9575 0.9649
Periodic Signals:
Nncopy can be used to produce a vector with repeating sequence. If we want a vector ‘x’ in below example to repeat for three times, we can use,
>>x=[1 2 3];
>>y=nncopy(x,1,3);
1 2 3 1 2 3 1 2 3
Practice:
Write MATLAB code for generating a periodic sequence using only ‘ones’ command.
CODE:
>> x=ones(1,2);
>> y=nncopy(x,3,3)
RESULT:
y = 1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 03
Introduction to different operations on sequences
Operations on sequences:
Signal addition:
In MATLAB, two sequences are added sample by sample using arithmetic operator ‘+’. However if lengths of sequences are different or if sample positions are different for equal-length sequences, then we can not directly use ‘+’ operator. In this case, we have to augment the sequences so that they have same position vector ‘n’(and hence the same length). Following is the code for sequence addition keeping in view above mentioned facts.
Function[y,n]=sigadd(x1,n1,x2,n2)
%implemnts y[n]=x1[n]+x2[n]
%y=sum sequence over n which includes n1 and n2
%x1=first sequence over n1
%x2=second sequence over n2(n2 can be different from n1)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeroes(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;
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
Practice:
x1[n]=[3,11,7,0,-1,4,2] and x2[n]=[2,3,0,-5,2,11]
Use above function to add two signals.
MATLAB CODE:
x1=[3 11 7 0 -1 4 2];
x2=[2 3 0 -5 2 11];
n1=4;%initial element number of x1
n2=3;%initial element number of x2
if n2<n1
x2=[zeros(1,length(n1-n2)) x2];
x1=x1;
if length(x1)>length(x2)
x2=[x2 zeros(1,length(x1)-length(x2))]
x1=x1
x=x1+x2
elseif length(x1)<length(x2)
x1=[x1 zeros(1,length(x2)-length(x1))]
x2=x2
x=x1+x2;
elseif length(x1)==length(x2)
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
x=x1+x2;
end
elseif n2>n1
x1=[zeros(1,length(n2-n1)) x1];
x2=x2;
if length(x1)>length(x2)
x2=[x2 zeros(1,length(x1)-length(x2))]
x1=x1
x=x1+x2
elseif length(x1)<length(x2)
x1=[x1 zeros(1,length(x2)-length(x1))]
x2=x2
x=x1+x2;
elseif length(x1)==length(x2)
x=x1+x2;
end
elseif n2==n1
if length(x1)>length(x2)
x2=[x2 zeros(1,length(x1)-length(x2))]
x1=x1
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
x=x1+x2
elseif length(x1)<length(x2)
x1=[x1 zeros(1,length(x2)-length(x1))]
x2=x2
x=x1+x2;
elseif length(x1)==length(x2)
x=x1+x2;
end
end
MATLAB RESULTS:
x2 = 2 3 0 -5 2 11 0 0
x1 = 0 3 11 7 0 -1 4 2
x = 2 6 11 2 2 10 4 2
Signal multiplication:
In MATLAB, two signals are multiplied sample by sample using array operator ‘*’. Similar instructions regarding position vector imply for multiplication as for addition.
Practice:
Write a MATLAB function sigmult to multiply two signals x1[n] and x2[n], where x1[n] and x2[n] may have different durations. Call this function to multiply any two signals.
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
MATLAB RESULTS:
x2 = 2 3 0 -5 2 11 0 0
x1 = 0 3 11 7 0 -1 4 2
x = 0 9 0 -35 0 -11 0 0
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]
This operation has no effect on vector x but vector n is changed by adding k to each element.
Function[y,n]=sigshift(x,m,n0)
%implements y[n]=x[n-n0]
n=m+n0;
y=x;
Signal Folding:
In this operation each sample of x[n] is flipped around n=0 to obtaib a folded sequence y[n].
y[n]=x[-n]
In MATLAB, this function is implemented by flipr(x) function for sample values and by –flipr(n) function for sample positions.
Function[y,n]=sigfold(x,n)
%implements y[n]=x[-n]
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
Y=flipr(x);
n=-flipr(n)
Sample Summation and Sample Product:
It adds all sample values of x[n] between n1 and n2. It is implemented by sum(x(n1:n2)).
Sample multiplication multiplies all sample values of x[n] between n1 and n2. It is implemented by prod(x(n1:n2)).
MATLAB CODE FOR SUMMATION:
x=[1 2 3 4 5 6];
n1=x(1,3);
n2=x(1,5);
sum(x(n1:n2))
RESULT:
ans =12
MATLAB CODE FOR PRODUCT:
x=[1 2 3 4 5 6];
n1=x(1,3);
n2=x(1,5);
prod(x(n1:n2))
RESULT:
ans =60
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
Signal Energy:
Energy of a finite duration sequence x[n] can be computed in MATLAB using
>>Ex=sum(x.*conj(x));
or
>>Ex=sum(abs(x).^2);
MATLAB CODE:
x=[1 2 3];
Ex=sum(abs(x).^2)
RESULT:
Ex =14
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 04
Generation of sinusoidal signals in MATLAB
THEORY:
In this lab, discrete-time sinusoidal signal has been introduced. A discrete sinusoidal signal can be either sine or cosine time discrete signal and it can be expressed by:
X(n)=Asin(wn+ф), -∞<n<∞
Where w=2*pi*f
Therefore
x(n)=Asin(2*pi*fn+ ф), -∞<n<∞
Similarly, discrete-time sinusoidal signal for a cosine function can be expressed as
X(n)=Acos(2*pi*fn+ ф), -∞<n<∞
Where
n=integer variable called the sampler no.
A=Amplitude of the sinusoid.
w=frequency in radian per sample
ф =phase in radians
As the maximum value of the functions SINE & COSINE is unity, the A acts as a scaling factor giving maximum and minimum values of ±A.
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
OBJECTIVES:
• To learn the generation of discrete time sinusoidal signals • To perform the elementary operations of shifting(advanced and delayed) • To learn the techniques of doing scaling(time and amplitude) • To learn the application of some basic commands of MATLAB for simple
digital signal processing problems
MATLAB CODE:
n=0:40;
f=0.1;
phase=0;
A=1.5;
arg=2*pi*f*n-phase;
x=A*cos(arg);
clf; %clear and graph stem(n,x);
axis([0 40 -2 2]);
grid;
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
axis;
RESULT
ANSWE
(1)Wha
ANS: n
(2)Wha
ANS: f=
(3)Wha
ANS: p
(4)Wh
ANS: A
(5)Wh
ANS: f=
T:
ERS TO T
at is the pe
n=10
at comman
=0.1
at paramet
phase
at parame
A
at is the F
=0.1 Hz
THE QUES
eriod of th
nd line con
ter control
ter contro
REQUENC
STIONS:
e Sequenc
ntrols the
ls the PHA
ols the AM
CY of this
ce?
FREQUEN
ASE of this
MPLITUDE
Sequence
NCY in the
s sequence
E of the seq
e?
e program
e?
quence?
PREPARASAD N
2006‐RCET‐
m?
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 05
Generation of complex exponential signals in MATLAB
THEORY:
In this lab, discrete-time complex exponential signal has been introduced. By using complex numbers the exponential and sinusoidal signals can be written as special cases of a more general signal, the complex exponential.
Consider the case:
X(n)=Aean
If ‘a’ is real, it is a simple discrete-time exponential signal. Taking, a=jw the signal becomes:
X(n)=Aejwn
X(n)=Acos(wn)+jsin(wn)
Hence, the discrete-time exponential signal can be generalized to represent a sinusoidal of arbitrary phase by writing:
X(n)=Aej(nѲ+ф) =AejnѲ*ejф
OBJECTIVES:
• To learn the generation of discrete time complex exponential signals • To learn the effect of changing different parameters of the signal • To learn the application of some basic commands of MATLAB for simple
digital signal processing problems
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
MATLAB CODE:
%Generation of a complex EXPONENTIAL SEQUENCE
clf;
c=-(1/12)+(pi/6)*i;
k=2;
n=0:40;
x=k*exp(c*n);
subplot(2,1,1);
stem(n,real(x));
xlabel('Time index n');
ylabel('Amplitude');
title('Real part');
subplot(2,1,2);
stem(n,imag(x));
xlabel('Time index n');
ylabel('Amplitude');
title('imaginary part');
Result:
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 06
Sampling of discrete time signals in MATLAB
MATLAB CODE:
%Illustration of sampling process %in the time domain clf; t=0:0.0005:1; f=13; xa=cos(2*pi*f*t); subplot(2,1,1) plot(t,xa); grid; xlabel('Time,msec'); ylabel('Amplitude'); title('Continuous time signalx_{a}(t)'); axis([0 1 -1.2 1.2]) subplot(2,1,2); T=0.1; n=0:T:1; xs=cos(2*pi*f*n); k=0:length(n)-1; stem(k,xs); grid; xlabel('Time index n'); ylabel('Amplitude'); title('Discrete time signalx[n]'); axis([0 (length(n)-1) -1.2 1.2
MATLA
AB RESULLT:
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 07
Understanding of aliasing effect of discrete time signals in MATLAB
THEORY:
Aliasing is the phenomenon that results in a loss of information when a signal is reconstructed from its sampled signal.
In Principle, the analogue can be reconstructed from the samples, provided that the sampling rate is sufficiently high to avoid the problem called “Aliasing”.
MATLAB CODE:
%Illustration of Aliasing Effect in the Time-Domain
clf;
t=0:0.0005:1;
f=13;
xa=cos(2*pi*f*t);
subplot(2,1,1)
plot(t,xa);
grid
Xlabel('Time,msec');
Ylabel('Amplitude');
title('Continous=time signal x_{a}(t)');
axis([0 1 -1.2 1.2])
subplot
T=0.1;
F=13;
n=0:T:1
xs=cos(2
t=linspa
ya=sinc
plot(n,x
grid;
xlabel('
ylabel('
title('Re
axis([0 1.2 1.2]
RESULT
t(2,1,2);
1;
2*pi*f*n);
ace(-0.5,5,
c((1/T)*t(:,o
xs,'0',t,ya);
Time,mse
Amplitud
econstruct
1 -);
T:
500);
ones(size(n
;
c');
e');
ted continu
n)))-(1/T)*
uous-time
*n(:,ones(s
e signal y_
ize(t))))*xs
{a}(t)');
s;
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 08
Study of Discrete-Time Linear and Non-Linear Systems in MATLAB
THEORY:
In this experiment following two types of Discrete-Time systems have been introduced.
Linear Discrete-Time system:
A system which satisfies “Super-Position Principle” is a linear system.
Hence, a relaxed “T” system is linear if and only if
T[a1x1(n)+ x2(n)=Ta1[x1(n)]+Ta2[x2(n)]
For any arbitrary input sequences x1(n) and x2(n), and arbitrary constants a1 and a2
Non-Linear Discrete-Time system:
A system which doesn’t satisfy “Super-Position Principle”, given above is non-linear system.
In this lab given below, we investigate LINEARITY property of a causal system of the type given below;
∑ k ∑ k x(n-k)
MATLAB CODE:
>> %Generate the input sequences
>> a=2;
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
>> b=-3;
>> clf;
>> n=0:40;
>> X1=cos(2*pi*0.1*n);
>> X2=cos(2*pi*0.1*n);
>> X=a*X1+a*X2;
>> num=[2.2403 2.4908 2.2403];
>> den=[1 -0.4 0.75];
>> ic=[0 0];
>> Y1=filter(num,den,X1,ic); %Compute the output Y1[n]
>> Y2=filter(num,den,X2,ic); %Compute the output Y2[n]
>> Y=filter(num,den,X,ic); %Compute the output Y[n]
>> Yt=a*Y1+b*Y2;
>> d=Y-Yt;%Compute the difference output d[n]
>> %Plot the output and difference signal
>> subplot(3,1,1)
>> stem(n,Y);
>> ylabel('Amplitude');
>> title('Output Due to Weighted Input:a\cdot x_{1}[n]+b\cdot x_{2}[n]');
>> subplot(3,1,2)
>> stem
>> ylab
>> title(
>> subp
>> stem
>> xlab
>> ylab
>> title(
RESULT
m(n,Yt);
el('Amplit
('Output D
plot(3,1,3)
m(n,d);
el('Time in
el('Amplit
('Differenc
T:
tude');
Due to We
ndex n');
tude');
ce Signal')
eighted Inp
;
put:a\cdot y_{1}[n]++b\cdot y_{
PREPARASAD N
2006‐RCET‐
{2}[n]');
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 09
Study of Convolution Theorem in MATLAB
THEORY:
The convolution of the equation
Y[n]=h[n]*x[n]
is implemented in MATLAB by the command copy, provided the two sequences to be convolved are of finite length. For example, the output sequence of an FIR system can be computed by convolving its impulse response with a given finite-length input sequence.
The following MATLAB program illustrates this approach;
MATLAB CODE:
>> clf;
>> h=[3 2 1 -2 1 0 -4 0 3];
>> x=[1 -2 3 -4 3 2 0 0 1];
>> y=conv(h,x);
>> n=0:4;
>> plot(1,1);
>> stem(n:y);
>> xlabel('Time Index');
>> ylabel('Amplitude');
>> title('Output Obtained by Convolution');
>> grid;
MATLA
;
AB RESULLT:
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 10
Study of Correlation Theorem in MATLAB
THEORY:
“Correlation is the process that is necessary to be able to quantify the degree of interdependence of one process upon another or to establish the similarity between one set of data and another.”
Hence, the correlation between the processes can be sought and can be defined mathematical and can be quantified.
Correlation is also an integral part of the process of convolution. The convolution process is essential the correlation of two data sequences in which one of the sequences have been reversed.
This means that the same algorithms may be used to compute correlations and convolutions simply by reversing one of the sequences.
The two types of correlations discussed in this lab are;
• Cross Correlation • Auto Correlation
MATLAB CODE:
>> %Output Obtained by Cross Correlation
>> clf;
>> x1=[4 2 -1 3 -2 -6 -5 4 5];%first sequence
>> x2=[-4 1 3 7 4 -2 -8 -2 1];%second sequence
>> y=xcorr(x1,x2);
>> n=0:
>> plot(
>> stem
>> xlab
>> ylab
>> title(
>> grid;
MATLA
16;
(1,1);
m(n:y);
el('Time In
el('Amplit
('Output O
;
AB RESUL
ndex');
tude');
Obtained b
LT:
by Correlation');
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 11
Study of Z-Transform in MATLAB
THEORY:
Z-Transform technique is an important tool in the analysis of characterization of discrete time signals and LTI systems; Z-Transform gives the response of various signals by its pole zero locations.
Z-Transform is an important tool in DSP that gives the solution of difference equation in one go.
The Z-Transform of a discrete time system x (n) is defined as power series;
X(z)=∑ ^∞
And the inverse Z-Transform is denoted by;
X(n)=Z-1[X(n)]
Since, Z-Transform is the infinite power series; it exists only for the region for which this series converges (region of convergence). Inverse Z-Transform is the method for inverting the Z-Transform of a signal so as to obtain the time domain representation of signal.
The features of Z-Transform which are explained are as fellows;
Z-Transform of a Discrete time function
EXAMPLE:
1 1.6180 ^ 21 1.5161z^ 1 0.8781z^ 2
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
MATLAB CODE:
>> b=[1 -1.6 180 1];
>> a=[1 -1.5 161 0.878];
>> A=roots(a)
>> B=roots(b)
>> zplane(b,a)
RESULTS:
A =
0.7527 +12.6666i
0.7527 -12.6666i
-0.0055
B =
0.8028 +13.3927i
0.8028 -13.3927i
-0.0056
Pole=Ze
Z-Tran
Or
Let the
MATLA
>> syms
>>a=ztr
MATLA
ans=
ero Diagra
Z-TR
sform is de
difference
AB CODE
s z n
rans(1/4^n
AB RESUL
am:
RANSFOR
efined as,
e equation
:
n)
LT:
RM OF A D
X(z)=
X(z
n be,
DISCRETE
z)=Z[x(n)]
E TIME FU
UNCTION
PREPARASAD N
2006‐RCET‐
N:
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
4*z/4*z-1
INVERSE Z-TRANSFORM:
The inverse Z-Transform is denoted by,
X(n)=Z-1[X(z)]
Let the Z-domain is:
2z2zs 1
MATLAB CODE:
>> syms z n
>>iztrans(2*z/(2*z-1))
MATLAB RESULT:
ans=
(1/2)^n
POLE ZERO DIAGRAM FOR A FUNCTION IN Z-DOMAIN
‘zplane’ command computes and displays the pole-zero diagram of z-function.
The command is
>>zplane(b,a)
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 12
Study of frequency response in MATLAB
FREQUENCY RESPONSE ESTIMATION
The freqz function computes and displays the frequency response of given Z=Transform of the function.
The command is
>>freqz(b,a,npt,Fs)
Where, Fs is the Sampling Frequency, npt is the no. of frequency points between and Fs/2.
EXAMPLE:
1 1.6180 ^ 21 1.5161z^ 1 0.8781z^ 2
MATLAB CODE:
>> b=[1 -1.6 180 1];
>> a=[1 -1.5 161 0.878];
>> freqz(b,a)
MATLA
AB RESULLT:
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 13
Study of Discrete-Time Fourier Transform in MATLAB
THEORY:
The discrete-time Fourier transform (DTFT) X(ejwt)of a sequence Z(n)is a continuous function of wt. Since the data in MATLAB is in vector form, X(ejwt) can only be evaluated at a prescribed set of discrete frequencies. Moreover, only
a class of DTFT that is expressed as a rational function in e-jwt in the form,
Po P1 Pndo d1 dn
can be evaluated. In the following lab work you will learn how to evaluate DTFT and study it’s certain properties using MATLAB.
DTFT Computation
The DTFT X(e-jwt) of a sequence x(n) of the form, Po P1 Pndo d1 dn
Can be computed easily at a prescribed set of L discrete frequency points w=wf
using the MATLAB function freqz. Since, X(ejwt) is a continuous function of w, it is necessary to make L as large as possible so that the plot generated using the command provides a reasonable replica of the actual plot of DTFT. In MATLAB freqz computes the L point DFT of the sequences Po P1Pn and do d1 dn and then forms the ratio to arrive at X(ejwt).l=1,1,…,L. For faster computations L should be chosen as a power of 2, such as 256 or 512.
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
MATLAB CODE:
%Evaluation of the DTFT
clf;
%Compute the frequency samples of DTFT
w=-4*pi : 8*pi/511 : 4*pi;
num=[2 1];
den= [1 -0.6];
h=freqz (num, den, w);
%plot the DTFT
Subplot(2,1,1)
plot(w/pi,real(h));
grid
title('Real part of H(e^{j\omega})')
xlabel('\omega/\pi');
ylabel('Amplitude');
subplot(2,1,2)
plot(w/pi,imag(h));
grid
title('Real part of H(e^{j\omega})')
xlabel('\omega/\pi');
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
ylabel('Amplitude');
pause
subplot(2,1,2)
plot(w/pi,abs(h));
grid
title('Magnitude Spectrum |H(e^{j\omega})')
xlabel('\omega/\pi');
ylabel('Amplitude');
subplot(2,1,2)
plot(w/pi,abs(h));
grid
title('Phase Spectrum arg [H(e^{j\omega})]')
xlabel('\omega/\pi');
ylabel('Phase, radians');
MATLA
AB RESULLTS:
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 14
Study of Time Shifting Property of Discrete-Time Fourier Transform in MATLAB
THEORY:
Most of the properties of DTFT can be verified using MATLAB. In the following we shall verify the different properties of DTFT using MATLAB. Since all data in MATLAB have infinite length vectors, the sequences being used to verify the properties are of finite length.
TIME-SHIFTING:
%Time-shifting Properties of DTFT
clf;
w=-pi:2*pi/255:pi ;
w0=0.4*pi;
D=10;
num=[1 2 3 4 5 6 7 8 9];
h1=freqz(num,1,w);
h2=freqz([zeros(1,D) num],1,w);
subplot(2,2,1);
plot(w/pi,abs(h1));
grid
title('Magnitude Spectrum of orig Seq')
subplot
plot(w/
grid;
title('M
subplot
plot(w/
grid;
title('Ph
subplot
plot(w/
grid;
title('Ph
MATLA
t(2,2,2)
/pi,abs(h2)
Magnitude S
t(2,2,3)
/pi,angle(h
hase Spect
t(2,2,4)
/pi,angle(h
hase Spect
AB RESUL
);
Spectrum
h1));
trum of Or
h2));
trum of Tim
LTS:
of Time-S
rig Seq')
me-Shifted
Shifted Seq
d Seq')
q')
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 15
Study of Frequency Shifting Property of Discrete-Time Fourier Transform in MATLAB
FRQUENCY-SHIFTING PROPERTY:
%Frequency-Shifting Properties of DTFT
clf;
w=-pi : 2*pi/255 : pi ;
w0=0.4*pi;
num1=[1 3 5 7 9 11 13 15 17];
L=length(num1);;
h1=freqz(num1, 1,w);
n=0:L-1;
num2=exp(w0*i*n).*num1;
h2=freqz(num2, 1, w);
subplot(2,2,1);
plot(w/pi,abs(h1));
grid
title('Magnitude Spectrum of orig Seq')
subplot(2,2,2)
plot(w/pi,abs(h2));
grid;
title('M
subplot
plot(w/
grid;
title('Ph
subplot
plot(w/
grid;
title('Ph
MATLA
Magnitude S
t(2,2,3)
/pi,angle(h
hase Spect
t(2,2,4)
/pi,angle(h
hase Spect
AB RESUL
Spectrum
h1));
trum of Or
h2));
trum of Fre
LTS:
of Freq-Sh
rig Seq')
eq-Shifted
hifted Seq'
d Seq')
')
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 16
Study of Convolution Shifting Property of Discrete-Time Fourier Transform in MATLAB
CONVOLUTION PROPERTY:
%Convolution Property of DTFT
clf;
w=-pi : 2*pi/255 : pi ;
x1=[1 3 5 7 9 11 13 15 17];
x2=[1 -2 3 -2 1];
y=conv(x1,x2);
h1=freqz(x1, 1, w);
h2=freqz(x2,1,w);
hp=h1.*h2;
h3=freqz(y,1,w);
subplot(2,2,1)
plot(w/pi,abs(hp));
grid
title('Product of Magnatude Spectra')
subplot(2,2,2)
plot(w/pi,abs(h3));
grid
title('M
subplot
plot(w/
grid
title('Su
subplot
plot(w/
grid
title('Ph
MATLA
Magnatude
t(2,2,3)
/pi,angle(h
um of Phas
t(2,2,4)
/pi,angle(h
hase Spect
AB RESUL
Spectra of
hp));
se Spectra
h3));
tra of Conv
LTS:
f Convolve
')
volved Seq
ed Sequen
quence')
ce')
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22
PREPARED BY ASAD NAEEM
2006‐RCET‐EE‐22
EXPERIMENT NO: 17
Study of Modulation Shifting Property of Discrete-Time Fourier Transform in MATLAB
MODULATION PROPERTY:
%Modulation Property of DTFT
clf;
w=-pi:2*pi/255:pi ;
x1=[1 3 5 7 9 11 13 15 17];
x2=[1 -1 1 -1 1 -1 1 -1 1];
y=x1.*x2;
h1=freqz(x1,1,w);
h2=freqz(x2,1,w);
h3=freqz(y,1,w);
subplot(3,1,1)
plot(w/pi,abs(h1));
grid
title('Magnatude Spectrum of first Seq')
subplot(3,1,2)
plot(w/pi,abs(h2));
grid
title('M
subplot
plot(w/
grid
title('M
MATLA
Magnatude
t(3,1,3)
/pi,angle(h
Magnitude S
AB RESUL
Spectrum
h3));
Spectrum
LTS:
of Second
of Produc
d Seq')
ct Sequence')
PREPARASAD N
2006‐RCET‐
RED BY NAEEM ‐EE‐22