From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

# LabVIEW

cancel
Showing results for
Did you mean:

## How to simulate two sine funcitons

Dear all,

first, I am trying to create (simulate) sine function in time. For example, when I would start a VI, the function starts to change (sine wave). After that I would need a second function, that would be dependent on the first one, but with a certain lag. For example, when first function increases, the second one would follow the first one but with the certain time lag in between.

Any ideas? I tried using while loop and a sine function, but couldn get anywhere 😕

The VI is attached.

z

Message 1 of 11
(3,380 Views)

## Re: How to simulate two sine funcitons

Hi zigolin,

After that I would need a second function, that would be dependent on the first one, but with a certain lag.

"time lag" usually means "phase shift"…

Have you tried to calculate your 2nd sine wave with a phase shift?

In general it helps to write down the math ("formulas") before starting to code them. Can you supply the needed formulas?

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 11
(3,366 Views)

## Re: How to simulate two sine funcitons

Yes, sure.

f(x) = A*sin(2*pi*freq*t)

g(x) = A*sin(2*pi*freq*t + phi)

where phi is a phase shift, freq is frequency and t is time. In attached VI, I created a cosine wave, but I have a problem running it repeatedly, so I would get more periods on graph.

Thanks.

Z

Message 3 of 11
(3,335 Views)

## Re: How to simulate two sine funcitons

Hi zigolin,

so all you need is to implement the "+phi" part in the loop!

Where exactly do you have problems with?

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 11
(3,333 Views)

## Re: How to simulate two sine funcitons

Not just that. Actually the VI now calculates only on period, I would like the it would contniouslly calculate this periods (from 0-25) until I stopped it. The I would add another wave that will be phase shifted. I guess that I have wrongly determined while loop to do so?

Thanks Z

Message 5 of 11
(3,329 Views)

## Re: How to simulate two sine funcitons

Hi zigolin,

while I usually suggest to get rid of ExpressVIs this time they are really helpful to implement your problem:

(Both ExpressVIs are set to the same settings.)

Edit: I just learned you cannot change the phase while the VI is running, by default the ExpressVI does not use an updated phase value. You need to send a TRUE to "Reset signal" too…

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 11
(3,325 Views)

## Re: How to simulate two sine funcitons

Thanks for that! Any ideas how can I get this done using my VI?

Message 7 of 11
(3,321 Views)

## Re: How to simulate two sine funcitons

Hi zigolin,

Any ideas how can I get this done using my VI?

Either implement your formulas in your VI or take my suggestion! 😄

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 11
(3,318 Views)

## Re: How to simulate two sine funcitons

Perhaps I have asked question wrong: I would need to make it that way, that when I start the VI, the sine wave would start draw on front panel (graph), so for example, after 5 second, there would be 3 periods on the graph I if I don't press stop, it would still draw new periods.

Message 9 of 11
(3,313 Views)

## Re: How to simulate two sine funcitons

Hi zigolin,

you you want to create a larger plot from those generated sinewaves?

Either use a chart (with it's own history buffer) or build your own larger waveform using AppendWaveforms!

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 11
(3,310 Views)