LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Signal Processing accelerometer ADXL345 using FFT

i am new to Labview and just learning FFT signal processing. I am trying to make data processing in the adxl345 accelerometer. In this project, I use ESP32 devkit v1, adxl345 accelerometer with data rate settings of 400Hz and acceleration of 8g. but when I put the sensor on the vibrating table it has a frequency of 36 Hz and the one that reads on the labview is around 44Hz. is there something wrong with my Labview program?
Im using labview 2015

sasa_one_0-1686992629721.png

 

 

0 Kudos
Message 1 of 18
(2,077 Views)

You have a "loop time" of ~53ms according to the picture (not really a loop time, it's just for the partial code between the two ticks), so you add only about 20 points per second to the ever-growing data array. It is safe to say that this is not a sufficient sampling rate for the frequencies you are interested in and all you get are alias frequencies.

.

As a first step, I would recommend to use a cleaner code architecture. Your local variables are not needed, because the wire is right there! It is also safe to say that stacked sequences are out. Just don't use them. Nobody does anymore.

 

For the FFT, maybe you could use a ptbypt version with a reasonable history length to avoid collecting an ever-growing array.

0 Kudos
Message 2 of 18
(2,032 Views)

Your LabVIEW code shows you are "new to LabVIEW" (use of Stacked Sequence, wrong way to use VISA to read serial data from microprocessor, inconsistent and sometimes "wrong" use of Error Line).  I also wonder what you know about signal processing, and what you really want to acquire and analyze.

 

You are acquiring data from a 3-axis accelerometer over a serial line at 115200 baud, which is about 576 packets of 20 bytes each.  Rather than wait for all the bytes to be present, you read "bytes at port" for every While loop, but only use the data on Loop 1 (discarding any data that comes in on Loop 0, and loops 2..5).

 

I don't see any "control of the microprocessor", i.e. any VISA Writes to tell the microprocessor to start (or stop) sending data.  Are you "streaming" accelerations continously at a fixed 2.5 ms/transmission (which corresponds to a sampling rate of 400 Hz, unless I dropped a decimal someplace)?  What is the lowest frequency of interest for you?  You realize, I hope, that at 400 Hz, the highest frequency the FFT will contain is 200 Hz, right?

 

Are you interested in how the spectrum changes with time?  Time-frequency spectrums are even trickier than a simple FFT.  Among other considerations, you don't want to "waste time processing the data while you are acquiring it", which means you need to take advantage of LabVIEW's ability to do parallel processing, one loop acquiring acceleration data continuously and handing it off in "chunks" (perhaps 400 time-samples each second) to a second loop that does the FFT and saves (or plots) the data.

 

If I can make a suggestion --

  • Write a new program that only acquires 1 second of data.  It should include starting the microprocessor, then simply requesting (I'd use a For Loop for this) 400 VISA Reads of 2000 samples (do you understand why you don't read "bytes at port", but ask for more characters than you expect the microprocessor to send you for the 3 Acceleration values?  Hint -- what is a Termination Character, and why did you turn it on?).
  • Each read should have a string with 3 acceleration values.  Use "Scan from String" to give you three Dbls representing the X, Y, and Z acceleration components, build them into an Array, and bring them to the right edge of the For Loop (where they should form an Indexing tunnel).
  • I don't know how you start and stop the microprocessor, but you should start it before doing the above, and tell it to stop after getting the 400 reads of 3 samples each, when you exit the For loop.
  • So you now have a 2D Array of 400 time point and 3 components of Acceleration.  Figure out how to do an FFT and get three spectrums.  All three should have their maximum excursion at roughly the same frequency.

Do return with this improved, simplified routine.  Put an Indicator on the 2D Array that comes out of the For loop and when you get data that looks "reasonable", showing in the Indicator, go to the "Edit" menu and choose "Save all as Default" to "freeze" these data.  Now, when you attach this "simplified" "frame-sequence-less" version, we will be able to "look at the data" you collected and see if it "makes sense" to us.

 

Bob Schor

0 Kudos
Message 3 of 18
(2,009 Views)

Hi  Sir Alten, thank you for answering my question.

 



@altenbach wrote:

You have a "loop time" of ~53ms according to the picture (not really a loop time, it's just for the partial code between the two ticks), so you add only about 20 points per second to the ever-growing data array. It is safe to say that this is not a sufficient sampling rate for the frequencies you are interested in and all you get are alias frequencies.

.

As a first step, I would recommend to use a cleaner code architecture. Your local variables are not needed, because the wire is right there! It is also safe to say that stacked sequences are out. Just don't use them. Nobody does anymore.

 



For the FFT, maybe you could use a ptbypt version with a reasonable history length to avoid collecting an ever-growing array.


so i must deleted this squence :

sasa_one_0-1687049250612.png

sasa_one_1-1687049274915.png

 

 

and this?

0 Kudos
Message 4 of 18
(1,988 Views)

Hi Sir Bob Schor, Thank you for answering my question

about signal processing, I know a little bit about it and I'm still learning it. 
I just want to make sure of my vibrator table when I run in 36Hz, and FFT makes sure in 36Hz.

"You are acquiring data from a 3-axis accelerometer over a serial line at 115200 baud, which is about 576 packets of 20 bytes each.  Rather than wait for all the bytes to be present, you read "bytes at port" for every While loop, but only use the data on Loop 1 (discarding any data that comes in on Loop 0, and loops 2..5)." 
-> how to doit this ? can you teach me how?

"Are you "streaming" accelerations continuously at a fixed 2.5 ms/transmission (which corresponds to a sampling rate of 400 Hz, unless I dropped a decimal someplace)?" 
-> yes im yes im "streaming" accelerations continuously. 

"What is the lowest frequency of interest for you?  You realize, I hope, that at 400 Hz, the highest frequency the FFT will contain is 200 Hz, right?"
-> lowest interest for the frequency I want is 0Hz. and Yas it will 200Hz because I'll experiment in 0 Hz - 50 Hz so i choose ini 400Hz sample Data Rate in the accelerometer.


"Write a new program that only acquires 1 second of data.  It should include starting the microprocessor, then simply requesting (I'd use a For Loop for this) 400 VISA Reads of 2000 samples (do you understand why you don't read "bytes at port" "
-> how to do it this ? can you teach me sir?

"I don't know how you start and stop the microprocessor, but you should start it before doing the above, and tell it to stop after getting the 400 reads of 3 samples each, when you exit the For loop."
-> you mean, i must code in IDE? can't it be done in labview?




0 Kudos
Message 5 of 18
(1,984 Views)

i tried to make it like this, but it doesn't work either

0 Kudos
Message 6 of 18
(1,953 Views)

@sasa_one wrote:

i tried to make it like this, but it doesn't work either


There are millions of ways something "does not work". You need to be more descriptive and explain exactly what you see and what you like to see instead.

I am sure you have a termination character in the received string, so don't use "bytes at port" at all.

 

As a first step, you need to eliminate ALL local variables. None are needed! All you get are race conditions because there is no guarantee that the locals are only read after their terminal has been written.

 

You seem to be coming from a text programming background and are searching for an equivalent of "variables". In LabVIEW, the wire is the variable. All your data paths can be fully replaced by wires, forcing correct execution order automatically.

 

Here' show a literal rewrite could look like (Green insert. Yes, many things could be further simplified). show the digital display of the chart and you no longer need the axis indicators. less clutter! Only one terminal instead of four!:

 

altenbach_0-1687102094411.png

 

 

 

As I already said, you can use ptbypt FFT versions, no need to accumulate gigantic arrays where you never look at the old data ever again.

 

I recommend to eliminate the instrument and write the code using simulated data, the work out things until the results are as expected. Then substitute data from the serial port at the end.

0 Kudos
Message 7 of 18
(1,940 Views)

Hi sir Alten, thanks for answering my question again. 

is this VI what you mean about termination ? and and how to make a wire like that?

 

sasa_one_0-1687106705329.png

 

0 Kudos
Message 8 of 18
(1,931 Views)

Have a look at Tim's presentation about serial communication. You don't need "bytes at port"! You also probably don't need the wait because the serial data arrive in regular time intervals. Why do you attach code that you did not write?

 

To change a 1D to a 2D array, just initialize the shift register with an empty 2D array. Still, you don't need that at all, because you should.....

 

Use FFT ptbypt instead of collecting infinite amounts of stale data!

0 Kudos
Message 9 of 18
(1,924 Views)

you mean like this ?, i didnt find example FFT ptbypt

sasa_one_0-1687112899976.png

 

0 Kudos
Message 10 of 18
(1,913 Views)