Please complete Part C using MATLAB. Below is the MATLAB code I have for Part A
ID: 3348973 • Letter: P
Question
Please complete Part C using MATLAB. Below is the MATLAB code I have for Part A and B
clc;
close all;
for n = 1:32
x(n) = 0.9*(n-1)*cos(0.1*pi*(n-1));
end
%code for part a)
figure()
subplot(4, 1, 1);
plot(x);
xlabel('time');
ylabel('amplitude');
title('Input signal');
%code for part b)
subplot(4, 1, 2);
plot(real(fft(x,32)));
xlabel('frequency');
ylabel('amplitude');
title('Real part of fft of the signal');
subplot(4, 1, 3);
plot(imag(fft(x,32)));
xlabel('frequency');
ylabel('amplitude');
title('Imaginary part of fft of the signal');
subplot(4, 1, 4);
plot(dct(x,32));
xlabel('frequency');
ylabel('amplitude');
title('DCT of the signal');
% code for part c)
xdft = fft(x, 32);
Explanation / Answer
Hello user,
Please find the whole code attached.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
close all;
for n = 1:32
x(n) = 0.9*(n-1)*cos(0.1*pi*(n-1));
end
%code for part a)
figure()
subplot(4, 1, 1);
plot(x);
xlabel('time');
ylabel('amplitude');
title('Input signal');
%code for part b)
subplot(4, 1, 2);
plot(real(fft(x,32)));
xlabel('frequency');
ylabel('amplitude');
title('Real part of fft of the signal');
subplot(4, 1, 3);
plot(imag(fft(x,32)));
xlabel('frequency');
ylabel('amplitude');
title('Imaginary part of fft of the signal');
subplot(4, 1, 4);
plot(dct(x,32));
xlabel('frequency');
ylabel('amplitude');
title('DCT of the signal');
% code for part c)
N=32;
xdft_base = fft(x, N);
m=1:2:31;
for i=1:16
xdft = fft(x, N);
k=(N+1-m(i))/2:(N-1+m(i))/2;
xdft(k)=0;
xmdft(i,:)=xdft;
ximdft(i,:)=ifft(xmdft(i,:),N);
errordft(i)=norm(ximdft(i,:)-x,2)^2;
end
figure
stem(m,errordft);
title('Error DFT plot');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Please comment if you have any doubt.
Thank you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.