2

I have a simple problem but since I have not used MATLAB Fourier Transform tools I need some help. I have a plot obtained from n excel file. The plot is in time domain. Time range for the plot is 0 to 50 ps. And I have data for the y component of the plot every 0.5 fs. Basically the plot contains 100000 data printed every 0.5fs. Now I want to get the Fourier transform of this plot. What should i do? The following is a simple format for my excel file that includes the data I needed to have the time-domain plot.

0       116.0080214
0.0005  116.051128
0.001   116.0939229
0.0015  116.1362197
0.002   116.1776665
0.0025  116.2178118
0.003   116.256182
.
.
.
.
50.0    123.000

The first column is time in ps. Thank you so much in advance for you helps. Best, HRJ

H.RJ
  • 91
  • 7
  • you can use the fft() function. Also if you have it there is a Digital Signals Processing toolbox that comes with a nice psd function – willpower2727 Jun 23 '15 at 17:57

1 Answers1

5

I have adapted this page for the solution.

    Fs = 100000/50;               % Sampling frequency (in 1/ps)
    T = 1/Fs;                     % Sample time (in ps)
    L = 100000;                   % Length of signal
    t = (0:L-1)*T;                % Time vector; your first column should replace this

    % Sum of a 50 1/ps sinusoid and a 120 1/ps sinusoid
    % Your second column would replace y 
    x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); 
    y = x + 2*randn(size(t));     % Sinusoids plus noise

    NFFT = 2^nextpow2(L);         % Next power of 2 from length of y
    Y = fft(y,NFFT)/L;
    f = Fs/2*linspace(0,1,NFFT/2+1);

    close all
    subplot(2,1,1)
    % Plot your original signal
    plot(Fs*t(1:100),y(1:100))
    title('Signal Corrupted with Noise')
    xlabel('time (fs)')

    % Plot single-sided amplitude spectrum.
    subplot(2,1,2)
    plot(f,2*abs(Y(1:NFFT/2+1))) 
    title('Single-Sided Amplitude Spectrum of y(t)')
    xlabel('Frequency (1/ps)')
    ylabel('|Y(f)|')

Output of the FFT

Delyle
  • 529
  • 3
  • 14
  • I'd visited that page earlier! what are you going to do with the following part? where did you get these sin functions?? Just copy and paste? Sum of a 50 1/ps sinusoid and a 120 1/ps sinusoid % Your second column would replace y x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); y = x + 2*randn(size(t)); % Sinusoids plus noise – H.RJ Jun 23 '15 at 21:44
  • @H.RJ The sin functions are just examples to show how `fft()` works. Instead of using the sines, just define `y` as the second column in the data you attached, and define `t` as the first column in the data you attached. – Delyle Jun 24 '15 at 01:48
  • I do appreciate your paying attention! But how about x? – H.RJ Jun 24 '15 at 05:07
  • Sorry to be annoying, I am a beginner in this area! – H.RJ Jun 24 '15 at 05:07
  • @H.RJ The `x` in this example is a superposition of pure sine waves. The `x` signal is corrupted by noise in the line marked `% Sinusoids plus noise`. The amplitude spectrum should display large peaks in power at the frequencies that make up the pure sine wave `x`, and smaller peaks at other frequencies. This is the case, as you can see in the lower plot. – Delyle Jun 24 '15 at 18:30
  • @H.RJ Just to be clear, in your case you do not need the variable `x`. – Delyle Jun 25 '15 at 01:08
  • Dear Delyle, What does this NFTT MEAN? – H.RJ Jun 28 '15 at 23:57
  • @H.RJ NFFT is the number of points used to form the Fast-Fourier Transform. FFT is faster with signals with length = a power of 2. You don't want to truncate your data to the next _lowest_ power of two (you should use all the data available to you), so you calculate the next power of two _larger_ than the length of your signal. Then FFT just pads y with zeros. Again, this just makes the computation faster. – Delyle Jun 29 '15 at 18:56