n = input('Enter number of data points: '); t = (2*pi/n)*(0:(n-1)); x = 1 + cos(t) + 2*sin(2*t); %Create a simple signal z = fft(x); %fft is the fast Fourier transform algorithm %Note that if n is odd z(n) is the complex conjugate of z(2), %z(n-1) is the complex conjugate of z(3), etc. m = (n-1)/2; a = real(2*z(1:m+1)/n); %Recover frequency content of signal. b = -imag(2*z(2:m+1)/n);