www.gusucode.com > signal 案例源码程序 matlab代码 > signal/FFTPhaseExample.m

    %% FFT Phase
% Generate a signal that consists of two sinusoids of frequencies 15 Hz and
% 40 Hz. The signal is sampled at 100 Hz for one second.

%%

fs = 100;
t = 0:1/fs:1-1/fs;
x = sin(2*pi*15*t) + sin(2*pi*40*t);

%%
% Compute the discrete Fourier transform of the signal. Find the phase of
% the transform and plot it as a function of frequency.

y = fft(x);
phs = unwrap(angle(y));
ly = length(y);
f = (0:ly-1)/ly*fs;

plot(f,phs/pi)
xlabel 'Frequency (Hz)'
ylabel 'Phase / \pi'
grid