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…