LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to sum the las n bits of a signal?

Hi, somebody know hay I can take the last 'n' values from the analog read block a sum to average it? In real time I need take 16 values, sum it, and repeat. I should have a slowly variations in the read. Thanks!

0 Kudos
Message 1 of 13
(7,046 Views)

Hey Gabrielo91,

It sounds like the Mean PtByPt Vi is what you're looking for:

http://zone.ni.com/reference/en-XX/help/371361H-01/ptbypt/mean_ptbypt/

Let us know if that works for you.

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 2 of 13
(5,128 Views)

Hi, that isn't enough. I really need take 64 samples, sum it and divide by 8. I need somewhat like a a buffer o a queue. But I can't implement it. That each 64 samples.

0 Kudos
Message 3 of 13
(5,128 Views)

Do you want to do a running average or sum 64 samples, divide by 8, then start over?

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 4 of 13
(5,128 Views)

If you want to reset after every 64 samples you can do something like this (VI attached):

0.PNG

Other case structure frame:

1.PNG

Let us know if that is what you were looking for.

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

Message 5 of 13
(5,128 Views)

Yes, I need reset it every 64 samples and start again... I'll try it! But I cant understand where is keeping the last 64 data. Could you explain me that part?

0 Kudos
Message 6 of 13
(5,128 Views)

The code above uses the Quotent and Remainder vi to count 0-63 then repeat. If this count is less than 63 we don't have all of our samples yet so the false case of the case strcutre executes.  In that case we add the current sample to the previous samples.  A shift register (http://www.ni.com/gettingstarted/labviewbasics/shiftregisters.htm) is used to pass the information from one loop iteration to the next, so all we need to do in the case structure is add the new sample.  When the iteration counter hits 63 the true case of the case structure executes.  In this case we add the current sample to the shift register value and then divide that by 8 as you requested.  A 0 is passed into the shift register so that the next loop iteration starts with with a fresh set of samples.

Let us know if that makes sense or if you have any more quesitons about this.

Thanks!

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 7 of 13
(5,128 Views)

I understand. Thank you. I have one question more, when I put a numeric indicator  to 'i' (iterations indicator). It is ever in zero '0'. Is that normal? Don't have to increase?

0 Kudos
Message 8 of 13
(5,128 Views)

Can you post a screenshot of your code?  If the inidcator is connected to the 'I' inside the loop it should update as the VI runs.  If the indicator is outside the loop it will not update until the loop is finished.

Thanks!

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker Group on google+

0 Kudos
Message 9 of 13
(5,128 Views)

Captura.PNG
I tested it, but it only take the last number, I mean, it takes a number each 64 samples. I need take 64 samples and sum all of them. Can you help me? (I fixied the previous problem, you can ingnore that). Whe I tested your vi, it worked fine. But in my schematic, the value of the sum is ever the same. (The counter is working, I can see how that increase.)

0 Kudos
Message 10 of 13
(5,128 Views)