Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Defining a domain over a period 2Pi and More

Asked by Balachandra on 14 Nov 2013
Latest activity Edited 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?

0 Comments

Balachandra

Products

No products are associated with this question.

0 Answers

Contact us