LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble writing .wav file from 16 bit array

Hello,

 

I am trying to write my 16 bit ADC data to a .wav file and am having some trouble.  I'm very new to LabView so please bear with me....

 

Let me first preface that my GUI works very well before adding the addition of the wavefile write.


When I try to do a simple write at my ADC value, it really slows down my Waveform Graph 2.  The graph chokes and pauses and the data in the wave file looks corrupt.  

 

Could anyone take a look and see what I am doing wrong/missing?  My data is sampled at 5Khz.

Thanks for any help.

0 Kudos
Message 1 of 3
(1,190 Views)

A couple of points:

  • I'm not sure what you mean by a "wavefile write".  The only File I/O I see is writing a text file of whatever data comes out of the VISA Read.
  • When you talk about a 5 kHz Sampling Rate, where does this come from?  I do see some VISA code, but for sampling at these rates, I'd expect some DAQmx hardware.
  • You have a comment that says "analyze only every N samples", but you have only one Loop (the outer While loop), and it appears to be "clocked" by the VISA Read.  I suspect you are being tripped up by not understanding the Laws of Data Flow (which I will paraphrase below).

LabVIEW is a DataFlow language.  Consider a Structure (like a Case Structure, a While Loop, a LabVIEW function, a Control, or an Indicator).  They are connected by "wires", through which "Data Flows".  Here are three "Rules":

  1. If a Structure has one or more Wires coming in to it, it will not start executing until all of the Wires have Data on them (presumably from "upstream" Structures).
  2. If a Structure has one or more Wires coming out of it, no Data appears on any of the Wires until all the Wires have data that has "flowed" to them from inside the Structure.
  3. A Structure cannot exit until every sub-Structure within it has run (and exited).

Look at your code.  The main Structure is a While Loop, with a Case Structure inside it, and two additional "Green" Case Structures inside that.  Everything inside the While Loop has to run before the While Loop can count an iteration.  In particular, the right-most Green Case takes a Spectral Measurement for every VISA Read, i.e. for every data point, so if they are coming in at 5 kHz (or every 200 µs), and it take a millisecond to do the Spectral Measurement, your sampling rate goes from 5 kHz to 1/0.0012 = 833 Hz, and if it take 10 msec, you are now at less than 100 Hz.

 

Bob Schor

Message 2 of 3
(1,182 Views)

It was embedded in the case statement, but yes that makes sense.

The 5Khz sampling is done in hardware before the serial stream is fed in.  The waveform graph is not meant to plot each and every sample, I just need some visual that the signal is coming in correctly.

 

The 3rd and 4th byte of my data frame are my audio bytes.  I would like to write them to a .wav file.  I tried adding a second while loop to pick out those bytes and write them to the .wav file, however, right now it won't even create a new .wav file.

 

What am I missing here.
Thanks for the reply

0 Kudos
Message 3 of 3
(1,137 Views)