10-29-2021 01:53 PM
Hello all!
In short, I'd like to generate a square wave at 1 Hz with an amplitude of 1 and with a duty cycle of 50% (zero offset) and use this square wave's pulse width to modulate a sine wave's amplitude. I'd like to use this square wave's y-value (1 or -1) to switch a case in which the amplitude property of a Sine Waveform VI can be multiplied.
(See attached) For example, with the square wave described above, the y-value y(t) of the square wave would be 1 for half a second, and -1 for the other half (y(t)=1 for t<0.5, y(t)=-1 for t>0.5). I intended to use this to compare the instantaneous y-value of the square wave with a Greater Than Zero? function. I would then send this output to a case structure in which the amplitude property constant of a Sine Waveform VI would be multiplied by 2 if True, and simply passed through if False.
So basically, I'd like to use pulse width modulation to modulate a sine wave's amplitude controlled by half of the square wave's period. However, I can't seem to figure out how to obtain an instantaneous y-value from the square wave. I know that the waveform y-value data is a 1D array of doubles, so I'm stuck on how I could do this (I assume a flaw in my understanding of how LabVIEW runs). Is it possible to use a square wave to modulate a sine wave's amplitude at all?
I know that there are other ways to do this (such as via a timed loop), but eventually I want to use an external square wave acquired via an external source to modulate the sine wave. This is an attempt to develop my VI before I am ready for an actual external square wave.
Thanks in advance for any advice and insights!
10-29-2021 03:05 PM
Is there any hardware involved or is this just a simulation?
Not sure why you are using the error output for the case decision. That has nothing to do with the data.
Maybe you want to generate your data "point by point" and display it on a chart. I don't think you need any waveform or dynamic data. Where do you define the loop rate?
If I understand this right, your duty cycle is always 50% and you just want a 180 degree phase change of a sine wave with each transition.
Sorry, I don't have LabVIEW 2021 available, so I cannot open your snippet and look at it in more detail. Feel free to "save for previous" and attach the actual VI.
10-31-2021 12:16 PM
I'm assuming you have not (yet) taken a class in (or studied, or read about) Signal Theory, especially the difference between a digital (or "sampled") representation of a (usually) continuous "signal" (such as a voltage) and the signal, itself, which has a value at every "instant" in time.
Sampled signals are represented by a LabVIEW data construct called a "Waveform", which incorporates time in two places (t0, the time the Waveform sample started, measured as accurately as LabVIEW can determine it, and dt, the sampling time, or time between successive samples), along with an array of Sampled Data (Y).
Suppose you configure your Waveform to represent 1000 samples acquired at a rate of 1 kHz. Every second, LabVIEW should present you with 1000 points representing the previous second. Suppose you are sampling a square wave and it has a single transition in that previous 1 second. When did it occur? Well, you can look at the data and see when the value changed, but notice that it will sometime in the past (LabVIEW has not yet mastered "predicting when the signal will change in the future").
You might want to re-think what you are trying to do, You can, indeed, use digital square wave signals to modulate a (in-principle-continuous) value, such as an amplitude, but you need to think how you acquire the digital signal and how you use it. If you want to make a change "as close as possible" to when the digital signal changes, you have to look at every sample as it is acquired, not acquire 1000 samples before looking at them.
Bob Schor
11-03-2021 10:03 AM
@altenbach,
I will eventually be using an external device (most likely a function generator) to produce a square wave, but that will not be for some time, so I will need to simulate (or work around) this missing external input while I build the rest of the VI.
Not sure why you are using the error output for the case decision.
I apologize for that confusion, I hooked up the wrong output when trying to make the snippet for this post. The attached VI (saved as previous version 20.0) should be corrected.
I also believe that I'd like to generate my data "point-by-point", but after the responses here, I'm starting to see that that isn't possible with the Waveform or DDT. I may be forced to simply set a loop that executes every 10ms and modulates the amplitude of my sine wave by evaluating which iteration it is on.
If I understand this right, your duty cycle is always 50% and you just want a 180 degree phase change of a sine wave with each transition.
To clarify on this last point, the square wave will have a 50% duty cycle, but I don't want a phase change for the sine wave, simply an amplified amplitude. I would like to use it to tell my sine wave what to multiply its amplitude constant by (either by 1 or 2). For instance, for a square with pulse width of 10ms (again 50% duty cycle), if I generate a sine wave (amplitude = 1) for one cycle of the square wave (20ms), the first 10ms of the sine wave would have an amplitude of 1, and the last 10ms of the sine wave would have an amplitude of 2. I don't desire any phase or frequency change.
Thank you very much for your comments, questions, and advice!
11-03-2021 10:22 AM
@Bob_Schor wrote:
If you want to make a change "as close as possible" to when the digital signal changes, you have to look at every sample as it is acquired, not acquire 1000 samples before looking at them.
I think that I'm starting to understand my mistake. The entire waveform is being generated with an array of samples before being sent out, at which time I'm accessing it, and I have no way of going back in time to switch the sine wave amplitude according to the change in (square) waveform's y-value.
It's my understanding that once I begin sampling an actual external square wave's voltage, that I'll be able to modulate my sine wave with significant accuracy. I also believe that it'd be trivial to set up a loop that simply changes the amplitude of my sine wave signal, but I'm finding this to be a great learning opportunity.
Suppose you configure your Waveform to represent 1000 samples acquired at a rate of 1 kHz. Every second, LabVIEW should present you with 1000 points representing the previous second.
For fun and clarification, if I were set up a square wave VI using your example here, and set it up in a loop that executed every 1ms, I assume that the waveform would not have generated yet (perhaps until the 1000th iteration (i=999)?), is that correct? I believe that follows from your second sentence in the quote above, but I hoped to clarify.
Thank you for your succinct and very helpful response. I believe that my understanding of Signal Theory (you're correct about my ignorance of it) is the issue at hand here, and I think that you have helped me a great deal in flushing out how it was hindering my approach in this VI.