I'm trying to get the amplitude- frequency relationship and phase- frenquency relationship using fft. My signal is given by:
t=0:0.005:14; % Time [s] Where mod(length(t),100)~=0% t=t=0:0.005:14; t(end)=; % Where mod(length(t),100)==0Vs=10*cos(2*pi*20*t-pi/5)+13*cos(2*pi*60*t+pi/6);Spectrum=fft(Vs)/length(Vs);Spectrum(2:end-1)=Spectrum(2:end-1)*2;
To get the amplitude and the phase of the signal of specified frequency, I used:
The question is, if the length(Vs) is an integral multiple of 100 (100,2700, etc.), the programe returns a correct amplitude and phase like:
Both Amplitude and Phase value at the DC, 20Hz, 40Hz is the setting value. However, once the length(Vs) is not of an integral multiple of 100, the same program returns a totally wrong result like:
I don't know the reason, and I want a method by which I can get right Spectrum no matter what the length(Vs) is.(On the premise of guaranteeing sampling theorem).