Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an m-file mydftloop.m that takes as input a column vector fk of samples a

ID: 2291654 • Letter: C

Question

Create an m-file mydftloop.m that takes as input a column vector fk of samples and produces as output a column vector Fr of DFT coefficients according to the formula

(Note that the first entry of the vector Fr will correspond to the DFT coefficient F0, while the last entry of the vector Fr will correspond to the DFT coefficient FN0?1.) Your code should automatically determine N0 based on the length of the input vector fk. To compute the DFT coefficients you should use a nested loop. Hand in your m-file and make sure it is clearly documented.

N0-1

Explanation / Answer

clc
clear all
close all
% fk=input('Enter the input samples: ');
fk=[1 2 3 4 4 3 2 1];

fk=fk';
Fr=dftfun(fk);
fprintf('The DFT of fk is: ')
disp(Fr')

function Fr=dftfun(fk)
N0=length(fk);
r=0:N0-1;
k=0:N0-1;
for i=1:length(k)
X1=0;
for j=1:length(r)
X1=X1+fk(j)*exp(-1j*2*pi/N0*k(i)*r(j)); %DFT of x(n)
end
Fr(i)=X1;
end

Output:

The DFT of fk is:
20.0000 + 0.0000i
-5.8284 + 2.4142i
0.0000 + 0.0000i
-0.1716 + 0.4142i
0.0000 + 0.0000i
-0.1716 - 0.4142i
-0.0000 + 0.0000i
-5.8284 - 2.4142i

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote