Compose code performing FFT

Aditya Hegde_22173
Aditya Hegde_22173 Altair Community Member
edited February 20 in Community Q&A

1)I have been trying to perform FFT using time domain data. The time domain data that I have is in excel format and with data points up to 100000. Can somebody tell me what is wrong with my code as the FFT I am obtaining here doesn't match with the one which i have performed in other softwares. (code attached below) 

Code:

data= xlsread('pave_25_time_data.xlsx'); 
Time=data(:,1); 
Acc=data(:,2); 

figure(1); 
plot(Time,Acc);  

L= numel(Time); 
Y = fft (Acc); 
P2 = abs (Y/L); 
P1 = P2(1:L/2+1); 
P1(1:end-1) = 2*P1(1:end-1); 
f = (0:(L/2))/2; 
figure(2); 

plot(f,P1); 

 

 

 

Answers

  • João Marabisa
    João Marabisa
    Altair Employee
    edited February 19

    Hello @Aditya Hegde,

    This could be due to the headers. The easiest way to do it is using:

    image

    I compared the results with Octave and they match:

    image

    Attaching the files that I used.

  • Orestis_YB
    Orestis_YB
    Altair Employee
    edited February 20

    Hello Aditya,

    when creating an fft it's important to take into account sample frequency. As you already have the time data from the xlsx file you can set the sampling frequency as Fs = 1/(mean(diff(Time)); A very useful function when plotting the fft is also freq(). Here you can use it as f = freq( L, Fs, 'onesided') with L being the length of the signal, Fs the sampling frequency and 'onesided' the option to obtain the single side fft frequencies. You can also check this brief how to video Altair Compose: Signal Processing - Fast Fourier Transform . Hope this helps!


    Best regards,
    Orestes.