A05 – Audio Analyzer

In this exercise you will create an application that will continuously measure the signal on the two audio inputs of a myDAQ, display the resulting time series data, and take a power spectrum to display the frequency content while satisfying the additional requirements listed below.

  • The application should be written in a dual loop architecture with one loop consisting of an Event Loop to handle user interface events and another loop operating as a queued message handler (queued state machine) to handle the data acquisition and other program actions.
  • Front panel controls for the Sample Rate in Hz and the Total Duration in seconds should be grouped in a type-defined cluster.
  • Use default values of 50kHz and 0.1 seconds for the Sample Rate and Total Duration.
  • The program should display the Nyquist Frequency (Hz) and Frequency Resolution (Hz) in indicators.
  • The application should continuously measure the signals from both audio input channels (left and right) and display results on a waveform graph.
  • The application should continuously perform a power spectrum of the acquired waveform data and display the results on a second waveform graph.
  • If the user changes either the Sample Rate or Total Duration controls then the application should stop the current acquisition and restart it with the new parameters. The Nyquist Frequency and Frequency Resolution indicators should be refreshed with new values. This DAQ restart should appear seamless to the operator.
  • If an error occurs then the program should display an error message and allow the user to attempt to correct the issue.
  • The application should stop the acquisition and shut itself down if the user presses a stop button or the red X.

Audio Input Action Engine

Encapsulate the code for measuring two channel audio from the myDAQ into an action-engine style subVI.

You should write a small test program that uses the action engine to verify that it operates correctly.

  • Your action engine should use a shift register to store the DAQmx TaskID for a data acquisition task that will perform hardware-timed analog input from the two audio input channels on the myDAQ. The DAQmx TaskID should be encapsulated in the action engine and should not be available externally on the subVI connector pane.
  • The subVI should use a type-defined enumerated control to perform the actions described below. This control should be a required input to your subVI.
    1. Configure – Finds a myDAQ connected to the computer and creates an analog input task for the two audio channels, audioInputLeft and audioInputRight. Sets up the timing for the task using Sampling Rate (S/s) and Buffer Size (sec) parameters provided by the caller. These parameters should be grouped together in a type-defined cluster called Timing Parameters. Use double-precision, floating-point representations for each with defaults of 50 kS/s and 0.20 seconds respectively. The configure action should use the Sampling Rate and Buffer Size to tell the DAQmx Timing subVI the number of samples to read. This value should be stored in a shift register so that the Read action will have access to it when needed.
    2. Start – Starts the analog input task.
    3. Read – Reads the appropriate number of samples from the audio inputs and returns the result in an array of waveforms.
    4. Shutdown – Stops and Clears the analog input task.
  • The action engine should incorporate standard error handling using an Error In control and Error Out indicator.
  • The action engine should be well documented. In the VI Properties -> Documentation the overall function of the action engine should be described as well as describing the function and the inputs and outputs for each of the different actions that the subVI will perform. The contents of each shift register should be clearly labeled and each case in your action engine should have a descriptive sub-diagram label. The controls on the front panel should also have descriptions that will show up in the Help window.
  • If you write a test program for the Action Engine, it should use a continuous loop design pattern. It should use your subVI to Configure and Start the analog input task before going into a while loop that will Read and plot the acquired data continuously until an error occurs or a Stop button is pressed. Upon exiting the loop the data acquisition task should be Shutdown.

Saving Data to TDMS File

  • The application should provide the capability to stream the measured time series data to a TDMS data file. There should be a File Path control on the front panel that allows the user to select an existing folder for where the data will be saved and a button with a switch mechanical action that will allow the user to Start or Stop streaming data to the file. The functionality for writing data to this file should be encapsulated into an action engine. Shift registers should be provided in the action engine for storing (1) the file reference number for the data file, and (2) a boolean flag, called status, that tells whether the data file is open (T) or closed (F). The action engine should have the following actions:
    • Initialize – This action should set the status flag to false. The subVI should be called with this action when your top-level VI starts up.
    • Create – This action should automatically create a new TDMS file in a folder location specified by a control passed from the top-level VI. The name of the file should be based upon the current date and time in a format similar to YYYY-MM-DD-HH-MM-SS.tdms. This action should set the status flag to True. This action should also accept the cluster of Timing Parameters and should write these values to the file as metadata. The subVI should be called with this action from your top-level VI whenever the Stream Data boolean button becomes True.
    • Write – This action should accept a buffer full of time-series data in the form of an array of waveforms. If the status flag is True then the data should be written to the file. If the status flag is false then nothing should happen. The subVI should be called with this action each time a new data buffer is read from the analog inputs.
    • Close – This action should close the TDMS data file (if it is open) and should set the status flag to False. The subVI should be called with this action from your top-level VI whenever the Stream Data boolean button becomes False and also upon shutdown of the main program.

State Diagram


01 – Setup Dual Loop Architecture
  • 00:00  Demo of Working Program
  • 03:00  State Diagram
  • 07:30  Program Actions Enum
  • 08:10  Create Main Program

02 – Create Timing Parameters Cluster

03 – Create Analog Input Action Engine

04 – Test Analog Input Action Engine


Print Friendly, PDF & Email