Please Provide the Matlab Code for each part. Thanks. I\'ll give points to best
ID: 2080287 • Letter: P
Question
Please Provide the Matlab Code for each part. Thanks. I'll give points to best answer.
Consider an LTI system with a transfer function H(x) = .98 sin (pi/24)z/z^2- 1.96 cos(pi/24) + .9604' Its impulse response is given by h[n]= .98" sin(pi n/24)u[n]. Suppose that this system has the following signal as input: x[n] = n^2(.99) cos (pi n/48) u [n]. Since both h[n] and x[n] decay to zero, we can approximate them as L-point signals (i.e.. keep their first L samples) when L is sufficiently large. For this problem, let us choose L = 512 (so, x[n] and h[n] are truncated and represented by their respective samples for 0 lessthanorequalto n lessthanorequalto 511). Directly compute the convolution of x[n] and h[n] (use 'conv' in MATLAB) and plot the resulting y_dir Implement the convolution of x[n] and h[n] using the following scheme: To compute a 1024-point FFT of h[n], use 'fft(h, 1024)' (same for x[n]). IFFT is called in a similar way (type 'help fft', 'help ifft' in MATLAB for more details). Plot the resulting y_fast[n] on the same graph as y_dir[n]. A careful examination of the complexity of the direct method in (a) reveals that the number of required operations is n_dir = 2L^2. On the other hand, for the implementation in (b), the number of required operations is n_fast = 12L log_2(2L) + 8L + 4. Plot n_dir and (on the same graph) for 1 lessthanorequalto L lessthanorequalto 1000, and comment the resulting graph.Explanation / Answer
clc;
close all;
clear all;
%QUESTION a
figure(1);
n = 0:1:511;
hn = (0.98).^n .* sin(pi*n/24);
subplot(3,1,1);
stem(n,hn);
xn = (n.^2).*(0.99.^n).*cos(pi*n/48);
subplot(3,1,2);
stem(n,xn);
m = 0: 1 : length(xn)+length(hn)-2;
ydirn = conv(xn,hn);
subplot(3,1,3);
stem(m,ydirn);
%QUESTION b
n = 0:1:1023;
figure(2);
hn = (0 < n < 511).*(((0.98).^n) .* sin(pi*n/24)) + (n > 511).*0;
Hfft = fft(hn,1024);
subplot(3,1,1);
stem(n,Hfft);
xn = (0 < n < 511).*(n.^2).*(0.99.^n).*cos(pi*n/48) + (n > 511).*0;
Xfft = fft(xn,1024);
subplot(3,1,2);
stem(n,Xfft);
Yconv = Hfft.*Xfft;
yfastn = ifft(Yconv);
m1 = 0: 1 : length(Yconv)-1;
subplot(3,1,3);
plot(m1,yfastn,'r',m,ydirn,'b');
%QUESTION c
L = 1:1:1000;
figure(3);
ndir = 2*(L.^2);
nfast = 12*L.*log2(2*L) + 8*L + 4;
plot(L,ndir,'r',L,nfast,'b');