0% found this document useful (0 votes)
42 views

Tutorial 1 Report: Digital Signal Processing Lab

This tutorial report discusses generating and plotting discrete signals and their properties in MATLAB. It includes: 1) Creating impulse and step sequences and adding/multiplying signals. 2) Plotting the real, imaginary, magnitude and phase of an exponential signal. 3) Computing the cross-correlation between signals. 4) Determining the impulse and step responses of a system and checking stability. Functions are created to shift, fold, add and multiply signals. Various signals are generated and transformed using these functions and their properties analyzed.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Tutorial 1 Report: Digital Signal Processing Lab

This tutorial report discusses generating and plotting discrete signals and their properties in MATLAB. It includes: 1) Creating impulse and step sequences and adding/multiplying signals. 2) Plotting the real, imaginary, magnitude and phase of an exponential signal. 3) Computing the cross-correlation between signals. 4) Determining the impulse and step responses of a system and checking stability. Functions are created to shift, fold, add and multiply signals. Various signals are generated and transformed using these functions and their properties analyzed.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

TRƯỜNG ĐẠI HỌC BÁCH KHOA

NGUYỄN MINH TƯỜNG


CHANG NGỰ QUYỀN
GROUP 6

TUTORIAL 1 REPORT

DIGITAL SIGNAL PROCESSING LAB

Professor Lê Tiến Thường

Thành Phố Hồ Chí Minh,8 tháng 3 năm 2015


Abstract: In this tutorial we try to generate and plot some discrete function over a given
time period which include their magnitude and their phase plot as well. We also evaluate the
cross correlation between a signal and its noise super-impose counterpart. Later on, we
determine the unit step and impulse response of the system and observe if the system itself
is stable or not.

Problem 1:

a/

Creating file script:

function [x,n] = impseq (n0,n1,n2)

n = [n1:n2];

x= [(n-n0) == 0 ];

%This Matlab script represent the generalized shifted version of the impulse response

1, n  n0 
 (n  n0 )   
0, n  n0 

In Command window:

n = [-5:5];

x= 2*impseq(-2,-5,5) - impseq(4,-5,5);

stem (n,x);

Title ('Problem 1a');

xlabel('n');

ylabel('x[n]');

The result shown as the figure below:


Comment: By using the following script we will be able to plug in the corresponding
parameters to plot the giving discrete function as illustrated above.

b/

Creating file script:

function [x,n] =stepseq (n0,n1,n2)

n = [n1:n2];

x = [(n-n0) >= 0];

This script describe the unit step function


1, n  0 
u(n)   
0, n  0 

In Command window,we type:

n = [0:20];

x1=n.*(stepseq(0,0,20)- stepseq(10,0,20) );

x2=10*exp( -0.3*(n-10) ).*(stepseq(10,0,20) - stepseq(20,0,20));

x = x1 + x2;

plot (n,x);
stem (n,x);

title ('Problem 1b');

xlabel('n');

ylabel('x[n]');

The result shown as a figure below:

Comment: Similar to the previous problem we just plug in the parameter and stem-plot the
result with the given range of n.

c/

In Command window, we type:

n = [0:50];

x = cos (0.04*pi*n) + 0.2*randn(size(n));

plot (n,x);

stem (n,x);

title ('Problem 1c');

xlabel('n');

ylabel('x[n]');

The result shown as a figure below:


Comment: The Gaussian random sequence can be denote as randn(size(n)). r = randn(n)
returns an n-by-n matrix containing pseudo-random values drawn from the standard normal
distribution and the syntax r= randn(size(A)) returns an array the same size as A. The
randn(1 ,N) will generates a length N Gaussian random sequence with mean 0 and variance 1

d/

In Command window,we type:

n = [-10:9];

x= [5, 4, 3, 2, 1];

xtilde = x' * ones(1,4);

xtilde = (xtilde(:))';

plot (n,xtilde);

stem (n,xtilde);

title ('Problem 1d');

xlabel('n');

ylabel('x[n]');

The result as below:


~

Comment: On the given interval, the sequence x(n) has 4 periods. To generate
some periodic behavior of the signal from the original we can copy and
duplicate as much as we want by using the command "xtilde" .Then, we
generate a matrix containing P rows of X (n) values. Then we try to put =P rows
into a long row vector using the operator (:). However, this construct works
only on columns. Hence we will have to use the matrix transposition operator '
to provide the same effect on rows as well.
Problem 2

Creating file script first then solve the following given question:

function [y,n] = sigshift (x,m,n0)

n = m + n0;

y=x;

%This function shift the signal by some given sample y ( n )=x (n−k )

function [y,n] = sigfold(x,n)

y=fliplr(x);

n=-fliplr(n);

%This function flip the signal around n=0 to obtain the folded version of the original
y ( n )=x (−n)

function [y,n] = sigadd(x1,n1,x2,n2)

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;

%This function simply add two signals together y ( n )=x 1 ( n ) + x 2 ( n )

function [y,n] = sigmult(x1,n1,x2,n2)


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;

%This function simply multiply two signals together y ( n )=x 1 ( n ) × x 2 ( n )

