Computing the Fourier transfer of a function

I am asked to write a code to compute FT of this signal
x(t) = -1/2 * |x| +1
But, the instructions restrict us with only 7 lines (And with that given format below of the For loop), and here is the intial part of what i wrote, but can't get the idea throughly yet
t=-2:0.01:2;
w=-20:0.001:20;
x=-1/2 * abs(t)+1;
for i=1:
X(i)=
end
plot(w,abs(X));

5 comentarios

Walter Roberson
Walter Roberson el 24 de Mayo de 2022
The only way that I can see within that context is to symbolically compute the transform ahead of time, which is 2*pi*dirac(w) + 1/w^2
t=-20:0.001:20;
w=-20:0.001:20;
x=-1/2 * abs(t)+1;
for i=1:0.01:20
X(i)= 2*(sum(x.*exp(-1*j*w)))*0.001;
end
plot(w,abs(X));
What about this? it gives me an error still, but its the closest i could get
Bjorn Gustavsson
Bjorn Gustavsson el 25 de Mayo de 2022
1: Your indices needs to be integers.
2: Each turn through the loop you might want to only calculate the sum for one element in the w-array, so perhaps use indexing there too.
Ahha, okie the first makes sense, but i didn't the second? Like adding a second for loop within the i loop, and definiing w as a function of -20*pi to 20*pi?
Bjorn Gustavsson
Bjorn Gustavsson el 25 de Mayo de 2022
In the second line of your script you define w as an array of angular frequencies. For each step through the loop you want to calculate the integral of your function with a complex exponential with one frequency, that is one element out of w, not all of them. Also you need to think about how many times you need to run through the loop - for that you should learn to not hard-code the loop like you've done by look at the number of steps you need to make from the number of elements in the relevant array - look at the help and documentation of numel.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Mayo de 2022

Comentada:

el 25 de Mayo de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by