LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Sine Waves

Solved!
Go to solution

Hey!! I am new to LabView and I am adding two sine waves. When adding two waves of the same amplitutde and freq. with a phase difference of 180 they should cancel each other out but that's not happening. Correct me if my concept is wrong and please point out the issue.

Download All
0 Kudos
Message 1 of 8
(1,199 Views)

It's floating point rounding errors that build up.

 

Your signals have an amplitude of 8 but your "combined signal" output has an amplitude of around 1e-14, which is about a quadrillion times smaller.

0 Kudos
Message 2 of 8
(1,166 Views)

How Can I fix it then?

0 Kudos
Message 3 of 8
(1,163 Views)

You could try a magnitude of -8 instead of an offset of 180 degrees.

 

You could put in code to treat any number under a certain threshold as zero.

 

If neither of those is acceptable, can you tell us what this is for?  It looks like a programming exercise or homework assignment, not a task for a job.

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

it is an exercise..is there any other solution rather than just treating it as 0? 

Also negative 8 yields the same result but at negative 10 it fluctuates between 0 and a smaller value.

 

0 Kudos
Message 5 of 8
(1,146 Views)
Solution
Accepted by topic author bilalskd

I'd just set the chart's amplitude to a fixed value (say, +/- 20). The smaller chart's value of 1.5E-14 means literally any non-perfect math will show up as SOMETHING, which I doubt is what you want.

 

In other words, your Signal A and Signal B values are about 1,000,000,000,000,000x (yes, one quadrillion, 15 zeros) as large as your Combined Signal graph. Do you really care about values that small?

Message 6 of 8
(1,141 Views)
Solution
Accepted by topic author bilalskd

If you're doing a programming exercise, dealing with floating point inaccuracy is a part of programming.  If you ever do anything with fractional values that don't have a denominator with a power of 2 (1/2, 3/8, 9/32nds, etc.) then this will come up.  

 

This evaluates to False, for example:

Kyle97330_0-1690916319167.png

Since quite a lot of Sine values evaluate to irrational numbers, you're not going to be able to avoid it normally.

 

It does look like your output is entirely graphical.  You could consider scaling the graphs manually instead of automatically, so that the output would appear to be zero on the graph even though the numbers aren't zero exactly mathematically.

Message 7 of 8
(1,134 Views)

Thank You to both of you for your help. I have manually scaled the graph and the soulution is satisfactory for me.

0 Kudos
Message 8 of 8
(1,121 Views)