FFT from time domain data
FFT from time domain data
(OP)
Hi,
I am getting wrong results and hence trying to figure out if I am computing FFT from time domain data right.
Here is the code for matlab (MATLAB 7.5.0; R2007b).
AllData.dat file contains time in first column and X moment in the 5th column.
load AllData.dat;
Time = AllData(:,1);
Mx = AllData(:,5);
% Define time step and sampling frequency
Ts=Time(2)-Time(1); % Time Step (sec)
fs=1/Ts; %frequency
% X Axis Moment (Mx) FFT Plots
Mx_fft = fft(Mx);
Mx_fft = abs(Mx_fft)/(length(Time)/2);
FHz_fft = [0:(length(Time)-1)]*(1/(Ts*length(Time))); % Cycles per seconds
%
figure;
subplot(1,1,1)
loglog(FHz_fft,Mx_fft,'k',[0.03906 0.159 5.30 1000],[0.003 0.003 0.1 0.1],'r');
grid on;
%Raw moment FFT plot
xlabel('Frequency (Hz)');
ylabel('Moment Mx (N-m)');
title('X Axis Moment Mx FFT');
grid on;
print -djpeg Mx-fft;
I know this is elementary for some of you. Thanks in advance.
Appreciate your help.
- Dipak
I am getting wrong results and hence trying to figure out if I am computing FFT from time domain data right.
Here is the code for matlab (MATLAB 7.5.0; R2007b).
AllData.dat file contains time in first column and X moment in the 5th column.
load AllData.dat;
Time = AllData(:,1);
Mx = AllData(:,5);
% Define time step and sampling frequency
Ts=Time(2)-Time(1); % Time Step (sec)
fs=1/Ts; %frequency
% X Axis Moment (Mx) FFT Plots
Mx_fft = fft(Mx);
Mx_fft = abs(Mx_fft)/(length(Time)/2);
FHz_fft = [0:(length(Time)-1)]*(1/(Ts*length(Time))); % Cycles per seconds
%
figure;
subplot(1,1,1)
loglog(FHz_fft,Mx_fft,'k',[0.03906 0.159 5.30 1000],[0.003 0.003 0.1 0.1],'r');
grid on;
%Raw moment FFT plot
xlabel('Frequency (Hz)');
ylabel('Moment Mx (N-m)');
title('X Axis Moment Mx FFT');
grid on;
print -djpeg Mx-fft;
I know this is elementary for some of you. Thanks in advance.
Appreciate your help.
- Dipak





RE: FFT from time domain data
%%%%%
clear all;
%
fs = 1000; % sampling freq.
T = 1/fs;
TM=3;
t = 0:T:TM;
x = cos(50*t)+2*sin(80*t+pi/3)+3.5*cos(155*t+pi/6)+4*cos(180*t+pi/4); % example signal
%
data=x;
N=length(data);
Fmax=fs;
delta_f=(1/(TM*Fmax))*Fmax;
f = 0:delta_f:Fmax;
F=fft(data);
figure
plot(f(1:N/10),abs(F(1:N/10))),grid
title('FFT'); xlabel('Frequency (Hz)');ylabel('Amplitude')
%%%%%
Change x to your signal.
The thread is here:
http://www.eng-tips.com/viewthread.cfm?qid=245991
Fe
RE: FFT from time domain data
I will try this code.
Appreciate your help.
- Dipak
RE: FFT from time domain data
The important parameters are simply fs (sampling freq. ) and TM (total length of signal , seconds)
The rest is not signal specific.
Fe
RE: FFT from time domain data
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: FFT from time domain data
The amplitude scaling factors in Matlab are derivable from first principles, but they do look a bit like voodoo.
Also you should always use a test signal as Felix has done in order to make sure you have got the frequency scaling right.
Cheers
Greg Locock
SIG:Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.
RE: FFT from time domain data
Anyways, good points about the magnitude/scaling guys.
Fe
RE: FFT from time domain data
Note that the DC & nyquist terms don't need the multiplication by 2 (in Matlab anyway).
I'm with Greg though. Compare time domain and frequency domain calcs before declaring that you're happy. The next issue will probably be peak vs RMS.
- Steve
RE: FFT from time domain data
Yes, that seems to be fundamental due to the folding. Not that I really worry about scaling the Nyquist term. If it isn't zero then it needs to be, for engineering.
(Sorry Fex, I got the impression you were someone I know elsewhere)
Cheers
Greg Locock
SIG:Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.
RE: FFT from time domain data
Fe