How do I extract phase from an FFT?
70 ビュー (過去 30 日間)
古いコメントを表示
I am new to both Matlab and fft analyses and I was wondering two things. 1) whether the code is written without errors. It appears to work properly but I wonder if I have included the right steps in the fft processing and 2) how do I extract the phase information? I can not seem to get the phase information using the angle() function, as it results in a very noisy phase signal. Alternatively using an atan() function did not succeed as well.
Thanks!
I have written the following code:
time=linspace(0,8760,8760);
% A is an input signal from an external model
A_noDC=A-mean(A); %This cuts the 0 Hz DC component
f=1/3600; %frequency is 1 sample per hour, thus 1/3600 per second
N=length(A);
X=fft(A_noDC);
X_mag=abs(X);
X_amp=X_mag/N; %normalises magnitude into amplitude
X_ampsingle=X_amp(1:N/2+1); %divides the plot from two-sided to one
X_ampsingle(2:end-1)=2*X_ampsingle(2:end-1); %idem
freq=(0:(N/2))*f/N; %plots the frequency on the x-axis rather than bins
figure('visible','on')
plot(freq,X_ampsingle);
title('Frequency spectrum')
xlabel({'Frequency','[Hertz]'});
ylabel({'Amplitude [MW]'});
figure('visible','on');
plot(time,A); %plots original signal
title('original signal');
end
Update: Thanks for the comments! I will look into that. Nevertheless, the following code appears to show logical results as well, where the threshold is merely used to cut low-amplitude (<X/10) sinusoids from the phase plot. Does this seem right?
X2=X
threshold=max(abs(X)/10);
X2(abs(X)<threshold)=0; % determines the low-amplitude threshold
phase=atan2(imag(X2),real(X2))*180/pi;
phase_single=phase(1:N/2+1); %turns the plot into a one-sided plot
phase_single(2:end-1)=2*phase_single(2:end-1);
figure('visible','on')
plot(freq,phase_single);
title('Phase information')
xlabel({'frequency','[Hertz]'});
ylabel({'phase [degrees]'});
2 件のコメント
回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Spectral Measurements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!