a/

In command window, we type:

n = -2:10;

x= [1:7,6:-1:1];

[x11,n11] = sigshift (x,n,5) ;

[x12, n12] = sigshift (x,n,-4);

[x1,n1] = sigadd (2*x11,n11,-3*x12,n12);

subplot (2,1,1);

stem (n1,x1);

title('Problem 2a');

xlabel('n');

ylabel('x1(n)');

The result as below:


Comment: Use the multiply and add function with their corresponding parameters provide
the result as illustrated above.

b/

In command window, we type:

[x21,n21] = sigfold(x,n);

[x21,n21] = sigshift(x21,n21,3);

[x22,n22] = sigshift(x,n,2);

[x22,n22] = sigmult(x,n,x22,n22);

[x2,n2] = sigadd (x21,n21,x22,n22);

subplot(2,1,2);

stem(n2,x2);

title ('Problem 2b');

xlabel('n');

ylabel('x2(n)');

The result as below:


Comment: x ( 3−n ) =x(−( n−3 )) can be achieved by utilizing the sigfold function above

Problem 3

In Command window, we type:

n = [-10 : 1 : 10];

alpha = -0.1 + 0.3j;

x=exp(alpha*n);

subplot (2,2,1);

stem (n,real(x));

title ('real part');

xlabel('n');

subplot (2,2,2);

stem (n,imag(x));

title ('Imaginary part');


xlabel('n');

subplot (2,2,3);

stem (n,abs(x));

title ('Magnitude Plot');

xlabel('n');

subplot (2,2,4);

stem (n,(180/pi)*angle(x));

title('Phase Plot');

xlabel('n');

Comment: The entire plots are listed above.


Problem 4

First we reused the script :

function [y,n] = sigshift (x,m,n0)

n = m + n0;

y=x;

function [y,n] = sigfold(x,n)

y=fliplr(x);

n=-fliplr(n);

function [y,n] = sigadd(x1,n1,x2,n2)

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;

function [y,n] = sigmult(x1,n1,x2,n2)


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;

Comand window:

x = [3,11,7,0,-1,4,2];

nx=[-3:3];

[y,ny]= sigshift(x,nx,2);

w = randn(1,length(y));

nw = ny;

[y,ny]=sigadd (y,ny,w,nw);

[x,nx]=sigfold(x,nx);

[rxy,nrxy]=conv_m(y,ny,x,nx);

subplot(1,1,1), subplot (2,1,1); stem (nrxy,rxy);

axis ( [-5,10,-50,250] );

xlabel('Lag variable 1');

ylabel ('rxy');

title('Crosscorrelation: noise sequence 1');

x = [3,11,7,0,-1,4,2];

nx=[-3:3];
[y,ny]= sigshift(x,nx,2);

w = randn(1,length(y));

nw = ny;

[y,ny]=sigadd (y,ny,w,nw);

[x,nx]=sigfold(x,nx);

[rxy,nrxy]=conv_m(y,ny,x,nx);

subplot(2,1,2);stem (nrxy,rxy);

axis ( [-5,10,-50,250] );

xlabel('Lag variable 1');

ylabel ('rxy');

title('Crosscorrelation: noise sequence 2');

The result as the below:

Comment: y(n) is similar to x(n- 2) and their cross correlation would show the strongest
similarity . To test this out using MATLAB, we compute the cross correlation using two
different noise sequences. It is important to see that both different noise sequences is
created by the same command >> w = randn(1,length(y));

Matlab has a built in function to compute cross correlation as well:


xcorr(x,y)

This function returns the cross-correlation sequence in a length 2*N-1 vector, where x and y
are length N vectors(N>1). If x and y are not the same length, the shorter vector is zero-
padded to the length of the longer vector.

Problem 5:

a/

b = [1];

a = [ 1 ,-1,0.9];

x = impseq (0,-20,120);

n= [ -20:120];

h = filter(b,a,x);

subplot (2,1,1);

stem(n,h);

title('impluse response');

xlabel('n');

ylabel('h(n)');

b/

x= stepseq(0,-20,120);
s = filter(b,a,x);

subplot(2,1,2);

stem(n,s);

title('Step response');

xlabel ('n');

ylabel('s(n)');

Comment: The filter function is implemented as

y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) - a(2)*y(n-1) - ... - a(na+1)*y(n-na)

where n-1 is the filter order, which handles both FIR and IIR filters. na is the feedback filter
order,and nb is the feed forward filter order.

We use the command :

y= filter (b,a,x) to complete the given task where x will be the input as an unit impulse "
impseq ". Or can be a unit step function u(n) " stepseq". The corresponding response is show
above in order.

c/

To determine whether the system is stable or not, we will calculate the sum of h(n) to see if
it converge or not :

sum(abs(h));
ans= 14.8785

The sum is a finite number so the system is stable.

References:

[1]  "Matlab Release Notes ". MathWorks. 2003. Retrieved 7 February 2014.

[2] Andre Quinquis, Digital Signal Processing Using Matlab, 2nd edition, 2007.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy