MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
Asked by Balachandra on 14 Nov 2013

When defining a sine wave in matlab, do we choose a domain [1:N]/N or [0:N-1]/N; These two domains differ by a grid point. However, stuff gets complicated when we take FFT. If I define

N = 128; x = [0:N-1]/N; f = sin(2*pi*x); F = fftshift(fft(f)); F(end+1) = 0; F = flipdim(F,2); F = F(1:end-1); f_inv = -real(ifft(ifftshift(F))); norm(f-f_inv,'fro'); plot(f,'b*'); hold on plot(f_inv,'r*');

2) However, if I defined

x = [1:N]/N;

and do the rest same, I get a sine wave in the final which is offset by 2 bins. Why so? and Which is correct?

*No products are associated with this question.*

## 0 Comments