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)];
- n=0:127;
- xf=fft(xn);
- xf=fftshift(xf);
- plot(n.*2*pi/128,abs(xf));
- title("fft calculated magnitude plot");
- figure;
- plot(n.*2*pi/128,angle(xf));
- title("fft calculated phase plot");
- %problem 2
- %{
- xf2=zeros(1,128);
- omega=linspace(-pi,pi,128);
- temp=1;
- for omega= linspace(-pi,pi,128)
- xf2(temp)=sum(xn.*exp(-1i*omega*n));
- temp=temp+1;
- end
- %}
- 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);
- figure;
- omega=n.*2*pi/128;
- xf2=xomega(omega);
- xf2=fftshift(xf2);
- plot(omega,abs(xf2));
- title("Manually calculated magnitude plot");
- figure;
- plot(omega,angle(xf2));
- title("Manually calculated phase plot");
- %Problem 3
- Xn=ifft(xf);
- figure;
- stem(n,Xn);
- title("original signal without abs function");
- figure;
- stem(n,abs(Xn));
- title("original signal with abs function");
- %% Part B
- un= @(n) 1.0.*(n>=0);
- und= @(n) un(n).*(mod(n,1)==0);
- n=[0:15];
- xn=sin(2*pi.*n/10).*(und(n)-und(n-10));
- omega=linspace(-pi,pi,1001);
- W_omega1=exp(-j).^((0:length(xn)-1)'*omega);
- X1=(xn*W_omega1);
- plot(omega, abs(X1));
- title("magnitude of x[n] FT");
- figure;
- plot(omega, angle(X1));
- title("phase of x[n] FT");
- figure;
- hn=und(n)-und(n-10);
- W_omega2=exp(-j).^((0:length(hn)-1)'*omega);
- X2=(hn*W_omega2);
- plot(omega, abs(X2));
- title("magnitude of h[n] FT");
- figure;
- plot(omega, angle(X2));
- title("phase of h[n] FT");
- figure;
- yf=X1.*X2;
- plot(omega,abs(yf));
- title("magnitude of X[\Omega]H[\Omega]");
- figure;
- plot(omega, angle(yf));
- title("phase of X[\Omega]H[\Omega]");
- yn=conv(xn,hn);
- W_omega3=exp(-j).^((0:length(yn)-1)'*omega);
- X3=(yn*W_omega3);
- figure;
- plot(omega,abs(X3));
- title("magnitude of y[n]");
- figure;
- plot(omega,angle(X3));
- title("phase of y[n]");
- disp("convolution in the time domain is the same thing as multiplication in the frequency domain");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement