Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Part A
- %problem 1
- xn=[1 6/7 5/7 4/7 3/7 2/7 1/7 zeros(1,121)]; %declaring xn as an array
- n=0:127; %delclaring n
- xf=fft(xn); %finding DTFT of xn
- xf=fftshift(xf); %shifting xf to be centered at 0
- plot(n.*2*pi/128,abs(xf)); %plotting from -pi to pi
- title("fft calculated magnitude plot"); %setting a title
- %problem 2
- disp('For A2: The DTFT was calculated using the following equation: Sum (from n=-infinity to infinity) of x[n]*e^(-j*omega*n). The result for our given x[n] is: exp(-0i.*o) + (6/7)*exp(-i.*o) + (5/7)*exp(-2i.*o) + (4/7)*exp(-3i.*o) + (3/7)*exp(-4i.*o) + (2/7)*exp(-5i.*o) + (1/7)*exp(-6i.*o)')
- xomega=@(o) exp(-0i.*o) + (6/7)*exp(-i.*o) + (5/7)*exp(-2i.*o) + (4/7)*exp(-3i.*o) + (3/7)*exp(-4i.*o) + (2/7)*exp(-5i.*o) + (1/7)*exp(-6i.*o); %creating the function for the hand calculated DTFT
- figure;
- omega=n.*2*pi/128; %setting an index for plotting
- xf2=xomega(omega); %instantiating the function
- xf2=fftshift(xf2); %shifting xf2 to be centered at 0
- plot(omega,abs(xf2)); %plotting
- title("Manually calculated magnitude plot"); %setting a title
- %this part of the code is creating a graph comparing parts 1 and 2
- figure;
- plot(omega,abs(xf2));
- hold on;
- plot(omega,abs(xf),'-.g');
- hold off;
- title("comparison of manually calculated spectrum and fft spectrum");
- %Problem 3
- Xn=ifft(fftshift(xf)); %preforming the Inverse DTFT
- figure;
- stem(n,Xn); %plotting the result
- title("original signal for part 3 "); %giving it a title
- disp("Part A3: yes, the original signal is the exact same, due to the fact that we are finding the spectrum of the signal, then without any changes, recovereing the signal using the inverse DTFT");
- %% Part B
- un= @(n) 1.0.*(n>=0); %declaring a general step function
- und= @(n) un(n).*(mod(n,1)==0); %declaring a discrete step function
- n=[0:15]; %declaring n for making the function
- xn=sin(2*pi.*n/10).*(und(n)-und(n-10)); %creating the function xn
- omega=linspace(-pi,pi,1001); %doing the DTFT
- W_omega1=exp(-j).^((0:length(xn)-1)'*omega);
- X1=(xn*W_omega1);
- plot(omega, abs(X1)); %plotting the DTFT
- title("magnitude of x[n] FT"); %adding a title
- figure;
- hn=und(n)-und(n-10); %creating the function h[n]
- W_omega2=exp(-j).^((0:length(hn)-1)'*omega); %preforming the DTFT
- X2=(hn*W_omega2);
- plot(omega, abs(X2)); %plotting the DTFT
- title("magnitude of h[n] FT"); %adding a title
- figure;
- yf=X1.*X2; %multiplying the spectrum of xn and hn
- plot(omega,abs(yf)); %plotting the result
- title("magnitude of X[\Omega]H[\Omega]"); %adding a title
- figure;
- yn=conv(xn,hn); %preforming a convolution on the time domain functions of xn and hn
- W_omega3=exp(-j).^((0:length(yn)-1)'*omega); %preforming the DTFT
- X3=(yn*W_omega3);
- plot(omega,abs(X3)); %plotting the result
- title("magnitude of y[n]"); %adding a title
- %creating a graph to compart parts 3 and 5
- figure;
- plot(omega,abs(yf));
- hold on;
- plot(omega, abs(X3), '-.g');
- hold off;
- title("comparison of part 3 and part 5");
- disp("Part B6 answer: convolution in the time domain is the same thing as multiplication in the frequency domain, so the results of the 2 operations should be the same");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement