2010-03-31 13:38:37 +00:00
|
|
|
function [f,val] = FFT_time2freq( t, val )
|
2010-07-14 08:23:55 +00:00
|
|
|
% [f,val] = FFT_time2freq( t, val )
|
|
|
|
%
|
2015-12-13 15:27:10 +00:00
|
|
|
% Note: This function can only be used for pulse signals
|
|
|
|
%
|
2010-07-14 08:23:55 +00:00
|
|
|
% See also DFT_time2freq
|
2010-03-31 13:38:37 +00:00
|
|
|
|
2010-04-21 15:58:02 +00:00
|
|
|
dt=t(2)-t(1); % timestep
|
|
|
|
L=numel(val); % signal length
|
|
|
|
NFFT = 2^nextpow2(L); % next power of 2 (makes fft fast)
|
|
|
|
%very fine freq resolution... NFFT = NFFT+100000;
|
2011-01-31 09:57:20 +00:00
|
|
|
val = fft( val, NFFT)*dt;
|
2010-04-21 15:58:02 +00:00
|
|
|
f = 1/(2*dt) * linspace(0,1,NFFT/2+1);
|
|
|
|
|
2010-04-28 10:12:54 +00:00
|
|
|
val = 2*val(1:NFFT/2+1); % single-sided spectrum
|
2011-06-08 09:23:55 +00:00
|
|
|
|
|
|
|
%correct phase for time-shifted signals
|
|
|
|
val = val .* exp(-1j*2*pi*f * t(1));
|