LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

acquire analog input sound for 10 seconds, display and save as wav file

Hi,
I am using one channel of a 9233 IEPE card to measure the input from a microphone. One of the tests I'd like to perform is to record XX seconds of sound (hopefully displaying the time signal and FFT), then save this XX seconds of sound to a wav file that I can play back.
 
I understand how to setup the analog input, I've got my waveform, but I'm not sure how to monitor the signal while it's measuring (let's say it's doing 500,000 samples of channel 3 at 50KHZ. This should be 10 seconds of data.
I'd like to see this graphically as it's measured, then have it save to a wav file so I can play it back later.
 
Also, I'd like to see an FFT of the same acquisition.
 
Is this possible?
 
jeff
0 Kudos
Message 1 of 9
(5,363 Views)

If you want to see the data displayed as it's be acquired, you're going to have to acquire fewer data points per acquisition.

Setting up the acquisition to get 500,000 samples will cause the DAQ Read to grab all 500,000 data points and output all of them as an array or waveform.

Try dividing the total number of samples per acquisition down to a number that will return the data in about 100mS chunks. (or experiment a bit to see what works best for you) So using your example, try grabbing 5000 points at 50kHz and loop on that 100 times concatenating the data from the previous run to the new data so you can plot it all and run your FFT.

As for getting it all to a .wav file, there's some VI's in LabVIEW to write data to a wave file. Look in the 'Graphics & Sound>Sound>Files' palette. You should find what you want there.

Ed



Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 2 of 9
(5,351 Views)

Thanks Ed, I'll give those things a try!

 

Jeff

0 Kudos
Message 3 of 9
(5,329 Views)
hmm.. it appears that the save to wav file VI's are looking for an array of waveforms.

I am extracting one channel of a four channel analog input (it's reading a microphone). The data was previously saved to a .tdms file.
 
the tdms file has four channels. If I open it, extract the last array, I can play it into my speakers and it sounds fine.
 
But when I try to save to a wav file using the VI, it's telling me that I need to send it an array of waveforms, rather than a waveform.
 
Am I doing this right?
 
Jeff
0 Kudos
Message 4 of 9
(5,268 Views)
Hello Jeff,
 
From the LabVIEW Help description:


Sound File Write Simple (Windows, Linux)

Writes data from an array of waveforms to a .wav file. This VI automatically opens, writes to, and closes the .wav file. Windows You must have DirectX 8.0 or later to use this VI. Linux You must have the Open Sound System (OSS) driver to use this VI.


So, the data input to Sound File Write Simple.vi is an array of waveforms. However, if you only have one waveform, you can build an array that contains only your single waveform using the Build Array VI. As described in the LabVIEW Help description:

Build Array

Concatenates multiple arrays or appends elements to an n-dimensional array. You also can use the Replace Array Subset function to modify an existing array.


So, for example, you could run your single waveform into the Build Array function and get an array of waveforms containing only your waveform. You could then wire this array of waveforms to the Sound File Write Simple.vi. This is shown in the image below.

Message Edited by Matt A on 06-28-2007 09:58 PM


Matt Anderson

Hardware Services Marketing Manager
National Instruments
Message 5 of 9
(5,245 Views)
wonderful! That worked, thanks!
 
It's a weird concept to accept though, that I can turn one waveform into an array of waveforms..
 
anyway, I've solved my problem, so thanks again!
 
Jeff
0 Kudos
Message 6 of 9
(5,227 Views)
Hello Jeff,
 
The Sound File Write Simple.vi takes an array of waveforms as an input because it can merge these waveforms into a single sound file. For example, if you wire an array with a 1kHz sine wave and a 10kHz sine wave, the resulting sound file will be composed of two tones. One tone will be at 1kHz and the other at 10kHz. So, by taking an array as an input the Sound File Write Simple.vi allows the user to mix separate waveforms into one sound file. However, since you wanted a .wav file of only your waveform, you only needed a single waveform in the .wav file. However, since Sound File Write Simple.vi requires an array as the input, you have to build your single waveform into an array. This results in an array with one element (your waveform). I hope this clarifies things.
 

Matt Anderson

Hardware Services Marketing Manager
National Instruments
0 Kudos
Message 7 of 9
(5,209 Views)

THanks Matt that makes it very clear!

 

Jeff

0 Kudos
Message 8 of 9
(5,202 Views)


@jeff_scharpf wrote:
 
 
It's a weird concept to accept though, that I can turn one waveform into an array of waveforms..
 


It's like a 1-D array with exactly one element.  But in this case, the element is a waveform.
0 Kudos
Message 9 of 9
(5,180 Views)