From 0d2811ff213aa88ec2584df458267d9dc1f0faa0 Mon Sep 17 00:00:00 2001 From: Sebastian Held Date: Wed, 14 Jul 2010 10:23:55 +0200 Subject: [PATCH] bugfix DFT_time2freq.m The DFT used to operate on absolute time. This is now fixed. --- matlab/DFT_time2freq.m | 18 +++++++++++++++++- matlab/FFT_time2freq.m | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/matlab/DFT_time2freq.m b/matlab/DFT_time2freq.m index 79baac1..63a7011 100644 --- a/matlab/DFT_time2freq.m +++ b/matlab/DFT_time2freq.m @@ -1,12 +1,28 @@ function f_val = DFT_time2freq( t, val, freq ) -% val = FFT_time2freq( t, val, freq ) +% f_val = DFT_time2freq( t, val, freq ) % % computes the DFT at the given frequencies +% f_val: single-sided spectrum +% +% example: +% t=linspace(0,1,100); +% t_val=0.9*sin(2*pi*3*t); % sine wave; amplitude 0.9; frequency 3 Hz +% f=linspace(1,5,101); +% f_val=DFT_time2freq( t, t_val, f ); +% interp1(f,abs(f_val),3) +% ans = 0.8910 +% plot( t, t_val ) +% plot( f, abs(f_val) ) +% +% See also FFT_time2freq if numel(t) ~= numel(val) error 'numel(t) ~= numel(val)' end +% convert absolute time into relative time +t = t - t(1); + 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 ) ); diff --git a/matlab/FFT_time2freq.m b/matlab/FFT_time2freq.m index d62131a..885d4cb 100644 --- a/matlab/FFT_time2freq.m +++ b/matlab/FFT_time2freq.m @@ -1,4 +1,7 @@ function [f,val] = FFT_time2freq( t, val ) +% [f,val] = FFT_time2freq( t, val ) +% +% See also DFT_time2freq dt=t(2)-t(1); % timestep L=numel(val); % signal length