corrected amplitude of FFT_time2freq.m and added a DFT function
parent
7e2bdc67e2
commit
f356ff105c
|
@ -0,0 +1,16 @@
|
||||||
|
function f_val = DFT_time2freq( t, val, freq )
|
||||||
|
% val = FFT_time2freq( t, val, freq )
|
||||||
|
%
|
||||||
|
% computes the DFT at the given frequencies
|
||||||
|
|
||||||
|
if numel(t) ~= numel(val)
|
||||||
|
error 'numel(t) ~= numel(val)'
|
||||||
|
end
|
||||||
|
|
||||||
|
f_val = zeros(1,numel(freq));
|
||||||
|
for f_idx=1:numel(freq)
|
||||||
|
f_val(f_idx) = sum( val .* exp( -1i * 2*pi*freq(f_idx) * t ) );
|
||||||
|
end
|
||||||
|
f_val = f_val / numel(t);
|
||||||
|
|
||||||
|
f_val = f_val * 2; % single-sided spectrum
|
|
@ -1,9 +1,10 @@
|
||||||
function [f,val] = FFT_time2freq( t, val )
|
function [f,val] = FFT_time2freq( t, val )
|
||||||
|
|
||||||
dt=t(2)-t(1);
|
dt=t(2)-t(1); % timestep
|
||||||
val = [val zeros(1,5000)];
|
L=numel(val); % signal length
|
||||||
L=numel(val);
|
NFFT = 2^nextpow2(L); % next power of 2 (makes fft fast)
|
||||||
f = (0:L-1)/L/dt;
|
%very fine freq resolution... NFFT = NFFT+100000;
|
||||||
f = f(1:floor(L/2));
|
val = fft( val, NFFT)/L;
|
||||||
val = 2*fft(val)/L;
|
f = 1/(2*dt) * linspace(0,1,NFFT/2+1);
|
||||||
val = val(1:floor(L/2));
|
|
||||||
|
val = 2*val; % single-sided spectrum
|
||||||
|
|
Loading…
Reference in New Issue