LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving all data from a while loop

Solved!
Go to solution

I already asked a similar question but it might not be very clear and there were some concepts that I could not well understand.

1. I have a key pad to generate DTMF stream signal (I call it stream because it contains multiple tones which make up of a complete phone number)

2. I would like to save it as a wav file but I guess other format is okay and because the write to wav file does not support append so for this particular case, I use write to waveform instead of write to wav

 

My approach is to have a queue structure so I can write each iteration result to a file.

i)When I try to retrieve the data, there is nothing but 0.

ii)my intention is to get 8000 sample per second (fs = 8,000) but it save the data so fast

 

I attached the file so if there is way to solve the problems, please help me. 

0 Kudos
Message 1 of 17
(4,266 Views)

I believe what is happening is that your producer loop is iterating even when there is no key press and sending blank or default data to the consumer and overwriting the test.wav file.  

 

Easy way around this is to put an event structure in the producer that only enqueues data when there is a key press.   I can't see into the Mathscript node so I'm not sure what's going on there, but I suspect the default output (e.g all of the Booleans are false) is for zero-length arrays on f1 and f2 and this is getting enqueued and overwrites any real data that might have been in test.wav.

 

It should be possible to append to a .wav.  I have attached a proposed method.  Caution that this in your consumer will take longer and longer as the file grows as it needs to read in the file every time.  

Message 2 of 17
(4,256 Views)

Thanks Zwired1,

 The program needs to have the zero values too - it is used to seperate the tones so I do not worry about getting the zero value in between two tones.

A normal stream should be less than a min (times to press like 10 numbers).

 

Oh, the mathscript node just returns the f1 and f2.

0 Kudos
Message 3 of 17
(4,251 Views)

Ah. 

 

In that case, two things:

 

1] almost assuredly the program saving only the last thing enqueued is the biggest part of the problem

2] you need some mechanism to sync the amount of data (time length equivalent of the array you are producing in Mathscript)  to the iteration rate of the producer.  If you generate 1s of data every time the loop iterates and it iterates 100 /s you'll end up with a lot of data and an exaggerated time scale.  I'd use a 10ms wait in side the producer and generate 10ms time-equivalent of data.  That way, your loop iterates at a constant rate and is still responsive to UI activity.

 

Another thing you can do to help with the append issue is use a shift register in the consumer to accumulate data.  Append the dequeued data to an array inside the consumer and save it off to a file once the array size gets larger than x.  Increment the file name and zero the shift register and keep going.   You'll need some mechanism for saving the last bit of data when you shut down but I see by your "stop never" loop conditions that you're not too worried about that.... Smiley Happy   

Message 4 of 17
(4,242 Views)

THanks for the tips. I will try.

I only run a program for a short priod of time to get the recorded stream that why I just put the loop run forever and have the code saving the data inside the while loop.

 

0 Kudos
Message 5 of 17
(4,237 Views)


Running infinite while loops is a horrible idea.  The only way to end your program is to abort it.

 

What you can do is create and event structure for Mouse down and mouse up.  On mouse down, you generate the tones.  On mouse up, you generate a waveform without tones.  Now you'll have the waveform with distinctive breaks in between.

Message 6 of 17
(4,231 Views)

I am kind of new to this so I am limited. Is there anyway to replace the while loop with even struture in a fast way from what I have right now?

0 Kudos
Message 7 of 17
(4,225 Views)

Put the event structure in the while loop.  Put the code that generates the keytones in the mouse down event.  Put the code that generates the "no tone" in the mouse up event.

0 Kudos
Message 8 of 17
(4,218 Views)
Solution
Accepted by topic author muahang1234

This vi includes many of the items discussed above. It does not have provisions for the "no tone" intervals.

 

Changes: Replaced Mathscript node with native LabVIEW functions. Button Mechanical Action to Latch when Released.  Cluster to Array replaces Unbundle and Build Array. Reshape Array to match shape of keypad. Separate searches for row and column frequencies. Note that this is easily expandable to handle the 4x4 keypad. Added event structure. Added Stop control (but did not implement stopping for the file loop). Added indicators for diagnostic purposes. Added FFT Spectrum and graph.

 

I disabled the Write to File portion for testing.

 

Lynn

Message 9 of 17
(4,213 Views)

I realy appreciate your help.

 

Can you give  advice on when should we use not use Matscript?

 

0 Kudos
Message 10 of 17
(4,202 Views)