LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly generate a sin wave and take it fourier transform?

I am trying to take a digitized sine wave and then plot the magnitude and the phase of its FFT spectrum separately. However, the phase plot I am getting does not seem to be correct. I have attached my VI for reference. 

0 Kudos
Message 1 of 15
(982 Views)

Your Vi is one version newer than I have so I can't open it.

 

Anyway, what results you are expecting doing a frequency (FFT) analysis on a sine wave? 

 

A sine wave only contains the fundamental frequency. Try a more complex waveform.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 15
(940 Views)

When attaching a VI, make sure that all controls have typical default values. Currently, your frequency, sampling rate, and # of samples are all zero. Please tell us what input values you are suing and what you expect as result.

 

You are using an FFT function that expects a waveform, but you give it a naked 1D array, i.e. no timing information at all. The FFT thus assumes a dx of 1. (did you notice the red coercion dot?)

 

Also make sure to place a small wait inside your loop (e.g. 100ms) because it seems pointless to repeat the same calculation millions of times per second, burning 100% of a CPU core.

0 Kudos
Message 3 of 15
(927 Views)

Thank you for the suggestions. I am using the following values: 
No. of Samples: 100
Signal Frequency: 100
Sampling Rate: 1000

0 Kudos
Message 4 of 15
(922 Views)

ZainAli02_0-1711035001032.png

What I dont understand is the phase plot. Isnt it suppose to be at pi/2? Here is my block diagram: 

ZainAli02_1-1711035067328.png

 

0 Kudos
Message 5 of 15
(921 Views)

Wild guess: try increasing the resolution of your input signal.

Here the sine does not seem very smooth:

 

raphschru_0-1711035524347.png

 

Regards,

Raphaël.

0 Kudos
Message 6 of 15
(915 Views)

There are two main issues:

 

  • Your FFT by default applies a windowing function, so eliminate that. It is designed for real signals!
  • You should make sure that your signal has an integer number of cycles to avoid spectral leakage

See if this can give you some ideas:

 

altenbach_0-1711036520706.png

 

0 Kudos
Message 7 of 15
(894 Views)

I have been asked to used the sin function and not the sine waveform generation sub vi

0 Kudos
Message 8 of 15
(859 Views)

You can built your array into a waveform by just defining dt, right?

0 Kudos
Message 9 of 15
(849 Views)

yes, that should result in an array

0 Kudos
Message 10 of 15
(843 Views)