# Is D flip flop equivalent to frequency mixer (difference frequency) for square waves?

I was trying to make a frequency mixer (only difference frequency) for two square waves (PWM1, PWM2, both 0.5-4KHz range) using ONLY Arduino due.

I'm new to signal processing, and the only way I can think of making a differential frequency is purely mathematical,and only for sin waves:

$$sin(A-B)=sinAcosB-cosAsinB$$

The cos term is a problem because it involves 90 degree phase shift, so I cannot just use logical operators to express the function.

However during Googling I saw a statement that D flip flop can be used to produce only the difference term in frequency mixing.

That is, if I understand it correctly, attaching an interrupt to the rising edge of PWM1, in the ISP read the PWM2 value and write it to the output pin.

It make sense as the closer the frequencies of PWM1 and PWM2 is, the smaller the frequency of the output wave. However it seems too good to be true and I cannot figure out how this is mathematically equivalent to the difference part of the product of the two signals.

Will I get better accuracy if I use a real D flip flop ?

Clarification:

For 'frequency mixer' I mean the product of two signals. $$2cosAcosB=cos(A+B)+cos(A-B)$$ For 'the difference part of frequency mixer' I mean only the term with differential frequency (A-B).

• Give the Google a try again using the term "CORDIC" and see if that helps. – CapnJJ Jun 18 '18 at 21:27
• What is frequency mixer in your terms? What would be the input signals and what is the output? – Eugene Sh. Jun 18 '18 at 21:27
• @EugeneSh. Both PWM1 and PWM2 is in the range of 0.5-4 KHz. – 7E10FC9A Jun 18 '18 at 21:35
• I don't think it will be very accurate because the interrupt latency is not constant. But if the frequencies of the PWM signals are very small, then perhaps... But are you thinking about this the correct way? What are you really trying to achieve? If you make the PWM signals yourself, then surely you know their frequencies and can calculate the difference....? – PkP Jun 18 '18 at 21:35
• @PkP PWM1 and PWM2 are from not-so-stable external clock, the output need to be phase correct. – 7E10FC9A Jun 18 '18 at 21:37