I used the example of two oscillators at the same frequency to simplify the problem. If you are talking about generating signals of frequency f and 2*f the principle is the same. You will not get ideal frequencies. There will be some error even using the same processor. The 2*f frequency will not be exactly twice the f frequency.

If you use my algorithm to generate sine waves you can see this effect. If you generate the first three Fourier terms of a square wave you will initially see a textbook result. Over a few seconds you will see something completely different because the frequency multiples are not exact even for the same processor and the same algorithm. The phases drift. I don't know how else to make the point.

Hi again,

Ok i think i see what you are trying to say here, and i think it is a good point. If the second wave error in time accumulates then it will show up as a phase shift. But that's if the second wave error accumulates.

Knowing this might happen, we can force synchronization cant we?

For example, keep a running time variable t (if needed) and use a cycle time tc:

y=sin(w*tc)+sin(2*w*tc)

We will usually start out with tc=0, and at the end of the cycle time tc set it back to zero:

tc=0

This means if the phase error over the first cycle is 1 part in 1 million then the phase error will be 1 part in 1 million for the second cycle as well.

We might want to keep a running time variable too though:

t=t+tc

just so we know where we are in real time.

Note this works with integer multiples, but some non integer multiples could be done too as long as they dont result in a cycle time that is too long.

But then again, doesnt the Due do (ha ha, "Due do", say it out loud, but only once) double floats? Does it use this for the trig functions too? I'd have to check, but that might mean we get a longer time period before we see significant phase shift (you could check into this if you like).

We would also have to check to see how the trig functions work for this processor. Some may use the modulus of the frequency so that we only operate on the difference between the actual argument and a multiple of 2*pi (ie principle angle).

Short table:

2*pi=>0

3*pi=>pi

4*pi=>0

5*pi=>pi

This would mean only the initial phase shift (which would be quite small) would be retained over any number of wave cycles.

Check this out and see what you think.

We could also try this numerically on the PC without using the Due just to see the numerical results.