Tutorial 1 Report: Digital Signal Processing Lab
Tutorial 1 Report: Digital Signal Processing Lab
TUTORIAL 1 REPORT
Problem 1:
a/
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);
xlabel('n');
ylabel('x[n]');
b/
n = [n1:n2];
n = [0:20];
x1=n.*(stepseq(0,0,20)- stepseq(10,0,20) );
x = x1 + x2;
plot (n,x);
stem (n,x);
xlabel('n');
ylabel('x[n]');
Comment: Similar to the previous problem we just plug in the parameter and stem-plot the
result with the given range of n.
c/
n = [0:50];
plot (n,x);
stem (n,x);
xlabel('n');
ylabel('x[n]');
d/
n = [-10:9];
x= [5, 4, 3, 2, 1];
xtilde = (xtilde(:))';
plot (n,xtilde);
stem (n,xtilde);
xlabel('n');
ylabel('x[n]');
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:
n = m + n0;
y=x;
%This function shift the signal by some given sample y ( n )=x (n−k )
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)
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;
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;
a/
n = -2:10;
x= [1:7,6:-1:1];
subplot (2,1,1);
stem (n1,x1);
title('Problem 2a');
xlabel('n');
ylabel('x1(n)');
b/
[x21,n21] = sigfold(x,n);
[x21,n21] = sigshift(x21,n21,3);
[x22,n22] = sigshift(x,n,2);
[x22,n22] = sigmult(x,n,x22,n22);
subplot(2,1,2);
stem(n2,x2);
xlabel('n');
ylabel('x2(n)');
Problem 3
n = [-10 : 1 : 10];
x=exp(alpha*n);
subplot (2,2,1);
stem (n,real(x));
xlabel('n');
subplot (2,2,2);
stem (n,imag(x));
subplot (2,2,3);
stem (n,abs(x));
xlabel('n');
subplot (2,2,4);
stem (n,(180/pi)*angle(x));
title('Phase Plot');
xlabel('n');
n = m + n0;
y=x;
y=fliplr(x);
n=-fliplr(n);
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;
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);
axis ( [-5,10,-50,250] );
ylabel ('rxy');
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] );
ylabel ('rxy');
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));
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)');
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.
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
References:
[2] Andre Quinquis, Digital Signal Processing Using Matlab, 2nd edition, 2007.