Hello,
I have two signals: both of them are logarithmic chirp but with different amplitude and normally a different phase according to the frequency. Frequency range: from 0 to 150 Hz, Sampling Rate 2000 Hz.
From those curves I would like to extract the frequency (to be sure that I have a logarithmic chirp and control the starting and ending frequency) the Amplitude and the Phase.
Here is the little code I wrote for it following the matlab help
function [f0,m,p] = myfft(x,fs)l = length(x); % Window length
n = pow2(nextpow2(l)); % Transform length
y = fft(x,n); % DFT
f = (0:n-1)*(fs/n); % Frequency range
power = y.*conj(y)/n; % Power of the DFT
figure(1)plot(f,power)xlabel('Frequency (Hz)')ylabel('Power')title('{\bf Periodogram}')y0 = fftshift(y); % Rearrange y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = y0.*conj(y0)/n; % 0-centered power
m= 2*abs(y0)/l;figure(2)plot(f0,m)xlabel('Frequency (Hz)')ylabel('Magnitude (m)')title('{\bf 0-Centered Periodogram}')phase = unwrap(angle(y0));p = phase*180/pi;figure(3)plot(f0,p)xlabel('Frequency (Hz)')ylabel('Phase (Degrees)')grid onend
I tried also to use the spectrogram function
function [f,m,a,FreqMax] = myspectrogram(Wave,SamplingRate) [s,f,t,p] = spectrogram(Wave,4096,4050,9192,SamplingRate,'yaxis'); snorm = (2 * abs(s')) /sum(hamming(4096)); [m,nd] = max(snorm); m = 2*m; p0 = unwrap(angle(s')); a = p0(nd);end
And to use the hilbert transformation.
My results are: I am able to extract the Frequency (from 0 to 1000 Hz as my sampling rate is 2000 Hz) but I have trouble to only get the frequency range of interest. I am able to measure the amplitude for the signal quite easily
BUT I don't get anything for the Phase. All three methods give me different results.
Could you tell me what is wrong ? And how can I extract the phase properly of my signal ?
Thank you !
Michael
Best Answer