08-01-2023 12:14 PM - edited 08-01-2023 12:38 PM
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.
Solved! Go to Solution.
08-01-2023 01:22 PM
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.
08-01-2023 01:29 PM
How Can I fix it then?
08-01-2023 01:34 PM
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.
08-01-2023 01:49 PM
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.
08-01-2023 01:54 PM
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?
08-01-2023 02:02 PM
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:
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.
08-01-2023 02:25 PM
Thank You to both of you for your help. I have manually scaled the graph and the soulution is satisfactory for me.