File: FFT_time2freq.m

package info (click to toggle)
openems 0.0.35+dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,288 kB
  • sloc: cpp: 40,259; yacc: 580; lex: 350; makefile: 258; sh: 169; ruby: 19
file content (18 lines) | stat: -rw-r--r-- 521 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function [f,val] = FFT_time2freq( t, val )
% [f,val] = FFT_time2freq( t, val )
%
% Note: This function can only be used for pulse signals
%
% See also DFT_time2freq

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)*dt;
f = 1/(2*dt) * linspace(0,1,NFFT/2+1);

val = 2*val(1:NFFT/2+1); % single-sided spectrum

%correct phase for time-shifted signals
val = val .* exp(-1j*2*pi*f * t(1));