01-10-2017 03:38 PM
I’m currently working on a project where I’m required to generated soundwaves at different frequencies. I am having a problem when it comes to continuously running my code and saving the data. Is there a way I can get the program to generate the varies frequencies for 1 sec and record the data separately for each frequency?
01-10-2017 03:45 PM
What kind of problems are you having? Can you show us some code?
01-10-2017 04:20 PM
01-10-2017 04:46 PM
Thanks for the code. (Please don't maximize the front panel and diagram to the screen, that very annoying!).
You are not using a timed loop, just a plain loop with a wait.
Since you know the number of iterations before the loop even starts (assuming the controls don't change), a FOR loop is more appropriate. You can show the conditional terminal to stop early when an error occurs.
In any case, your equal comparison to determine loop termination is likely to fail with fractional numbers because of limitations of floating point math. You should do a "Larger or equal" instead.
Unless the user should be able to adjust the interval, end freq, sampling rate, etc during the run, their terminals don't belong in the loop.
There does not seem to be any synchronization between the sound generation and the DAQ stuff since they don't have any data dependency. In what order should they start?
The spectral measurement and file writing belong in a parallel loop. Use e.g. a queue to communicate.
01-11-2017 01:29 PM
Thank you for all the recommendations. I will look into making those changes. In regards to my issue, do you know how I would be able to program my signal generator to create frequencies from 200 to 2000 Hz but to do it in intervals. For example for the program to generate the 200hz frequency and hold that signal for a sec or so before changing to the next frequency lets say 205 Hz and so one until it reaches 2000 Hz.
01-11-2017 01:51 PM - edited 01-11-2017 01:51 PM
Hi Michelle,
generate the 200hz frequency and hold that signal for a sec or so before changing to the next frequency lets say 205 Hz and so one until it reaches 2000 Hz.
Some pseudocode:
freq:=200 repeat generate sine(freq, 1s duration) freq:=freq+5 wait til next 1s until freq >=2000
All you need is a loop, a shift register, a wait function and a signal generation function…
01-11-2017 01:57 PM - edited 01-11-2017 01:58 PM
Another option is to use the Ramp Function to create an array of frequencies you need and use a FOR loop with Autoindexing Tunnel to loop through the frequencies.
At 5Hz steps, that would become a fairly large array, so I would go with GerdW's pseudo code
01-11-2017 02:06 PM
GerdW,
Attach is the code im currently working with. Can you take a look at it and advise how I can incorporate the wait function to my program. Sorry im fairly new to labview and im still trying to learn how to use the program. Thank you in advance for the help.
01-11-2017 02:43 PM
Hi Michelle,
DON'T USE A TIMED LOOP FOR THIS!
(Atleast not as long as you don't really know what you are doing here!)
There are several functions in your loop which will have their own timing and delays. Putting them in a TimedWhileLoop with a strict timing will just create confusion and a mess! On a Windows PC you most often don't need TWLs at all…
Why do you need an ExpressVI to generate a sine wave?
01-11-2017 03:43 PM
GerdW,
I was able to recreate the function shown in the print screen. The function performs a frequency sweep from 200 to 2000 Hz. But is there a way to hold the tone of a frequency for a duration of 3 seconds? For example,we are looking to hold the 200 Hz tone constant for 3 seconds and for it to move to the next frequency and hold that tone as well for 3 seconds. Is there any way to control this?