-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfefft.m
More file actions
58 lines (43 loc) · 2.06 KB
/
fefft.m
File metadata and controls
58 lines (43 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [yfft,freq]=fefft(y,t)
%--------------------------------------------------------------------------
% Purpose:
% This function subroutine calculates Fast Fourier Transform (FFT)
% using the time domain signal. The time domain data are provided with
% coorseponding time interval.
%
% Synopsis:
% [yf, freq]=fefft(y,t)
%
% Variable Description:
% Input parameters - y : Time domain data n by 1
% t : Time interval for y of n by 1 size
% Output - yf : Absolute value of FFT of the time domain data y
% freq : Frequency axis values
%
% Notes:
% The number of data points for y should be power of 2, and
% truncation is needed to achieve the requirement
%------------------------------------------------------------------------
%------------------------------------------------------------------------
% Compute number of data points and sampling time interval
%------------------------------------------------------------------------
ntime=max(size(t));
dt=(t(1,ntime)-t(1,1))/ntime;
%-----------------------------------------------------------------------
% Extract data points at the power of 2. Truncate extra data points
% so that the final number of data points is in the power of two and
% also as close as possible to the given number of data points
%-----------------------------------------------------------------------
N=fix(log10(ntime)/log10(2))
% Calculate FFT of the time domain data and take absolute values of the result
yfft=fft(y(1:2^N,:));
yfft=abs(yfft(1:2^N/2,:))*dt;
%---------------------------------------------------------------------
% Set up the frequency scale from the given sampling interval.
% Apply the Nyquist criterion to establish the maximum frequency.
%---------------------------------------------------------------------
freq0=0;
freqf= (1/dt)/2; % Maximum or final frequency value
df=freqf/(2^N/2); % Frequency interval
freq=0:df:freqf-df; % Frequency axis values
%----------------------------------------------------------------------