FFT implementation by myselft
Mostrar comentarios más antiguos
Hello. Im studying discrete fourier transform and for that I want to implement it. I mean, this is the code I made but there is a problem
I defined a little discrete signal, x. And I calculate the DFT and then the inverse DFT but I dont get the same signal.
What Im doing wrong?
Thanks in advance.
x=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 -0.1 -0.2 -0.3 -0.4 -0.5 -0.6 -0.7 -0.8 -0.9 -1 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1]
sum=0
for k=1:40
for j=1:40
sum= sum+x(j)*exp(- 1i * 2 * pi * (1/20)*(j-1)*(k-1))
end
a(k)=sum
sum=0
end
n=1:1:40
sum=0
for k=1:40
for j=1:40
sum= sum+a(j)*exp( 1i * 2 * pi * (1/20)*(j)*(k))
end
b(k)=(1/40)*sum
sum=0
end
subplot(1,2,1)
plot(n, x)
subplot(1,2,2)
plot(n,b)
Respuesta aceptada
Más respuestas (3)
James Tursa
el 2 de Abr. de 2018
Editada: James Tursa
el 2 de Abr. de 2018
Use 1/40 instead of 1/20, and modify your inverse formula to account for the -1 difference between the MATLAB indexing (1-based) and the indexing used by the inverse formula (0-based). E.g.,
for j=1:40
sum= sum+x(j)*exp(- 1i * 2 * pi * (1/40)*(j-1)*(k-1))
end
and
for j=1:40
sum= sum+a(j)*exp( 1i * 2 * pi * (1/40)*(j-1)*(k-1))
end
It would be better to use a variable name other than "sum", since that is the name of an intrinsic MATLAB function. Also, it would be better to generalize your code using variables for indexing limits instead of hard-coded numbers (e.g., N instead of 40).
2 comentarios
Julian Oviedo
el 2 de Abr. de 2018
Erkan
el 9 de Feb. de 2024
Hi James, how can we calculate the w(2*pi*f) in the jw term in the Fourier integral formula from this
(- 1i * 2 * pi * (1/40)*(j-1)*(k-1)) expression? So how can we find frequency values?
Julian Oviedo
el 11 de Mayo de 2018
1 comentario
Jan
el 12 de Mayo de 2018
Please ask one question per thread only. Injecting a new question in the section for answers is rather confusing and it is not longer clear, to which question the answers belong.
If James' answer solves your problem, please accept it. Open a new thread for further questions. Thanks.
Julian Oviedo
el 11 de Mayo de 2018
Categorías
Más información sobre Discrete Fourier and Cosine Transforms en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
