07-04-2012 04:25 PM
Hi.
I am trying to convert the digital voltage (read from the analog pin on my arduino mega from an accelerometer) and perform FFT/Spectral analysis to convert it into a Magnitude vs. Frequency output waveform.
I am having some issues accomplishing this, with my output from the Arduino Read Pin Vi as a double 64-real 16 precision data, which I convert to a single waveform. The output from the FFT (RMS) from my spectral measurement via is a 1D cluster of 3 elements. When I wire this to a waveform graph it just changes the Y values (magnitude) but frequency is not updating the X axis at all.
Please help here is a screen shot of my setup so far:
[IMG]http://i.imgur.com/WrzbX.png[/IMG]
I also attached the VI below.
Solved! Go to Solution.
07-05-2012 09:27 AM
*bump*
07-06-2012 02:34 PM
That double 64-real is a single reading of a voltage level. Unfortunately one reading is not enough information to do a meaningful FFT, you will need to build an array of the data and do analysis of that array instead.
You also will want to put a "Wait (ms)" function into your loop so that it isn't polling as fast as possible.
Hopefully this offers enough guidance to get you started!
07-06-2012 02:59 PM
thanks for your guidance
does this make more sense?
07-06-2012 03:11 PM - edited 07-06-2012 03:11 PM
You're closer! Look through this example for some information about auto-indexing:
https://decibel.ni.com/content/docs/DOC-20828
You should be able to wire each voltage output into the right wall of the while loop. If you right click on the tunnel and choose enable auto indexing the output values of each iteration of the loop will be automatically indexed into an array. Thus after the while has finished you will have an array of all the values that the function read during the loop itself.
07-06-2012 04:29 PM
Hi Craig,
Thanks for your continued feedback.
I placed outside the while loop and wired the voltage to auto index. I also chose concatenate inputs to keep it as a 1D array rather than 2D.
Is this the correct approach?
07-06-2012 04:56 PM
You don't need the build array function as the data is already an array (it should work as coded though).
Otherwise does it work? Do you see the results that you want to see? I don't see anything that is jumping out at me.
07-09-2012 04:30 PM - edited 07-09-2012 04:31 PM
Thanks Craig.
I removed those build arrays functions as you suggested.
The FFT seems to be working, but not as I expect it...I think this has to do with the limited bandwidth of 50Hz sampling that the accelerometer itself can handle.
My new question is how can I control the While Loop with say an On/Off type button, which also will clear the values stored in that tunnel so I can use it simultaneously with the rest of my program? What I mean is that I'd like the accelerometer part of my program to have it reusable during the course of the program execution, without affecting the rest of my program which is controlling 8 DC motors. That is to say that while loop should be able to take new readings and data without stopping the rest of my program.
I've attached my VI to this reply.
Thanks a lot!!!
07-10-2012 02:04 PM - edited 07-10-2012 02:05 PM
I've attached a snippet which should do what you want.
I changed the while loop to a for loop which will now run a set number of times (your "window"), and this will determine how many data points that are output in the array.
The old structure is now wrapped in a while loop so that it should iterate through aquisition, analysis and display continuously.
Hopefully this is the functionality you were looking for!
07-10-2012 02:19 PM
Thanks a lot Craig!
Just out of curiousity though, this is only set to run for X number of samples for 1 trial. But let's say I want to run another data set through FFT without stopping the program. Is this possible?
I've tried by using Case Structures, but for some reason it doesnt seem to properly switch as I intend. I've attached my updated VI below.
Thanks!!