<jupyter_start><jupyter_text>The I and Q components are related asI = A cos(Φ)Q = A sin(Φ)	From this, the signal magnitude A and phasen angle Φ can be calculated as$A^2= I^2+Q^2$Φ=arctan(Q/I)<jupyter_code>from scipy.fftpack import fft, ifft
import numpy as np
from scipy.signal import chirp


t = np.linspace(0, 10, 5001)
# w = chirp(t, f0=100, f1=150, t1=10, method='linear')
# w2 = chirp(t, f0=100, f1=150, t1=10, phi=90,method='linear')
n= 7 # 1/n *pi  initial phase


s_sine= np.sin(50.0 * 2.0*np.pi*t)          #sin
s_cosine=np.sin(50.0 * 2.0*np.pi*t+np.pi/2)   #cosin  pi*n nust positive


# r = np.sin(50.0 * 2.0*np.pi*t)
r2 = np.sin(50.0 * 2.0*np.pi*t+np.pi/n)  #receive signal


qua_phase = r2*s_sine    # receive signal multiply sin signal  Quadrature phase
in_phase=  r2*s_cosine    # receive signal multiply cosin signal in phase

plt.plot(t[:50],in_phase[:50],'r')
plt.plot(t[:50],qua_phase[:50],'b')
plt.grid()
plt.show()

fft_signal=fft(r2)
fft_in_phase = fft(in_phase)  #in phase
fft_qua_phase= fft(qua_phase)  #quadrature phase

# 
# print('receive  signal :\n',fft_signal[:2],'\n')

# print('In phase :\n',fft_in_phase[:2],'\n')

# print('Quadrature phase :\n',fft_qua_phase[:2])

initial_phase=np.real(np.arctan(fft_qua_phase[0]/fft_in_phase[0])/np.pi)
initial_phase =1/(0.5-initial_phase)

print('\n Initial Phase was:1/%.f'%initial_phase, '*pi')
print(np.arctan(1.768/1.768)/np.pi, '*pi')<jupyter_output>0.25 *pi<jupyter_text>Φ=arctan(Q/I)<jupyter_code>print('Phase was:',np.real(np.arctan(fft_qua_phase[0]/fft_in_phase[0])/np.pi), '*pi')
print('Phase was:%.3f'%np.real(np.arctan(fft_qua_phase[0]/fft_in_phase[0])/np.pi), '*pi')
#there is one problem that is phase must be positive

from scipy.fftpack import fft, ifft
import numpy as np
from scipy.signal import chirp


t = np.linspace(0, 10, 5001)
# w = chirp(t, f0=100, f1=150, t1=10, method='linear')
# w2 = chirp(t, f0=100, f1=150, t1=10, phi=90,method='linear')
n= 4 # 1/n *pi  initial phase


# s_sine= np.sin(50.0 * 2.0*np.pi*t)          #sin
# s_cosine=np.sin(50.0 * 2.0*np.pi*t+np.pi/2)   #cosin 
s_sine = chirp(t, f0=100, f1=150, t1=10, method='linear')
s_cosine=chirp(t, f0=100, f1=150, t1=10, phi=90,method='linear')
# r = np.sin(50.0 * 2.0*np.pi*t)
# r2 = np.sin(50.0 * 2.0*np.pi*t+np.pi/n)  #receive signal
r2 = chirp(t, f0=100, f1=150, t1=10, phi=180/n,method='linear')

qua_phase = r2*s_sine    # receive signal multiply sin signal  Quadrature phase
in_phase=  r2*s_cosine    # receive signal multiply cosin signal in phase

plt.plot(t[:50],in_phase[:50],'r')
plt.plot(t[:50],qua_phase[:50],'b')
plt.grid()
plt.show()

fft_signal=fft(r2)
fft_in_phase = fft(in_phase)  #in phase
fft_qua_phase= fft(qua_phase)  #quadrature phase

# 
# print('receive  signal :\n',fft_signal[:2],'\n')

# print('In phase :\n',fft_in_phase[:2],'\n')

# print('Quadrature phase :\n',fft_qua_phase[:2])

initial_phase=np.real(np.arctan(fft_qua_phase[0]/fft_in_phase[0])/np.pi)
initial_phase =1/(0.5-initial_phase)

print('\n Initial Phase was:1/%.1f'%initial_phase, '*pi')
from scipy.fftpack import fft, ifft
import numpy as np
from scipy.signal import chirp


t = np.linspace(0, 10, 5001)
# w = chirp(t, f0=100, f1=150, t1=10, method='linear')
# w2 = chirp(t, f0=100, f1=150, t1=10, phi=90,method='linear')
n= -5# 1/n *pi  initial phase


s_sine= np.sin(50.0 * 2.0*np.pi*t)          #sin
s_cosine=np.sin(50.0 * 2.0*np.pi*t+np.pi/2)   #cosin  pi*n nust positive
plt.plot(t[:50],s_sine[:50],'g')
plt.plot(t[:50],s_cosine[:50],'b')

# r = np.sin(50.0 * 2.0*np.pi*t)
r2 = np.sin(50.0 * 2.0*np.pi*t+np.pi/n)  #receive signal


qua_phase = r2*s_sine    # receive signal multiply sin signal  Quadrature phase
in_phase=  r2*s_cosine    # receive signal multiply cosin signal in phase

# plt.plot(t[:50],in_phase[:50],'r')
# plt.plot(t[:50],qua_phase[:50],'b')
plt.grid()
plt.show()

fft_signal=fft(r2)
fft_in_phase = fft(in_phase)  #in phase
fft_qua_phase= fft(qua_phase)  #quadrature phase


# print('The phase is:',get_phase,1/get_phase)
initial_phase=np.real(np.arctan(fft_qua_phase[0]/fft_in_phase[0])/np.pi)
if initial_phase >0 :
    initial_phase =0.5-initial_phase
    print('initial_phase is:%.3f*pi'%initial_phase)
else:
    initial_phase =-0.5-initial_phase
    print('initial_phase is:%.3f*pi'%initial_phase)
        
# initial_phase =1/(0.5-initial_phase)
# # initial_phase =1/(-0.5-initial_phase)

# print('\n Initial Phase was:1/%.f'%initial_phase, '*pi')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1886919452546556, 'fraction_numerical': 0.06798294817141574, 'mean_word_length': 4.959893048128342, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '416853', 'license': 'MIT', 'n_tokens_mistral': 2254, 'n_tokens_neox': 2077, 'n_words': 371, 'path': 'code/fft/IQ processing.ipynb', 'repo_name': 'xing710/ModSimPy', 'size': '4457'}