LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to correctly plot FFT

Solved!
Go to solution

Hi,

 

I am tasked with taking the FFT of a 1D array of 2310 points. The dt value between each individual point is .142 seconds. So i believe the sampling frequency is around 7.0422 Hz. I have been trying to format the frequency axis correctly, so that my graph will correctly display at which frequency my peak is at. I have taken the FFT in three different ways, each displayed in the VI attached.

 

The first way, the graph is labeled "Resitance FFT using dt". After taking the FFT of the data, i wire the output to a build waveform vi with the dt value set to .142. The results of this graph display that i have a peak somewhere between 0 and .15 Hz, which is what i am trying to achieve, but i believe this is incorrect because the x-axis has the same scale as the original data(time) and not frequency.

 

The second way, the graph is labeled "using df". The df value is .003048. I believe this method is the correct way to scale my frequency axis, but the results i receive give me a peak at a frequency from 0 to 0.0025hz. To check these results i decided to wire the output of my FFT to a filter with a low cut-off frequency of 0.01 hz and a high cut-off frequency of .5 hz, and then take the inv FFT. The results of this display a sinusoidal wave on the graph labeled "FFT->filter->inv FFT" which is exactly what the whole goal of this program was to achieve. What i cannot seem to wrap my head around is that my FFT plot labeled "using df" which I scaled using df has a peak at a frequency much lower than the  low cut-off frequency of my filter, so after i take the inv FFT of that data, nothing should appear since it should be filtered out. To me this suggests that the way i scaled the first FFT plot labeled "Resistance FFT using dt" is correct. Is there an explanation as to why i am obtaining these results?

 

Finally, the last way i displayed my FFT of the data was by simply wiring the output of the FFT vi to a waveform graph. This graph is labeled "no scaling", and i believe this FFT is incorrect because when you look at the x-axis the final point is at 2310, exactly the number of data points, so the x-axis is not scaled correctly at all.

 

So, what is the correct way to scale my frequency axis? Or does anyone know why i am obtaining these odd results and how to fix it? if i left something out of this post/ you need more info to help solve the probem, please let me know.

 

Any suggestions/corrections are much appreciated. Thanks for your time.  

0 Kudos
Message 1 of 10
(10,764 Views)

Have not looked at your VI but the frequency axis should follow this

 

x axis = Fs*(0 to (L/2))/L

 

where Fs is the sampling frequency and L is the length of your original data vector before the FFT.

 

mcduff

0 Kudos
Message 2 of 10
(10,753 Views)

When you say x-axis, what do you mean? Like that is my scaling factor?

Also what is (0 to (L/2))/L? would that not just be my Fs*(1/2)?

 

Thanks for the response

 

 

0 Kudos
Message 3 of 10
(10,748 Views)

I assume you want to plot Magnitude, Phase, Real, or Imaginary component on the y-axis and frequency on your x-axis for your plot.

 

Your frequency vector is

 

Fs*(0 to (L/2)) / L

 

Assume your sampling frequency is 10 Hz and your have 10 data points your frequencies would be

(0 to L/2) would be

0, 1, 2, 3, 4, 5

then divide these numbers by 10 (L)

0, 0.1, 0.2, 0.3, 0.4, 0.5

Now multiply by the sampling frequency

0, 1, 2, 3, 4, 5

 

Does this make sense?

 

mcduff

0 Kudos
Message 4 of 10
(10,741 Views)

You also need to take only half of your frequency spectrum, as it will be symmetric around the frequency axis, that is positive and negative frequencies.

 

You can obviously adjust my previous advice if you want to see everything.

 

mcduff

0 Kudos
Message 5 of 10
(10,739 Views)

This make sense, but i am still confused. Is there anyway you could make a simple VI that would help explain this a little more?

 

What i am struggling with is how to properly implement what you are saying into a VI.

0 Kudos
Message 6 of 10
(10,727 Views)
Solution
Accepted by loudoe77

Try the following.

snip.png

 

 

 

VI in 2015 version attached.

 

mcduff

Message 7 of 10
(10,705 Views)

Hi mcduff,

 

I attached the new FFT graph labeled "Resstance FFT" using 0.003 as you mentioned.

 

Once again, thanks for all your help. I will kudo, but i just have one more question. So after i take the FFT of the data, i am supposed to use a bandpass filter to filter out the frequencies that are not around 0.1 Hz. When acquiring this resistance data, i was modulating a magnetic field at 0.1 Hz, so that is why i am interested in filtering out all other frequencies other than 0.1 Hz. After filtering the data, i am then to apply the inverse FFT and hopefully see my resistance data forming into a sinusoidal wave. When i apply a low cut-off frequency of 0.01 Hz, and high cut-off frequency of 0.5 Hz, i generate the waveform graph labeled "Filtered INV FFT". This graph gives me the sinusoidal wave i am looking for. But when i look at my FFT graph i see that i really have no strong signals at a frequency between 0.01 Hz and 0.5 Hz. The peaks in my FFT graph are at frequencies around  0 - 0.002 Hz, which in theory should be filtered out by my filter. So i am unsure why i am still able to achieve a graph with a sinusoidal wave. Do you have any clue as to why i am getting these results? Or if i should be using a different VI to filter my data other than the Express VI?

 

I attached 3 photos. 1. Is my Block diagram of the FFT, filter, and inverse FFT. 2. Graphs of FFT and Filtered Inverse FFT. 3. Finally zoomed in graph of FFT to show where peak frequencies are located.

Download All
0 Kudos
Message 8 of 10
(10,588 Views)

I can only offer you some advice and questions

 

  1. The data you submitted has a time column whose values repeated for 0 to about 9 seconds. Is this data really continuous or are they any gaps in it? If there are gaps the analysis is much harder.
  2. If I assume your data is continuous, no gaps, then the time series and FFT Magnitude look like the following

     FFT_10A.png

     I see some small peaks that may be what you are looking for, but maybe not.

     

  3. Depending on how you designed your filter it may be unstable and act like an oscillator/amplifier and actually amplify the noise and the bandpass frequencies, thus looking like you have a signal.

     

     mcduff

     

0 Kudos
Message 9 of 10
(10,573 Views)

The data is read in from another VI. The way the program operates is the magnetic field is modulated at a frequency of 0.1 Hz. The voltage and current readings are read by iterating a for loop so that 70 points are taken at each iteration of the for loop, then the next iteration starts and another 70 points are taken over about 10 seconds. At the end of each iteration, that iteration's 70 points are just appended onto the end of the array. So i believe yes the data is continuous. 

 

I have spoken with some other people and decided i need more accurate data to observe the peak i want, so i will be running more tests in order to obtain that data and re-running my post analysis. I'll check in if i make any progress. I will also check to see if the filter i designed is oscillating or amplifying my signl.

 

Once again, thank you so much mcduff you were a ton of help

0 Kudos
Message 10 of 10
(10,569 Views)