×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

FFT from time domain data

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

RE: FFT from time domain data

Here is one I posted in another thread:

%%%%%
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


peace


 

peace
Fe

RE: FFT from time domain data

(OP)
Thank you FeX32 !!

I will try this code.
Appreciate your help.

- Dipak
 

RE: FFT from time domain data

No problem. Hope it helps.
The important parameters are simply fs (sampling freq. ) and TM (total length of signal , seconds)
The rest is not signal specific.  

peace
Fe

RE: FFT from time domain data

Also there is a scaling factor.  Multiply by 2 to combine positive and negative frequencies.  Divide by N to account for the length of the sample.  Then when the peak magnitude of a sinusoid in is 1, the magnitude of the peak shown on the plot will be 1.  (of course if you want rms, there is another factor sqrt2 to account for).

=====================================
Eng-tips forums: The best place on the web for engineering discussions.

RE: FFT from time domain data

A quick way to check whether you have the y scaling correct is to compute the RMS of both the time signal and the spectrum. They should be identical.

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

Felix? How did you know that's my middle name smile jk.

Anyways, good points about the magnitude/scaling guys.  

peace
Fe

RE: FFT from time domain data

Nit picking time...

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

'e that the DC & nyquist terms don't need the multiplication by 2 (in Matlab anyway)."

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

No worries Greg. I don't mind, just curious. smile

peace
Fe

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources