How to do fft on matlab

The plot we have been using is plotted with the array index along the horizontal axis.  In other words, our data array was one-dimensional and was just an array of the measured data points.

The total time interval for the data record, T, determines the frequency spacing in the FFT plot.
For the ith point on the plot, the frequency for that point is i/T.
Now, with some data we can determine the resonant frequency.

We’re ready to compute the resonant frequency.

We will assume that the total time for the data was 1.024 seconds, and there were 1024 points in the data record, with one millisecond between points.
What is the frequency for an index, i = 16?  Answer is (16/1024)/(.001)  (One millisecond)  SET UP PROBLEM.

So far we haven’t had any problems with this technique.  Here’s a review of the technique and some questions.

Assuming that you have the impulse response, you can get a Bode’ plot that is equivalent to what you would get taking a frequency response, by FFTing the impulse response, and plotting it on log-log scales or db vs log f scales.
We’ve demonstrated the technique for a second order system with complex poles, but it seems clear – although you should check this – that we can do the same for data for other systems, e.g. systems with several real poles, or general combinations of real and complex poles and zeroes.
The one real question is “What if we don’t have the impulse response?”, or in particular, “What if we measure a step response – a widely used test signal – and all we have is a step response measurement?”.

If the input to a system is u(t), with a transform U(s), and the output of the system is y(t), with a transform Y(s), the transfer function is:
G(s) = Y(s)/U(s).
We can evaluate the transfer function by getting a plot of G(jw).  That should work out to be:
G(jw) = Y(jw)/U(jw).
So, we should be able to transform y(t) and u(t) numerically, and divide them and plot the result.
That’s the theory, but it only works if both functions actually have transforms.  A tempting line of reasoning is the following.
If the input to a system is a step, then the transform of the input is 1/s.
We can substitute s = jwin 1/s, and then compute the transfer function as:
G(jw) = jwY(jw).

image of  freqency

When we take the fft of this curve, we would ideally expect to get the following spectrum in the frequency domain (based on fourier theory, we expect to see one peak of amplitude 1 at -4 Hz, and another peak of amplitude 1 at +4 Hz):

picture of freqency spectrum of sine wave

There is also a phase component, but we’ll discuss that in a future tutorial.

If you enter type fftshift.m at MATLAB’s command line, you’ll see the source code for MATLAB’s implementation of the function (use edit fftshift.m if you want to view it in the editor with syntax highlighting). I’m not posting the code here, as it is copyrighted. However, you can try it on your machine and re-implement the same in C. Its up to you to figure out the license terms etc, if you’re into any of that.

the sources:

http://www.phys.ufl.edu

http://stackoverflow.com
http://blinkdagger.com

http://www.facstaff.bucknell.edu

How to do fft in excel

Instructions:

1-Open a blank spreadsheet. Add the following titles to the first cells in columns A, B, C, D, and E of your spreadsheet: Time, Data, FFT Frequency, FFT Magnitude, FFT Complex.

2-Add your data to the “Data” column. At this time, it may be helpful to make a note of the number of data points (samples) in your list, and the sampling rate at which your data was taken. Write and label these two numbers somewhere on your spreadsheet.

3-In the “Time” column, determine the time at which each point was taken. The easiest way to do this is to divide the total time by the number of data points.

4-Perform a Fourier Analysis of your data (Data/Data Analysis/Fourier Analysis) Make sure the input range is your entire data column (B2-B?), and the output range is your FFT Complex column (E2-E?) This is called the FFT Complex column because the Fourier Analysis function outputs a complex number (one involving the imaginary number i).

5-In the first cell of the “FFT Magnitude” column, type the following equation:
=IMABS(E2)
Then drag this equation down so it fills every cell in this column. This will turn the complex number in the “FFT Complex” column into a real number we can use to find the dominant frequencies.

6-Create a graph of the “FFT Magnitude” column (Y-axis) versus the “FFT Frequency” column (X-axis) If all goes well, you should get a graph with peaks where the dominant frequencies are.

picture of truertabmp

Excel Macro Processor is a powerful automation tool for Microsoft Excel 97/2000/XP Excel Macro Processor allows you to apply macros to lot of Excel documents Supports work with macros libraries Excel Macro Processor includes our library MacroBook with useful macros You may add new macros and create new libraries Due to this it is possible to solve practically any tasks of automatic processing of lot of documents.

photo of Excel Macro

Excel Macro Processor is a powerful automation tool for Microsoft Excel 97/2000/XP Excel Macro Processor allows you to apply macros to lot of Excel documents Supports work with macros libraries Excel Macro Processor includes our library MacroBook with useful macros You may add new macros and create new libraries Due to this it is possible to solve practically any tasks of automatic processing of lot of documents.

the sources:

http://en.wikipedia.org
http://business.softlandmark.com

How to do fft

The Cooley Tukey algorithm, named after J.W Cooley and John Tukey, is the most common fast Fourier transform (FFT) algorithm. It re-expresses the discrete Fourier transform (DFT) of an arbitrary composite size N = N1N2 in terms of smaller DFTs of sizes N1 and N2, recursively, in order to reduce the computation time to O(N log N) for highly-composite N (smooth numbers) Because of the algorithm’s importance, specific variants and implementation styles have become known by their own names, as described below.

Because the Cooley-Tukey algorithm breaks the DFT into smaller DFTs, it can be combined arbitrarily with any other algorithm for the DFT. For example, Rader’s or Bluestein’s algorithm can be used to handle large prime factors that cannot be decomposed by Cooley–Tukey, or the prime-factor algorithm can be exploited for greater efficiency in separating out relatively prime factors.

See also the fast Fourier transform for information on other FFT algorithms, specializations for real and/or symmetric data, and accuracy in the face of finite floating-point precision.

Here is how to plot the FFT of a sampled signal using matlab To make this a little more relevant to PLECS and Simulink plotting, that is where I’ll pull the signal from.

1) Lets create the simulink file we want to analyze. I’m going to use the sum of two sine waves and extract them in the fourier series. 1 signal with an amplitude of 1 and the other .5. The first frequency will be 472e3 and the second, 3*472e3.

2) Now let’s cheat to get a better transform To do this let’s set the sim time to be an even number of the fundamental’s period. Set the sim time to 32/f_fund.(Here I had originally called f_fund as fs and didn’t feel like going back to redo this picture For all future screen shots, the fundamental frequency is f_fund).

3) In the simout block to the workspace, let’s sample the signal at 16 times f_fund. And for good general practice, let’s only import half the data. So we only want 16 periods, which are 16 times oversampled, results in limiting the data exported to 16*16 .

image of Using FFT

This demonstration uses the FFT function to analyze the variations in sunspot activity over the last 300 years.

picture of fft shot

Here is how to plot the FFT of a sampled signal using matlab. To make this a little more relevant to PLECS and Simulink plotting, that is where I’ll pull the signal from.

the sources:

http://en.wikipedia.org

http://www.mathworks.com

http://eestuff.blogspot.com