MATLAB: How to calculate Amplitude and phase out of FFT transform of the signal

amplitudefft

Hi All ! How are you people ? I have a question in matlab: I tried to write a code that finds an Amplitude and Phase_shift of the Periodic signal(cosine wave) BUT it doesn't give the correct answer(instead of Amplitude=10,i am getting answer Amplitude=5)!!! Could someone to see the code and to tell me what i'am doing the wrong way ?
%THE CODE function ask_portal_fft per=24;%number of periods w=2*pi*per;% points=1000; t=linspace(0,1,points); a=10;%the amplitude so the answer of Amplitude suppose to be 10 y=a*cos(w*t-1);%Phase shift suppose to be 1 %plot(y)%for debug %————-
Y=fft(y); N=length(Y); Psd=Y.*conj(Y); mx=find(Psd==max(Psd),1); Amplitude=sqrt(Psd(mx)); Amplitude=Amplitude/N;%=4.99,why not 10 ?
Phase=angle(Y(mx));%suppose to be 1 end

Best Answer

This reminds me of the same issure here:
Basically your maximum amplitude should be at 24Hz, right? Here is the Fourier transform of your signal at 24Hz.
>> ff = 24;
>> G_ff = quad(@(t)10*cos(2*pi*ff*t-1).*exp(-1i*2*pi*ff*t),0,1)
G_ff =
2.7015 - 4.2074i
>> sqrt(G_ff*conj(G_ff))
ans =
5
It's 5 !!!