Lab View Example: A Simple Signal Averager Figure 1 is a diagram of a basic signal averaging virtual instrument. Signal averaging is at the heart of many programs used for acquisition of evoked potentials (EPs). EPs are 1 to 2 orders of magnitude smaller than the electroencephalogram (EEG) from which they must be extracted. The peak-to-peak amplitude of a somatosensory EP may be less than 1 F~V. Signal averaging relies on the fact that evoked potentials are time-locked to the evoking stimulus. By summing and averaging several hundred segments of EEG immediately following the stimulus, background activity ("noise") can be eliminated, while the signal of interest is preserved. The program uses a WHILE loop that continues until the specified number of sweeps has been acquired. A shift register positioned on the boundaries of the loop holds the summation waveform array. Shift registers are a convenient way to "remember" data values acquired or calculated in previous iterations of loops. Data enter the shift register on the right side of the loop, and are available at the left terminal during the next iteration. In the example in Figure 1, each EP sweep is added to the summation waveform. To obtain the averaged EP, the summation waveform is divided by the number of sweeps acquired. Two counters are updated every sweep: The first counter holds the number of averaged sweeps; the other counter holds the number of rejected sweeps. A CASE structure is used as part of the artifact detection algorithm. A dedicated subVI tests each incoming sweep to determine whether one or more of the artifact criteria are met. The result is a BOOLEAN variable (TRUE or FALSE). Only when the artifact criterion is not met (CASE selector = FALSE) will the most recently acquired sweep be added to the summation waveform; otherwise, the sweep is rejected, and the rejected sweeps counter is incremented. Ease of Programming and Documentation LabVIEW code is quite flexible and reusable. VIs can be nested almost indefinitely. The programmer can design icons for each VI or subVI, and can determine which front panel controls and indicators will be used as terminals to receive or supply data. SubVIs can be set to perform their calculations only, or to open their front panel when called. VIs can be shared among many applications.
For example, a digital filter VI might use an array of integer numbers, a cutoff frequency, and slope as inputs, and provide the digitally filtered data at the output. This VI needs to be written only once. It can then be reused in several programs. Another important aspect of LabVIEW is that many operations show POLYMORPHISM" addition, subtraction, multiplication, division; and even some of the more complex operations accept any data type on their inputs. For example, a
numeric array may be multiplied by a single number, or two arrays may be multiplied by each other, all by "wiring" them to the same multiplication function icon.
A common problem with line-oriented program languages is that unless one meticulously documents every statement and function, the program may rapidly become incomprehensible, not only for others, but, after some time, even for the programmer who designed the program. LabVIEW, by nature of its graphical programming syntax, provides almost self-documenting code; that is, one can usually deduct the function of the program by following the wires to and from the various functions and subVIs. In addition, each control, indicator, wire, or function can be individually commented, without cluttering the diagram. The comment can be made visible by clicking on the function. The current version of LabVIEW does not allow collecting and indexing individual comments in a list. Front panels, diagrams, and the hierarchy of subroutines can be. printed. Optionally, the contents of the various CASE alternatives can be individually printed.