Defining a domain over a period 2Pi and More
Show older comments
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?
Answers (0)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!