LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulating and outputting a variable frequency without clicking or delays

Solved!
Go to solution

For a project, me and a couple of other students at my university are attempting to wire up a sliding potentiometer so that it'll output a variable voltage, and then read that in with a DAQ board in order to affect the frequency of a waveform that we're signaling. Picture the mechanism of a trombone, except it's much more complicated and sounds entirely worse, and you'll have the basic idea. 

 

The problem is that all of our varying attempts with different versions of our basic VI idea and subVIs provided by people on these forums have run into one of two problems: either there's a persistent, regular "clicking" noise (presumably from the while loop resetting), or a 2-3 second long delay every time we change the frequency. By messing with the properties of the simulated waveform, we can pick and choose from these issues, but we can't figure out how to defeat both of them simultaneously. Any help would be appreciated! Included is our first, most basic crack at trying to play and simulate a waveform, just to give an example of the kind of inexperience we have.

0 Kudos
Message 1 of 4
(1,959 Views)

Have you or the other students at your University ever had a class or any instructions in LabVIEW?  Did anyone tell you about LabVIEW being a Data Flow language and what that means, particularly in terms of being able to change things inside of loops?  Have you spent much time trying to learn LabVIEW?  [I'll note that the use of Express VIs and the questions you are asking suggest that the most likely answer to the above questions is "No".]

 

Here's a thought experiment (I assume some of you are engineering students, and may have learned something about signals).  I create a sinusoidal signal at one frequency and play it for, say, a second.  Without a pause, I play another sinusoid of the same amplitude, but a different frequency, for another second.  Do you think I will hear a "pop" or "click" when it (abruptly) changes?

 

Based on your answer to this thought experiment, what do you have to do to get a smoothly-modulated frequency (sort of like a trombone)?

 

Bob Schor

0 Kudos
Message 2 of 4
(1,925 Views)

Forgive me if I'm misinterpreting you, but it sounds like the points you make are relevant to my idea as to the source of the clicking; namely, that there is a jump discontinuity between the value of a wave as the while loop terminates and the value of the wave as a new loop begins. Operating on the assumption that this was the case, I had two ideas on how to fix it - first, by terminating the loop early when the wave had a certain value (for instance, after it completed an integer number of periods to end the loop when it crossed the x-axis so that when the next loop started, it would start at the same point), and second, by passing the current value of the loop through a shift register so that it started from the same point on the next loop as well. Unfortunately, I hardly even knew where to get started on these, and my fumbling attempts were pretty quickly discarded. As you correctly guessed, the only class we're in that has a LabVIEW component does not put a great emphasis on the foundational elements of the language and how to use them. Is the line of thinking I was exploring on the correct path?

0 Kudos
Message 3 of 4
(1,923 Views)
Solution
Accepted by topic author jmath2

@jmath2 wrote:

Is the line of thinking I was exploring on the correct path?


Yes, but you don't go far enough.  Have you heard of Frequency Modulation (as in FM radio)?  The idea is that you have a sinusoid and you smoothly modulate its frequency.  Well, with digital signals, "smoothly" is slightly nebulous.  It is (in some sense) easiest if you program the change (as opposed to try to manually control the frequency).

 

Here's some math:  Suppose I have a "carrier" at some frequency f, and want to know (as a function of time) the value of my signal.  I'm going to ignore phase, and set the amplitude to 1.  Well, signal (f, t) = sin (2*pi*f*t).  If f is a constant, this is just a sinusoid.  But now let f, itself, be a function of t, say f(t) = sin (5*2*pi*t), i.e. a 5 Hz modulation.  Now we have signal (f(t), t) = sin (2*pi*sin(10*pi*t)*t), sort of a complicated function, right?  If you plot this, you should see a frequency-modulated sinusoid.  So what do you do with this?

 

Well, you are generating a sampled waveform, meaning you use equally-spaced values of t (the spacing being 1/(sampling frequency), yet another "frequency" in this equation) and plug them into the complicated expression for signal (f(t), t) above.

 

But you want, now, to listen to this signal.  Well, choose a modulating frequency, say 44.1 kHz.  Generate, say, a second of sound (how many points would that be?).  Take these points and send them to a function that can play them.

 

OK, so what about the next second of sound?  If you remember where you left off in generating the signal, you should be able to generate the next second of sound, play that, and keep doing this in an endless loop until you say "Stop!".

 

Do you see any problem here?  Did you ever learn about the Principle of Data Flow?

 

Let's look at your original program, consisting of a signal generator connected by a wire to a "Play Sound".  When the loop starts, it takes some time (let's say 1 msec) to generate a waveform that if played at the "correct" rate, will take 10 msec.  We can't repeat the loop (Data Flow) until the sound has played, and we can't start playing until the sound has been generated.  So it takes 1 + 10 msec for the loop run (and repeat), but the sound only plays for 10 msec -- see the problem?

 

But Data Flow now comes to the rescue.  Suppose you generate the first set of points for the first 10 msec.  Now you come into your loop.  You send the 10 msec of points to the Sound Player, and at the same time you generate the next 10 msec and save them for the next loop.  How?  Look up "Shift Register" and think about it.

 

There are other, more advanced, ways of solving this problem, but the main point is that Data Flow allows LabVIEW to do computations and operations in parallel.  Your big task now is to figure out how to implement the time-varying wave generating function (think "Write a sub-VI", think about the inputs and outputs, think about whether it needs to have an internal "memory", and read again about Shift Registers).

 

Bob Schor

0 Kudos
Message 4 of 4
(1,914 Views)