EECE 327Project 4LabVIEW Spectrum Program

An Audio Spectrum Analyzer Using LabVIEW

Jeffrey Bach

UNM PURSUE Program

LabVIEW is an icon-based software allowing control of processes and instrumentation, and creation of virtual instruments (VI’s) on the PC. The LabVIEW programming language is generally easier to write and understand than traditional text-based programming languages.

This project uses the capabilities of LabVIEW and the data acquisition card to measure the power spectrum of an audio signal. The power spectrum tells us the compostition of frequencies and their power level contained within a signal. For example, the power spectrum of a 1 kHz sine wave will be a spike (single frequency) at 1 kHz and the power will be proportional to the output amplitude.

Data Acquisition (DAQ) is the term used to describe the process of gathering data using digital means. Computers equipped with DAQ cards may have combinations of analog inputs, analog outputs, digital inputs, digital outputs, and counters. The particular boards that we have in the electronics lab contain eight differential analog inputs (or 16 single-ended inputs), two analog outputs, eight digital I/O lines, and two counters. The difference between a differential input and a single-ended input is that the single-ended inputs are all referenced to the same ground as the computer and DAQ card. The differential inputs are preferred, and are the only setup available in the lab on the breadboards that are connected to the computers.

In contrast to the thermistor project, power spectrum analysis requires relatively high sampling rates. While a thermistor may be sampled up to once per second, audio signals must be sampled many times per second. The actual sample rate is governed by the Nyquist criteria. Nyquist tells us that to accurately reproduce a sinusoidal signal, we must sample at a rate of twice the highest frequency component we expect to encounter. For audio signals, if we consider the range of frequencies to be from 20 Hz to 20 kHz, then we must choose a sample rate of 40 kHz or higher. This is known as the Nyquist rate.

If the sample rate is not twice the frequency of the input signal, then a phenomenon known as aliasing occurs. Aliasing can be thought of as a “folded back” measurement. The signals greater than 2 times the Nyquist rate are subtracted from the Nyquist rate to form an apparent frequency which falls within the acceptable frequency. These signals are misrepresented as lower frequencies, and thus contribute to error in the measurement of in-band signals. Figure 1 illustrates aliasing of a 1 kHz signal when sampled at various rates.

Figure 1 – Aliasing of a 1 kHz signal (from [1])

So how is aliasing prevented? The solution is to use an analog low-pass filter before the input to the DAQ card (see figure 2). The low-pass filter prevents signals that are beyond the Nyquist rate from reaching the DAQ card at an amplitude that is significant enough to show false measurements. Since ideal filters (infinite roll-off slope) are unachievable in real life, a real filter must meet certain specifications:

  1. The pass-band response must be flat to avoid amplitude errors in the measured signal. This means that filters that have ringing in the pass-band must be avoided. Avoid Chebyshev filters especially due to their excessive ringing.
  1. The roll-off must have a slope such that frequencies above the Nyquist rate are at a level such that they can be considered noise. If you define signals below –60 dB to be noise, then frequencies above the Nyquist rate must be attenuated below –60 dB.

Please note that rule number one applies especially to this program since we are interested in the amplitude of the frequency components of the input signal. Other applications may be more interested in the phase response. For these applications, the pass-band ripple is less important than the phase shift through the filter, and a Chebyshev filter may be appropriate (if the phase manipulation is not too great).

Figure 2 – System Block Diagram

The sampling must be buffered for the data to be acquired without timing errors. The thermistor program, in contrast, uses a software-timed acquisition. Buffered data acquisition for a single waveform is accomplished using the LabVIEW VI AI Acquire Waveform.vi. This is found on the functions palette (block diagram), Data Acquisition -> Analog Input. This VI is shown below as figure 4.

Figure 3 – Simple Buffered Data Acquisition

The device parameter is the particular DAQ card within the computer. Since we have only one card, this should be set to 1. The channel is set to whichever input channel is used, and will most likely be either 0, 1, or 2. The next two options set the number of samples at a time to take, and the number of samples per second (the rate) at which to take them. Again, for sound, the sample rate should be above 40 kHz.

The method of sampling presented here is referred to as simple buffered. There is a better way to accomplish the sampling such that the buffer is not cleared and filled with each iteration. This is called circular buffering. Information on circular buffering can be found in the LabVIEW Measurement Manual (see [2]).

LabVIEW has a simple VI provided to output the power spectrum of an input waveform. This vi is found under Waveform -> Waveform Measurements -> FFT Power Spectrum.vi (figure 4). For an example on how to use this VI, please see the DAQ examples in the help for LabVIEW. To understand more about the Fast Fourier Transform and sampling windows, please consult a book on signal processing.

Figure 4 – FFT Power Spectrum Usage

Your program should contain the following features: An FFT Power spectrum graph, a time domain graph (like the waveform on an oscilloscope), the ability to control how the FFT does the averaging, and the ability to control the window (FFT sampling method) that is used.

A sample program has been written which demonstrates the basic principles outlined. Please refer to figure 5 below.

Figure 5 - Program example with (slightly greater than) 800Hz input signal

References:

[1] G. W. Johnson and R. Jennings, LabVIEW Graphical Programming, 3rd ed., New York: McGraw-Hill, 2001, p. 90, figure 4.1.

[2] National Instruments Corporation. (2000, July). LabVIEW Measurements Manual. [Online]. Available:

For further information:

[3] G. W. Johnson and R. Jennings, LabVIEW Graphical Programming, 3rd ed., New York: McGraw-Hill, 2001, pp. 59-106.

[4] B. Mihura, LabVIEW for Data Acquisition, Upper Saddle River, New Jersey: Prentice Hall PTR, 2001

[5] R. H. Bishop, Learning With LabVIEW, Menlo Park: Addison Wesley, 1999

Page 1 of 5