From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get the Frequency of a real-time plotting Waveform Chart

Solved!
Go to solution

Hi,

 

I want to get the frequency of the chart plotted real-time. The data are coming from an ADXL345 connected to an Arduino UNO. I am using LINX to read the data.

 

I separated the x,y,z data so I can plot them separately and later get their respective frequencies as well.

 

Here's a snippet of my VI as well as the front panel.

 

img.pngimg2.png

 

I used a Write to Measurment File to each axes so I have a copy of the data.

 

Before posting, I tried first the LabView Spectral Tutorial. But that is different to what I want to happen because the frequency in that tutorial is known.

 

I also attached my VI.

 

Thank you! 🙂

0 Kudos
Message 1 of 7
(7,842 Views)
Solution
Accepted by JersonJose
If all you want is to know the spectral content of a time-domain signal, there are multiple examples the show how to do it. I would start by looking at the FFT functions.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 2 of 7
(7,832 Views)

Hi Mike Porter,

 

thank you for taking time. Yes, I've been studying some examples about spectral content.

 

I have another question, since my data are coming real-time, how do I get a specific number of samples to analyze?

 

Let's say I just need 10 samples from the data that is coming. How do I do that? Thanks!

0 Kudos
Message 3 of 7
(7,771 Views)

Here is some (very) basic Signal Theory:  Assume you sample N points at sampling frequency fs.  This means you take one sample every 1/fs seconds (I'm assuming fs is "samples per second").

 

The period of your total sample (that is, the time that you spent collecting all the data) is N/fs.  What is the lowest frequency sine wave that you can analyze?  It would be a sine wave that makes a single cycle during the sampling period, or had a frequency of 1/(N/fs), namely fs/N.  Example: 100 samples at 1000 Hz, the lowest frequency would be 1000/100 = 10 Hz, which makes sense, since you are sampling for 0.1 sec and that's the period of a 10Hz sinusoid.

 

What is the highest frequency you can sample?  Have you heard the term "Nyquist Frequency"?  It is half the sampling frequency, and represents the highest frequency you can represent with your sample.  The Nyquist Frequency is half the sampling Frequency, so our example of 100 samples at 1000 Hz would have 500 Hz as the highest signal we could resolve in our sample.  Your reading should explain the phenomenon of "aliasing" that causes frequencies higher than the Nyquist frequency to "look like" (or "have an alias of") a frequency that is lower than Nyquist.

 

Note that this means that with N points, you can determine N/2 frequencies in your signal.  But, you might wonder, shouldn't I be able to get N "descriptors" of my N-point signal?  Why do I have to settle for N/2 numbers?  Well, each frequency really has 2 values -- the amplitude (height) of the corresponding sine wave, and its phase, the amount it is shifted left or right (a sine wave shifted 90° becomes a cosine wave).  So here are your N points -- one is "the DC term", the mean value of your data.  You then have frequencies fs/N, 2*(fs/N), ... M*(fs/N) where M goes from 1 to (N/2-1).  The final point, corresponding to N/2, is usually called the "Noise" value, and represents what is "left over" when you remove the DC and (N/2 - 1) frequency (gain & phase) components.

 

If you only take 10 data points, you will only be able to express your signal as a sum of DC + 4 frequencies (+ "noise").  Generally, one takes a lot of samples (often a power of 2, like 1024, as it makes calculating the Fourier Transform, used to extract Gain and Phase, particularly Fast -- ever heard of the Fast Fourier Transform, or FFT?).  So returning to our example of 100 samples at 1KHz, we can express this as having a DC term, a gain and phase at 10 Hz, 20 Hz, ... 490 Hz, and some noise.  If we want finer frequency resolution, we need more samples (say 1 second to get 1 Hz resolution).

 

Bob Schor

Message 4 of 7
(7,754 Views)

Hey Bob, I was actually following this instruction from http://www.ni.com/white-paper/4541/en/#toc7

 

img.png

 

My only concern right now is to create the control for n. Because looking at my VI (see previous post), I cannot simply connect a control block to my data because LabView will just give me an error about too many sources.

 

And the 10 samples I pointed out is just an example. It does not mean that it is what I am going to use.

 

Thanks for the response as well though.

0 Kudos
Message 5 of 7
(7,739 Views)
What you just posted was essentially meaningless since you did not show how you attempted to wire for multiple samples.

It seems that one sample is taken each iteration. You are not setting the iteration time (I.e. with a wait/delay) or calculating it (I.e. with a tick count/elapsed time and shift register) You need to do one or the other. You can use the pt-by-pt functions once you have a known rate. Be aware that the sample rate is not going to be very precise. The only way to get something accurate is to use hardware timing of your device's a/d and acquire multiple samples with it.
0 Kudos
Message 6 of 7
(7,725 Views)

Hello, 

 

I have stumbled on the same exact problem. I wish to know if someone has found the solution to the problem. Please any help would be appreciated. 

 

Thank you.

0 Kudos
Message 7 of 7
(5,793 Views)