Create an m-file myidftloop.m that takes as input a column vector Fr of DFT co- efficients and produces as output the corresponding column vector fk of samples, according to the formula
1 N0−1 2πrk
fk= ?FrejN0 , k=0,1,...,N0−1.
Again, your code should automatically determine N0 based on the length of the input vector Fr. To compute the inverse DFT, you should use a nested loop. Hand in your m-file and make sure it is clearly documented.
Validate your m-file by running the following code (include a copy of the output at the command line):
T = 0.1e-3; N0 = 128; T0 = N0*T; ft = inline(’cos(2*pi*1100*t)’); fk = T*ft([0:1:N0-1]’*T);
Fr = mydftloop(fk); fkrecon = myidftloop(Fr); maxError = max(abs(fk-fkrecon))
% this should be very small
function Fr = mydftloop(fk);
N=length(fk)
for k=0:1:N-1
sum=0
for n=0:1:N-1
sum=sum+(fk(n+1)*exp(-j*2*pi*(k)*n/N));
Fr(k+1)=sum;
end
end
end
________________________________________________________
function fkr = myidftloop(Fr);
N=length(Fr)
for n=0:1:N-1
sum=0
for k=0:1:N-1
sum=sum+(Fr(k+1)*exp(j*2*pi*k*n/N));
fkr(n+1)=sum;
end
end
fkr=fkr/N
end
_________________________________________________________
Command window:
maxError = 3.8135e-18
Hint:
The last line of the calling script should be
maxError = max(abs(fk'-fkrecon))
Get Answers For Free
Most questions answered within 1 hours.