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: GNU radio flowchart 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?

Thank you for your time!

EDIT: I tried putting a PLL ref output block between the throttle and FFT blocks: PLL ref out block flowchart

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?

  • $\begingroup$ 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? $\endgroup$ Mar 10, 2020 at 15:19
  • $\begingroup$ 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 $\endgroup$
    – Slav
    Mar 10, 2020 at 15:51
  • $\begingroup$ 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. $\endgroup$ Mar 10, 2020 at 15:55
  • $\begingroup$ Wow! I am still learning DSP. Would you mind expanding your answer and/or giving some examples? Thanks! $\endgroup$
    – Slav
    Mar 10, 2020 at 16:28
  • $\begingroup$ are you using any simulation platform beyond GNU radio such as MATLAB, Octave or Python Scipy/Numpy? $\endgroup$ Mar 10, 2020 at 16:31

1 Answer 1


Re-reference your FFT phase measurement reference point to the center of your data window by doing an FFTShift (N/2 vector rotate) before the FFT. That moves the portion of data where there is a circular discontinuity (due to non-integer periodicity) away from the phase reference point of a typical FFT.

  • 1
    $\begingroup$ I am sorry I did not understand. How would I use the PLL or Clock Recovery MM to implement this? Can you show an example flowchart? Thanks! $\endgroup$
    – Slav
    Mar 10, 2020 at 11:32
  • $\begingroup$ Take a look at the EDIT in my original post please. $\endgroup$
    – Slav
    Mar 10, 2020 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.