openEMS/matlab/FFT_time2freq.m

11 lines
320 B
Matlab
Raw Permalink Normal View History

function [f,val] = FFT_time2freq( t, val )
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;
val = fft( val, NFFT)/L;
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