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 
Search instead 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. 

 

Thanks in advance. 

 

z

0 Kudos
Message 1 of 11
(3,380 Views)

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
0 Kudos
Message 2 of 11
(3,366 Views)

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

0 Kudos
Message 3 of 11
(3,335 Views)

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
0 Kudos
Message 4 of 11
(3,333 Views)

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

0 Kudos
Message 5 of 11
(3,329 Views)

Hi zigolin,

 

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

check.png

(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
0 Kudos
Message 6 of 11
(3,325 Views)

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

0 Kudos
Message 7 of 11
(3,321 Views)

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
0 Kudos
Message 8 of 11
(3,318 Views)

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. 

0 Kudos
Message 9 of 11
(3,313 Views)

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
0 Kudos
Message 10 of 11
(3,310 Views)