MATLAB: Radix 2 disspation in frequency

OK

Best Answer

Zhao - I think the problem may be due to trying to calculate the even and odd terms in your inner for loop (perhaps to improve computation time). If I remember correctly, the DFT (without a shift) can be simplified to just
X = zeros(N,1);
for k=0:N-1
innerSum = 0;
for n=0:N-1
innerSum = innerSum + x(n+1)*(cos(2*pi*n*k/N) - 1i*sin(2*pi*n*k/N));
end
X(k+1) = innerSum;
end
where X is your sum_all. But note how as we iterate from 0 to N - 1 in the inner for loop, that the factor x(n+1) is used but use n within the cos and sin function calls. That is not the case in your code where we have factors of 2n or 2n-1 but use just n within the cos and sin. I also don't understand why divide the N by two or the other factor for the sum_odd(k) terms of
(cos(2*pi*(k-1)/N)-1j*sin(2*pi*(k-1)/N))
Please clarify why these extra steps are being made.
If you do use the above simplified DFT code, then we will observe the frequency at 300 Hz if we do
f = (0:N-1)*(Fs/N);
subplot(2,1,2);
plot(f,abs(X)/(N/2));
which is still very similar to what you have written.
Related Question