LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Damped oscillations

Solved!
Go to solution
 

Hi,

Some good idea how to made virtual digital Q-meter which can view damped oscillations in graph?
I think i need to use input values from this formula: u(t) = A*exp(-gamma*t)*sin*(ω*t+phase).

Thanks

0 Kudos
Message 1 of 8
(4,358 Views)

Hi Feedy,

 

what have you tried so far? Where are you stuck?

 

LabVIEW comes with a lot of math functions, including sin() and exp(). So all you need is to create an array of "t" values and apply your formula with your constants A, gamma, omega and phase). Math is easy as all basic math functions support polymorphism to handle arrays directly: you don't even need a loop to calculate u(t)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(4,339 Views)

I don’t have many favors with this program (this is the biggest problem i think).

 

I got stuck at the beginning. I don't know how to make a graph out of so many variables.

0 Kudos
Message 3 of 8
(4,330 Views)

Start with a ramp of times (ID array [t]) and graph it. It should be a straight line that starts at zero and goes up.

 

Create controls for all parameters (A, gamma, w, phase). Place a graph.

 

Now modify it with one parameter at a time and graph each internedate result::

 

First, multiply the time ramp with "-gamma" (no loop needed) and take "e" to the power of it. If gamma is positive (and  -gamma thus negative), you'll now get a curve that starts at one and decreases exponentially. Adjust gamma so it goes down smoothly over the graph range,( i.e. not drop instantly or remain nearly constant).

 

Now add "A" which you use to multiply the resulting array from above. If A=1, nothing would change, but for other A, the data will scale accordingly.

 

Now multiply the [t] with w, add the phase, and take the sine. Multiply that with the result from above.

 

Graph it again, and voila! 😄

 

Now place everything in a while loop, add a small wait, add a stop button and run it again. At this time you can play with the parameters and see in immediately how the output changes.

 

 

0 Kudos
Message 4 of 8
(4,307 Views)

Thanks a lot, but I still dont know how to correctly create a graph for this. 

I attached what i created.

0 Kudos
Message 5 of 8
(4,299 Views)

Please do not maximize the front panel and diagram to the screen! This makes it difficult, because you cannot see both and you cannot see the help windows (which you need!) at the same time.

 

To create a time ramp, use ramp pattern, not a simple array control. Define start and end times and the number of desired points. There is also a function to negate. No need for anything blue.

0 Kudos
Message 6 of 8
(4,282 Views)

Thank you,

 

I think it works. Do you think that's right?

0 Kudos
Message 7 of 8
(4,242 Views)
Solution
Accepted by Feedy

@Feedy wrote:

I think it works. Do you think that's right?


Congratulations! I am sure you learned a lot.

 

Yes, it works, but there are a few flaws that have nothing to do with the algorithm, but are good habits to learn.

 

  • "Ramp by samples" never changes and can go before the loop since the output is always the same.. It only needs to run once when the VI starts, and not millions of times per second. Of course you could make its inputs controls (start,end time, # of points) and then it would need to go inside the loop, of course.,
  • As I already said, you loop needs a small wait (e.g. 50ms). Currently, it uses 100% of a CPU core mostly repeating the exactly same calculation over and over as fast as the computer allows. This wastes battery and makes your computer running hotter than needed. The loop does not need to spin faster than your capability of changing controls. (In the next lesson, you could even start using an event structure so the recalculation only happens when a control is changed).
  • There is still a function to negate. No need to multiply by -1.
  • Once all your controls have reasonable values, make their values default so we can immediately run it with typical data. At the moment all your controls are zero, giving a very uninteresting output. (enter reasonable values, select all controls (not indicators!), then menu...edit...make selected values default.)
  • You might want to add some scaling to have reasonable units (e.g. phase in degrees instead of radians). I sometimes prefer unit-less, making the slider go from -1 to 1, calling it "phase/pi", and multiplying with pi on the diagram (not shown).
  • It is not a good idea to have extra periods in the file name ("Damped oscill..vi")
  • Arrange the code more logically and avoid all these wire bends. Avoid unecessary right-to-left wires.
  • Make the controls more usable, e.g. by replacing them with sliders.

 

here's ow it could look like.

 

altenbach_0-1586102286470.png

 

altenbach_1-1586102383152.png

 

 

Message 8 of 8
(4,211 Views)