LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Average after every 20 scans

Highlighted

Hello,

 

I want to take my VI a step further. I'm currently saving the locations and amplitudes of the peaks for the individual scans. In addition to that, I now also want calculate and save the the average of the peaks locations and amplitudes after every 20 scans (e.g., 0-19, 20-39, 40-59 etc.). Any help will be appreciated. 

 

Petmarscan and move.PNG

 

0 Kudos
Message 1 of 24
(779 Views)
Highlighted

You could keep a running sum and the number of scans in shift registers.  When the number of scans has reached 20, divide to get the average, save your average, and reset your shift registers to 0.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 2 of 24
(730 Views)
Highlighted

The "simple answer" to your question is to arrange your "Take Data" case to accumulate the 20 "single items" you are writing in an array by passing them out of the For loop through indexing tunnels, then before exiting the Event structure, forming averages from these arrays and writing them to a file with a slightly different name (maybe "Image Average").

 

A more complete answer is that it would really surprise me if your code works!  There are numerous "style" problems with the part shown on your post that could (and should) be improved by doing such things as "hiding the details inside subVIs".  Here are a few examples:

  • You almost never need two Error Lines.  Note that you "reserve one" for this Case, but don't seem to do anything "error-wise" with it, while you have another, used for the rest of the code, that simply is ignored in this case.  Why?
  • Bring input wires in from the left of the function.  Look at the File Reference wire going from Build Path to Write to Text File -- it appears to be wired into an Output Connector of the latter function, but really is (correctly) wired to the top left Input.  Wires should (ideally) run straight, horizontal left-to-right, with "data" (almost) never flowing right-to-left (as happens here).
  • SubVI's are excellent for "hiding messy details" and allowing you to see the (structural) Forest for the Trees.
  • The "logic" of your program structure is a tad obscure.  You are using a State Machine (good), but it is difficult to (without comments or better/cleaner organization) "see the big picture" of what is going on.  The States seem wildly unequal in terms of "level of detail" (contrast "Take Data" with any other State).

Bob Schor

0 Kudos
Message 3 of 24
(727 Views)
Highlighted

Hello crossrulz,

 

Can you show me how it can be implemented? I have seen similar ways of doing it but I always get broken wires when I try it.

 

Petmar. 

0 Kudos
Message 4 of 24
(712 Views)
Highlighted

Hello Bob,

 

I understand your concerns about my VI but the truth is that I'm very new to LabVIEW. I've been able to come up with this thanks to the good people on this forum and so far it works fine. To be honest with you I don't know how I'll implement or fix most of the issues you raised. Please help me if you think there are areas that need improvement. Thank you.

 

Petmar.

0 Kudos
Message 5 of 24
(709 Views)
Highlighted

@petmar wrote:

Can you show me how it can be implemented? I have seen similar ways of doing it but I always get broken wires when I try it.


 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 6 of 24
(696 Views)
Highlighted

Just a quick note on something I saw in your diagram:

 

Don't open and close VISA sessions every time you use an instrument.

 

Open a VISA session at the beginning of your program  

Use shift registers to pass the VISA session around the loop and reuse it every iteration

Close the VISA session at the end of your program

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
Message 7 of 24
(683 Views)
Highlighted

Hello crossrulz,

 

I followed your steps but it seems I messed up somewhere. Can you please check for me. Thank you.

 

Petmar.scan and move2.PNG

0 Kudos
Message 8 of 24
(681 Views)
Highlighted

Hello RT SLVU,

 

Can you please wire what you're suggesting for me. I not sure of what you're talking about. You can do it in the VI above. Thank you.

 

Petmar.

 

0 Kudos
Message 9 of 24
(678 Views)
Highlighted

Petmar,

 

     This is your Project.  You've gotten numerous suggestions, but don't seem to have implemented many of them.  Try "starting over", using the suggestions, but trying to do just one thing at a time.  If it works (and it should), then add something else.  Start with using a single Error Line ...

 

     I assume you are trying to learn LabVIEW.  In my experience with trying to learn a number of Programming Languages and paradigms (including LabVIEW), there is no substitute for writing programs when learning how to write programs.  Having someone do your work for you doesn't really teach you to "do it yourself".

 

Bob Schor

0 Kudos
Message 10 of 24
(667 Views)