def build_phase_align_cc( fg, input0, input1,phase_avg_alpha=1e-5, ph_corr_type=1):
    #input two similar signals with a phase difference
    #returns two blocks outputting the signals phase aligned, 
    # also returns the block which outputs the average phase difference
    mult=gr.multiply_cc()
    conj=gr.conjugate_cc()
    c2arg=gr.complex_to_arg() #fft_size)
    mult2=gr.multiply_cc()
    conj2=gr.conjugate_cc()
    #degrees=180.0
    #ps=2.0*3.1415926535384626*degrees/360.0
    #phase_sh=gr.multiply_const_cc(complex(cos(ps),sin(ps))) #add this phase_shift block in between for testing
    phase_average=gr.single_pole_iir_filter_cc(phase_avg_alpha)
    fg.connect(input0,(mult,0))
    fg.connect(input1,conj,(mult,1))
    if ph_corr_type==0: #this version does not work very well
      mag=gr.complex_to_mag()
      div=gr.divide_cc() #output of this contains only phase information, magnitude is eliminated (mag==1.0)
      float_to_complex=gr.float_to_complex()
      fg.connect(mult,(div,0))
      fg.connect(mult,mag,float_to_complex,(div,1))
      fg.connect(div,phase_average,(mult2,0))
    elif ph_corr_type==1: #this version works OK, especially when both sources have amplitude 1.0 (use agc_cc for both before inputing)
      agc=gr.agc_cc(1e-5,1.0,1.0) #1e-3 #rate,reference,gain
      fg.connect(mult,phase_average,agc,(mult2,0)) #phase_average,
    elif ph_corr_type==2: #another way of doing this, this one is a bit noisy
      phasemod=gr.phase_modulator_fc(1.0)
      fg.connect(mult,c2arg,phasemod,phase_average,(mult2,0))
    fg.connect(input1,(mult2,1))
    #interleaver= gr.interleave(gr.sizeof_gr_complex)
    #fg.connect(dummy0,(interleaver,0))
    #fg.connect(mult2,(interleaver,1))
    #gr.hier_block.__init__(self, fg, di, interleaver)
    return input0,mult2,phase_average

