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: 

Sine wave generating using formula

Hi Guys.

 

I'm new in LabView and have a problem with sine wave generator using formula. Basically I want to generate the signal which will include start delay, specific number of cycle with specific frequency in sec, hold time and limitation of max and min signal e. g. starting at 0 for 2 sec then switching for 2 cycle of sine wave -> freq 2 sec and amplitude 5 limited in positive signal at 2 and then coming back to 0 for 3 sec -> hold time, and starting from beginning.

 

My problem is the sine wave not starting from zero but after Start Delay is jumping to some point where it will be when running from the beginning as a sine wave. I've attached the picture as a reference. There can be a problem with formula as well as I'm a mechanical engineer and first time touch with such a programing.

 

Can you please look at it and suggest how to solve that issue? In attached file there are cases where I've tested case "sine" and "step" where I've put a bit different solution. Both not working. 

Download All
0 Kudos
Message 1 of 7
(2,858 Views)

If you need the sine wave to start at zero after the Start Delay, you need to subtract it from in the time parameter for the SIN input.

 

The chart shows the first point of the sine wave at exactly the location of the Start Delay.  The chart shows a line connecting the previous point.  If the first point was 0 as intended, there would not be any difference between the 2 points.

Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.0, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 2 of 7
(2,849 Views)

I get the feeling that this all could be done with <20% of the current code. Can you attach your VI once more, but having typical default values in all controls so we can run it without having to guess. (Change all controls to reasonable values, select them all, edit..make current values default, save VI, attach it once more).

 

(Some controls seem to contain derived values most of the time. Shouldn't these be indicators instead? Some of your algorithm choices are weird. Why is the inner loop running more and more times, repeating calculations that have been done already earlier (unless controls change. Why is there no way to stop the outer loop? [sec] is not a frequency unit. And no, it does not start slighly before start delay. The point is exactly at the start. You see the linear interpolation where there are no points. That's fake.)

0 Kudos
Message 3 of 7
(2,822 Views)

Hi.

 

Thanks for your replay. I'm attaching the VI with default values. 

 

I will try to answer your questions as well:

1. All control values are adjustable to get as specific signal as I would like to get.

2. Inner loop is creating one full cycle i.e Start Delay + Number of cycle*Cycle time + Hold. If repeat push button is "on" it will repeat this sequence, if not it will stay to the end on DC value. 

3. There wasn't stop button just because of testing purpose. I've add it now.

4. Of course [sec] is not a Freq unit, I've change the name now. Panel need to be very simple and intuitive so it is the time of 1 wave cycle.

 

Hope that will help to understand the problem.

 

Regards

0 Kudos
Message 4 of 7
(2,779 Views)

Break out the Pencil and Paper, and answer the following questions:

  • What is the value of your function at t = 50?  [Correct answer -- undefined!].
  • What is the value of your function just before t = 50?  [Use Pencil and Paper].  What is the value just after t = 50?  [Use a calculator if you need to].  Are these the same?  Do you want them to be (almost) the same?  Did you read the earlier reply that told you how to "make it so"?
  • I recommend that you learn to generate waveforms (small "w", to distinguish from Waveforms, a LabVIEW data type that might be helpful in generating better code for your situation) using LabVIEW Functions (like add, subtract, multiply, and the Mathematics function such as Sin) than the Matlab-like Formula node.  Also learn about using sub-VIs to "hide the messy details" and make the logic of your code simpler to follow.

Bob Schor

0 Kudos
Message 5 of 7
(2,740 Views)

Hi,

 

Thanks for your answer and explanation.

If you know where is the issue can you help to implement what you already said? As said I'm a beginners and pretty didn't get your explanation playing with t=50? Function is done to permanently repeat the pattern so why to bother that?

 

Question is really simple. How to change the formula or add something to make it work correctly, means wave starting from beginning.

 

Regards     

0 Kudos
Message 6 of 7
(2,708 Views)

It's your formula.  Get out a calculator (or simply write down, with pencil and paper, the formula, decide what the value is at t = 49.9 (I'm going from memory, here, since you haven't put in any effort, I'm just going to trust my memory and say I think I remember that it is 0 before t = 50, and may even at t = 50), then evaluate it at t = 50.1 (or 50.000001).  Is it "near" zero?  Do you know the meaning of a "continuous" function?  Do you want a continuous function?  Looking at your "before" and "after" t=50 function, what would you need to change to make it continuous?

 

If you have had an algebra class (maybe in high school), you should be capable (with pencil and paper) of writing down an Equation you could solve for Something.  Now put that value of Something into your Equation ...  [I'm not going to tell you "the answer" -- you need to learn to think and solve these problems yourself].

 

Bob Schor

0 Kudos
Message 7 of 7
(2,698 Views)