LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with FFT data processing

Solved!
Go to solution

@layman93 wrote:

Hello all and McDuff

 

Thank you for your help with which I was able to figure out the technical aspects of my system.

 

I also followed you explanation in this thread

 

Please see attached VI

 

My sampling rate is 338 hz and the frequency of m,y interest range from 35 hz to 60 hz, thus satisfying the Nyquist law.

 

I am trying to sample 10000 data points at a time. with my df being 0.0338 Hz for my acquisition time of 29 secs.

 

But when i try to plot my data the frequency axis is not proper as shown-in capture png.

 

I believe the peak is correct but I am not able to set the frequency resolution properly.

 

I have also attached my Matlab plot which gives out correct peak.

 
 

Can you please help.

 

layman93


In Matlab you are processing the whole array, in LabVIEW you are processing it point-by-point?

 

From your VI, it appears you are downloading a single point at a time, is this true or are you downloading the data after you have collected 29 seconds worth of data? From your current response, it seems like the latter.

 

The Matlab plot looks like a power or amplitude spectrum. The plain FFT will give a complex result, you would need to feed this into a magnitude function. From your VI it also looks like you are getting the power spectrum, proportional to the square of the amplitude. Your Matlab plot may be that.

 

If you are not collecting point by point you are using the wrong VIs. If you are collecting point by point, at a 338 Hz sampling rate, then 100 points (your length) will give you a 3.38 Hz bin size, which would make your 35 Hz signal show up in the 10th bin with some leakage. Your front panel for the power spectrum shows about the 14th bin max, are you sure your frequency is correct?

 

mcduff

0 Kudos
Message 11 of 29
(1,262 Views)

Hello Mcduff,

 

I am downloading data point by point and plotting real time. Yes I am sure the target frequency is around 35 hz since the motor rotates at 2100 rpm.

 

If you are not collecting point by point you are using the wrong VIs. If you are collecting point by point, at a 338 Hz sampling rate, then 100 points (your length) will give you a 3.38 Hz bin size, which would make your 35 Hz signal show up in the 10th bin with some leakage. Your front panel for the power spectrum shows about the 14th bin max, are you sure your frequency is correct?


Yes this makes more sense now actually, I never understood the concept of frequency bin properly, thank you for explaining.

 

Is there something wrong with the ptbypt VI's that i am using or the graph inputs?

 

The aim of the work is to show the data in real time actually without the need of post processing so in that case I am not really looking for pin point accuracy but approximate values.

 

 I attached Matlab code to show the actual frequency peak which I am not able to see in Lab view,

 

Is there any way to work around this?

layman93

 

 

0 Kudos
Message 12 of 29
(1,257 Views)

Attached is a simulation that you can play with, 2015 Version. It is quick and dirty and probably can be improved.

 

Snip.png

 

mcduff

 

 

Message 13 of 29
(1,248 Views)

Thank you, let me try with this.

 

layman93

0 Kudos
Message 14 of 29
(1,242 Views)
Solution
Accepted by topic author layman93

@layman93 wrote:

Thank you, let me try with this.

 

layman93


Clear the charts before starting and put a 100ms wait in the loop, you can see the fft accumulate.

 

mcduff

Message 15 of 29
(1,237 Views)
Solution
Accepted by topic author layman93

Hi Layman,

You are almost near to your FFT plot which you want to achieve.

Only thing is you need to set the scale of your waveform graph as shown below:

srikrishnaNF_0-1594183416835.png

where 0.03554 is scaling factor which is 1/max(t) i.e. 1/(28.13) and maximum value is the value as

total number of samples*0.03554+1. 

Based on your data in CSV file,i got the plot as this:

srikrishnaNF_1-1594183624168.png

 

Regards,
Srikrishna


Message 16 of 29
(1,193 Views)

Hello McDuff,

 

It works now perfectly.  Thank you so much for this.  Although I do have the last question. The Arduino board sampling rate is not always same it varies highly depending on the frequency I guess. Is there any way to work around it or should I just keep an average sample size for the program and just leave it like that.

0 Kudos
Message 17 of 29
(1,173 Views)

Hello Sri,

 

Thanks for the help, yeah I can also work with this. 

 

This has really made it simple :).

 

 

0 Kudos
Message 18 of 29
(1,170 Views)

@layman93 wrote:

Hello McDuff,

 

It works now perfectly.  Thank you so much for this.  Although I do have the last question. The Arduino board sampling rate is not always same it varies highly depending on the frequency I guess. Is there any way to work around it or should I just keep an average sample size for the program and just leave it like that.


I believe there are routines that can handle a non-constant sampling rate for a point-by-point analysis. Not sure if they are included with base LabVIEW, there may be a toolkit.

 

You have options:

  1. Accept the uncertainties in your real time measurement.
  2. If you keep track of the time difference, you may be able to do a point-by-point interpolation to have equally spaced points. However, if you rate speeds up then, your interpolation will go into uncharted territory.

You are communicating to Arduino by serial port; this will be imprecise. Your computer has to send the command, Arduino process, then Arduino send response. All of these steps are not deterministic. You can experiment with sampling frequencies to see where things go awry and then try to avoid those regions.

 

mcduff

0 Kudos
Message 19 of 29
(1,163 Views)

Yes, Even I thought so too that the sampling rate will be imprecise due to serial communication.

 

Yeah, I will try to put an interpolating tool or something to fix it.

 

Thank you so much for your help.

 

-layman93

0 Kudos
Message 20 of 29
(1,157 Views)