Can someone explain these nested loops of DFT in matlab:
N=length(x);
for k=1:N
X(k)=0;
for n=1:N
X(k)=X(k)+x(n).*exp(-1j.*2.*pi.*(n-1).*(k-1)./N);
end
end
Can someone explain these nested loops of DFT in matlab:
N=length(x);
for k=1:N
X(k)=0;
for n=1:N
X(k)=X(k)+x(n).*exp(-1j.*2.*pi.*(n-1).*(k-1)./N);
end
end
The inner loop over n
is a straightforward implementation of the Discrete Fourier Transform equation for a specific frequency bin k
:
adjusted for 1-based indexing (as opposed to the 0-based indexing formula from Wikipedia).
The outer loop over k
simply compute the equation for all N
frequency bins.