Professional Documents
Culture Documents
LAB1
Solution:
1)
% Solution of Exercise1
% Given x(n):
x = [1,-2,4,6,-5,8,10];
xn = [-4:2];
% 1) Compute x1(n) = 2 * x(n+3) + x(n) * x(5-n)
% let p2 = x(n)
p2 = x;
pn2 = xn;
% Plotting
stem(xn1,x1);
Command window result:
x1 =
2 -4 8 18 -18 8 26 0 0 0
xn1 =
-7 -6 -5 -4 -3 -2 -1 0 1 2
2) % Solution of Exercise2
% Given x(n):
x = [1,-2,4,6,-5,8,10];
xn = [-4:2];
% 2) Compute x2(n) = x(n+2) * x(n) – x(-n-1)
% let p2 = x(n)
p2 = x;
pn2 = xn;
% Plotting
stem(xn2,x2);
x2 =
xn2 =
-6 -5 -4 -3 -2 -1 0 1 2 3 4 5
LAB2
Solution:
% Solution of Exercise1 LAB2
% Given x(n):
x = [0,0,0,0,1,1,1,1,1,0,0,0,0];
xn = [-6:6];
% Given h(n):
h = [1,1,1,1];
hn = [0:3];
% Compute the convolution sum y(n) = x(n) * h(n)
[y,yn] = conv_m(x,xn,h,hn)
subplot(3,1,1),stem(xn,x); % x(n)
subplot(3,1,2),stem(hn,h); % h(n)
subplot(3,1,3),stem(yn,y); % y(n)
y=
0 0 0 0 1 2 3 4 4 3 2 1 0 0 0 0
yn =
-6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9
LAB3
Using dtft() and idtft(), compute the magnitude and phase spectrum for the following finite
duration signal:
x(n) = [-1,-1,-1,-1,1,1,1,1] for -4 <= n <= 3
Solution:
% Solution of Exercise1 LAB3
% Given x(n):
x = [-1,-1,-1,-1,1,1,1,1];
xn = [-4:3];
% Plotting
subplot(2,1,1),plot(w,abs(X)),xlabel('w'),ylabel('Magnitude Spectrum'),grid on;
subplot(2,1,2),plot(w,angle(X)),xlabel('w'),ylabel('Phase Spectrum'),grid on;
LAB5
Using the dft.m function, compute the DFT of the following signal:
Solution:
% Solution of Exercise1 LAB5
% Given x(n):
N = 8;
x = [0,1,2,3,0,1,2,3];
xn = [0:N-1];
% Compute the spectrum and reorder the negative then positive frequencies
X = dft(x,N);
Xamp = abs([X(N/2+1:N) X(1:N/2+1)]);
% Plotting
subplot(2,1,1),stem(xn,x),xlabel('n'),ylabel('Amplitude'),grid on;
subplot(2,1,2),stem(w,Xamp),xlabel('w'),ylabel('Magnitude'),grid on;
LAB6
Solution:
a) Transforming the difference equation into system equation H(z) we get:
z −1
H (z)=
1−z−1−z −2
b)
b = [0,1];
a = [1,-1,-1];
zplane(b,a);
poles = roots(a)
poles = ROC is |Z| > 1.6180 , since unity circle is not within ROC, the system is
-0.6180 unstable. In other words, the system is unstable since not all poles within the unity circle
1.6180
c)
b = [0,1];
a = [1,-1,-1];
imp_sig = [1 , zeros(1,100)];
n = [0:100];
yn = filter(b,a,imp_sig);
stem(n,yn),xlabel('n'),ylabel('Amplitude'),title('Unit impulse response h(n)');