Phase difference calculation for non divisible sample rate to frequency

I am learning DSP and I am trying to simulate a simple phase difference calculator between two sinusoidal signals using GNU radio.

My flowchart looks like this: As can be seen on the chart, one of the signals is using a delay block (controlled by the "delay sig" range GUI).

Other interesting points are:

1. fft_width variable: Calculated by an expression - int(freq/20)
2. freq variable: Controlled by a GUI range with steps of 1.2KHz. Min 1.2KHz, Max 9.6KHz
3. The skip head and Keep M in N blocks - used together to extract only the FFT bin in interest. To do so the skip head calculates the first N blocks to be skipped via this expression: int((samp_rate/fft_width))+2 . Idea taken from this video: https://youtu.be/GJKbD--MsLM?t=326

The problem:

This flowchart works when the samp_rate and freq are divisible - say samp_rate=10k and freq = 1k. However, for more of a real world scenario I have chosen variables that have lower ratio and are not divisible. In particular: samp_rate=11k and freq=1.2k. As a result of this the phase calculation fluctuates between 180 degree difference - for example 3.42 and 3.42-pi.

The question:

How do I make this flowchart work when the samp_rate and freq are not divisible? Furthermore how do I make it work for samp_rate of 11k, but different frequencies (chosen by the freq range GUI)?

What I tried:

Not much unfortunately, as I cannot find much information about this problem. That said, I read somewhere that clock synchronization via a PLL or Clock Recovery MM might help, but I do not know how to apply the relevant GNU radio blocks to this flowchart. Furthermore, if PLL is used would it not change the phase difference between the signals when trying to synchronize them?

EDIT: I tried putting a PLL ref output block between the throttle and FFT blocks: For the parameters I used:

loop bandwidth: pi/200 (documentation states it should be either that or 2*pi/100)

min_freq & max_freq: (2*pi*1.1e3)/samp_rate (documentation states it needs to be in radians per sample)

My goal was to try to make it work for 1.2k frequency, but unfortunately I still face the same problems. How can I fix it?

• This is a very complex approach to determine the phase difference between two tones— was there just for educational purposes in using those functional blocks or is your goal to determine phase error? Mar 10 '20 at 15:19
• My end goal is to replace the sinusoidal blocks with pseudo noise and eventually work my way up to simulate rf ranging. Otherwise you are correct it is all for educational purposes
– Slav
Mar 10 '20 at 15:51
• For that purpose consider doing a circular cross correlation which you can do efficiently with FFTs as the IFFT(FFT(a)FFT(b)*): the cross correlation is the inverse FFT of the complex conjugate multiplication of the FFT of the two time domain sequences. Mar 10 '20 at 15:55
• Wow! I am still learning DSP. Would you mind expanding your answer and/or giving some examples? Thanks!
– Slav
Mar 10 '20 at 16:28
• are you using any simulation platform beyond GNU radio such as MATLAB, Octave or Python Scipy/Numpy? Mar 10 '20 at 16:31