I'm building this Simulate signal VI to generate waveform within a dedicated period of time determined by Elapsed TIme express VI both in the same loop. So that I can control exactly the output signal period for further application.
For instance, the simulation signal period is 6s and time elapsed for the while loop to run is 3s, therefore I should always obtain 1/2 period signal generated when the while loop terminated. But somehow, the Simulate signal express VI is by chance over generate extra 1 point that ruins the expected output signal.
Please help me to fix this,
Thank in advance.
Solved! Go to Solution.
Don't do it that way! Get rid of the Elapsed Time Express VI, the Simulate Signal Express VI, learn about Waveforms and use the Waveform Generation VIs, and do a little arithmetic to generate precisely the points you want. It helps to understand what LabVIEW means by a Triangle Wave, to understand what Frequency and Phase mean with such a wave, and a few other things that I don't think you fully understand.
Great reply sir, thank you!
But can you give me a brief example of how it can be done?
I think Waveform Generation VI is not well explained and is not commonly used. Since the timing between loop iteration and the single signal point generation is also critical to my program, this indirectly determined by the Sample per second (Hz) in Simulate Signal Express VI.
Well, you didn't describe what you wanted to do very clearly. Have you looked at the Examples that ship with LabVIEW? There are a number of examples showing Waveform Generation (some using the Waveform Generation functions, not the Express VIs) and playing them through various output devices.
Suppose you want to generate a Triangle Wave and output it at 100 points/second. I'm assuming you'll specify the waveform so that you'll get the appropriate waveform -- in your example, your rising phase lasts 1.5 seconds, or 150 points, and your falling phase is another 150 points, and if this is supposed to be one period of a triangle wave, then the Wave has a non-zero offset and a phase lag of 90°. Here is a Snippet (LabVIEW 2018) that generates one cycle of a 0.33 Hz (roughly 3-second period) Triangle Wave with a 90° phase lag at 100 Hz and for 300 points. I plotted it, setting the Plot to display Relative Time (so it starts from 0) and displaying the scale as seconds (with one decimal point)(right-click the Chart and set its Properties) -- I get a Triangle Wave from -1 to 1 (I leave it as an Exercise for the Reader to modify it so it goes from 0 to 10).
So how much time does it take to do this (not counting the plotting)? About 30 microseconds, i.e. 300 times faster than it takes to generate a point "in real time" (= 10 milliseconds). So you could generate a waveform, play it out "slowly" (one point every 10 milliseconds), and when you are done, generate another 300 points, play it out, generate, play, etc. Or, if you are really worried about the time to generate the points, do the following:
Now when your loop finishes, you have the next set of samples ready to go, so you repeat with no delay (note that if you generate during the last time through the loop, you just replace the (now empty) array of data with the newly-generated "next" part of the waveform). Incidentally, what you see here, a "vague" statement of when to generate the data in the algorithm above and a "better" way to do it in the preceding sentence, is an example of "thinking while designing", and getting the main points first and letting the details "suggest themselves to you".
Thank you so much for your detail explanation,
My idea is that I need the loop to run simultaneously with the point generation process. Because some code needs also to proceed inside it at the time between iterations.
So I use the sampling rate to determine the loop iteration time, then together with the period (1/frequency) to control the spacing between points and the number of the cycle that I want to generate.
Everything is fine except for your plot. You are updating once/second, presumably by sending values to a D/A converter. This is the output you will get:
The value is 0 for a second, then 1, then 2, then 1, then 0. Is this what you want? I suspect that it is not. If you are generating a signal digitally, you need to think about the update rate and how you go from one point to another.
Yes, that is exactly what I need, except the number of sample per generation is 1.
I'm controlling a thermal bath by sending this kind of signal to modify its temperature that following the triangle or sine wave. The update rate and the way it goes from one point to another should be even lower (longer) more or less.
You might have mentioned this earlier, but if so, I didn't notice it (I apologize). Here's a "thought experiment" to consider:
No, you did an excellent point out!
That I need to use the for loop (controllable iteration) with waveform generator VI, which allows deeper modification. Especially, the sample rate is actually a VI input gate, therefore I can directly intervene to change the iteration time and value (step) different between two consecutive generation points.
In the case of high thermal inertia (like a thermal bath), I can just make the iteration time extra slow (a couple of minutes perhaps). Otherwise, if it's too fast then the lag behind the desired temperature will occur.