Question

Create an m-file myidftloop.m that takes as input a column vector Fr of DFT co- efficients...

  1. 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.

  2. 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

Homework Answers

Answer #1

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))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function M-file my_euler.m which take 5 input values, f, t_0, y_0, dt, and t_f...
Write a function M-file my_euler.m which take 5 input values, f, t_0, y_0, dt, and t_f that specify the function to be approximated, the initial t-value, the initial condition y(t0)=y0, the step-size Δt, and the final t-value at which you want to approximate the solution y(t). Your function should: Use the input anonymous function f to calculate f(t,y). Plot the approximate solution with green "+" symbols at the points and a red line joining them up. Have a function output...
Create an m-file function called exam2 yourname fun. The function takes as input two values a...
Create an m-file function called exam2 yourname fun. The function takes as input two values a and b. If a is bigger than b the function returns the product of a and b. If a equals b, the function returns the sum of a and b. And if b is bigger than a, the output should be zero, and a message should be displayed that reads: Value of b = "value of b" bigger than a="value of a" EXAMPLE: If...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code which will read in strings from nemo.txt, then call Lab08(string) on each line of nemo.txt. Your job is to write Lab08.m. The Lab08 function will take in a string as input and will return an integer n as output. The value of n will be the nth word in the input string, where n is the location of the substring 'Nemo'. Please note that...