Extract Frequency, Amplitude and Phase of Logarithmic chirp
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Michael Lherbette
am 11 Aug. 2015
Bearbeitet: Brian Neiswander
am 14 Aug. 2015
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 on
end
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
0 Kommentare
Akzeptierte Antwort
Brian Neiswander
am 14 Aug. 2015
Bearbeitet: Brian Neiswander
am 14 Aug. 2015
You can get instantaneous amplitude envelope, phase, and frequency information from a signal using the Hilbert transform. In MATLAB, the "hilbert" function returns the discrete-time analytic signal "X" for some real-valued signal "Xr":
X = hilbert(Xr);
The instantaneous amplitude envelope is the magnitude of the analytic signal:
mag = abs(X);
The instantaneous phase information can be found using the "angle" and "unwrap" functions:
phi = unwrap(angle(X));
Finally, the instantaneous frequency can be found from the derivative of the instantaneous phase:
freq = 1/(2*pi) * diff(phi) * Fs;
For a detailed example, see the page below:
You can find more information about the MATLAB functions "hilbert", "angle", and "unwrap" below:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!