Best Python code snippet using avocado_python
test_orthogonality.py
Source:test_orthogonality.py  
1import numpy as np2import matplotlib.pyplot as plt3from scipy import linalg4# é忍¡æ¬çç®çæ¯çºäºå¤æ·ä¿¡èçæ£äº¤æ§5# ç¶ä¿¡èä¸åºç¾ä¸é£çºææ¯å
©ä¿¡èçé »çå·®ä¸çæ¼ k / T_symbol ( kçºæ´æ¸ãT_symbolçºä¸åsymbolçæå卿 )6# åå
§ç©ä¸çº0ï¼ä¸æ£äº¤7# æåä¹å¯ä»¥ç¼ç¾ä¿¡èçdelayï¼ä¸å½±é¿æ£äº¤æ§8# èä¸éæå¾éè¦çä¸é»ï¼çµ¦å®T_symbol(symbol 卿)æï¼æåæå¾å°åè¼æ³¢çé »ççº k / T_symbol , k = 1,2,3....9# è¥å樣ééçºTsï¼ä¸Ts * Nfft = T_symbol (ä¹å°±æ¯ä¸åsymbol 卿å
§å樣Nfftåé»)10# ååªæå好åNfftå颿£æååºåå
¶FFTç颿£é »èæææ£äº¤æ§ï¼å大æ¼Nfftæå°æ¼Nfftåé»å°±æ²ææ£äº¤æ§äº11Nfft = 16                      # åNfftç黿¸12T_symbol = 1.6                 # ä¸åsymbolç卿ï¼éä¹ä»£è¡¨å
¶ä»åè¼æ³¢çé »ççº( k / T_symbol )Hz , k = 1,2,3...13t = [0]*100014T = 0.002  # é£çºä¿¡èçéé15for i in range(len(t)):16    t[i] = T*i17x = [0]*len(t)18re_x = [0]*len(t)19Ts = T_symbol / Nfft            # 忍£å¨æä¸å¯çºå
¶ä»æ¸ï¼å¦åæåºç¾éæ£äº¤20t_sample = [0]*(int(2/Ts)+1)    # 總å
±æå樣(int(2/Ts)+1)åé»21for i in range(len(t_sample)):22    t_sample[i] = Ts*i23x_sample = [0]*len(t_sample)24re_x_sample = [0]*len(t_sample)25# å
±å樣(int(2/Ts)+1)åé»ï¼é¸åNfftåé»26f_index = [0]*Nfft27for i in range(len(f_index)):28    f_index[i] = i29x_matrix = [[0j]*6 for i in range(Nfft)]30x_matrix = np.matrix(x_matrix)31# å
ç«åºé£çºä¿¡è32for k in range(6):33    for i in range(len(t)):34        if k == 0:35            x[i] = np.exp(1j * 2*np.pi * t[i] / T_symbol)                   # é »ççº ( 1/T_symbol ) Hzãexponential ä¿¡èdelay 0ç§36            f = 137            delay = 038        elif k == 1:39            x[i] = np.exp(1j * 2*np.pi * 2 * t[i] / T_symbol)               # é »ççº ( 2/T_symbol ) Hzãexponential ä¿¡èdelay 0ç§40            f = 241            delay = 042        elif k == 2:43            x[i] = np.exp(1j * 2*np.pi * 3 * (t[i] - 0.1) / T_symbol)       # é »ççº ( 3/T_symbol ) Hzãexponential ä¿¡èdelay 0.1ç§44            f = 345            delay = 0.146        elif k == 3:47            x[i] = np.exp(1j * 2*np.pi * 4 * (t[i] - 0.7) / T_symbol)       # é »ççº ( 4/T_symbol ) Hzãexponential ä¿¡èdelay 0.7ç§48            f = 449            delay = 0.750        elif k == 4:51            x[i] = np.exp(1j * 2*np.pi * 3.5 * t[i] / T_symbol)             # é »ççº ( 3.5/T_symbol ) Hzãexponential ä¿¡èdelay 0ç§52            f = 3.553            delay = 054        elif k == 5:55            f1 = 456            delay1 = 0.357            f2 = 358            delay2 = 0.759            if t[i] <= 1.3:60                x[i] = np.exp(1j * 2*np.pi * 4 * (t[i] - 0.3) / T_symbol)   # é »ççº ( 4/T_symbol ) Hzãexponentialä¿¡èdelay 0.3ç§(ä¸é£çºä¿¡è)61            else:62                x[i] = np.exp(1j * 2*np.pi * 3 * (t[i] - 0.7) / T_symbol)63    for j in range(len(t)):64        re_x[j] = x[j].real65    plt.subplot(6, 2, 2*k + 1)66    if k == 5:67        plt.title(r'$when\/\/t<1.3\/\/cos(   \frac{{   j2\pi\cdot{0}\cdot (t-{1})   }}    {{  {2}  }}  ),\/\/else\/\/cos(   \frac{{   j2\pi\cdot{3}\cdot (t-{4})   }}    {{  {2}  }}  )$'.format(f1, delay1, T_symbol, f2, delay2))68    else:69        plt.title(r'$cos(   \frac{{   j2\pi\cdot  {0}  \cdot (t  -  {1} )   }}    {{  {2}  }}  )$'.format(f,delay,T_symbol))70    plt.plot(t, re_x ,linestyle = '--')71    plt.xlim(0,2)72# æ¥èç«åºå樣å¾çä¿¡è73for k in range(6):74    for i in range(len(t_sample)):75        # é6åexponential ä¿¡èä¸ï¼åªæå4åæäºç¸æ£äº¤76        if k == 0:77            x_sample[i] = np.exp(1j * 2*np.pi * t_sample[i] / T_symbol)                     # é »ççº ( 1/T_symbol ) Hzãexponential ä¿¡èdelay 0ç§78        elif k == 1:79            x_sample[i] = np.exp(1j * 2*np.pi * 2 * t_sample[i] / T_symbol)                 # é »ççº ( 2/T_symbol ) Hzãexponential ä¿¡èdelay 0ç§80        elif k == 2:81            x_sample[i] = np.exp(1j * 2*np.pi * 3 * (t_sample[i] - 0.1) / T_symbol)         # é »ççº ( 3/T_symbol ) Hzãexponential ä¿¡èdelay 0.1ç§82        elif k == 3:83            x_sample[i] = np.exp(1j * 2*np.pi * 4 * (t_sample[i] - 0.7) / T_symbol)         # é »ççº ( 4/T_symbol ) Hzãexponential ä¿¡èdelay 0.7ç§84        elif k == 4:85            x_sample[i] = np.exp(1j * 2*np.pi * 3.5 * t_sample[i] / T_symbol)               # é »ççº ( 3.5/T_symbol ) Hzãexponential ä¿¡èdelay 0ç§86        elif k == 5:87            if t_sample[i] <= 1.3:88                x_sample[i] = np.exp(1j * 2*np.pi * 4 * (t_sample[i] - 0.3) / T_symbol)     # é »ççº ( 4/T_symbol ) Hzãexponential ä¿¡èdelay 0ç§(ä¸é£çºä¿¡è)89            else:90                x_sample[i] = np.exp(1j * 2*np.pi * 3 * (t_sample[i] - 0.7) / T_symbol)91        if i < 16:92            x_matrix[i,k] = x_sample[i]93    for j in range(len(x_sample)):94        re_x_sample[j] = x_sample[j].real95    X = np.fft.fft(x_sample[0:Nfft]) #å¾(int(2/Ts)+1)å忍£é»ä¸ï¼é¸åNfftåé»ä¾åFFT96    for j in range(len(X)):97        X[j] = abs(X[j])98    plt.subplot(6, 2, 2*k+1)99    plt.stem(t_sample,re_x_sample)100    plt.ylabel('Re{x[n]}').set_rotation(0)101    ax = plt.gca()102    ax.yaxis.set_label_coords(-0.08, 0.9)  # ç¨ä¾è¨å®åº§æ¨è»¸å稱çä½ç½®103    plt.xlabel('t')104    ax.xaxis.set_label_coords(1.05, -0.025)  # ç¨ä¾è¨å®åº§æ¨è»¸å稱çä½ç½®105    plt.subplot(6, 2, 2*k+2)106    plt.stem(f_index,X)107    plt.ylabel('Re{X[k]}').set_rotation(0)108    ax = plt.gca()109    ax.yaxis.set_label_coords(-0.08,0.9) #ç¨ä¾è¨å®åº§æ¨è»¸å稱çä½ç½®110    plt.xlim(0,Nfft)111    plt.xticks(np.arange(0,Nfft,2))112ans = x_matrix.getH() * x_matrix / (T_symbol/Ts) #å¯è§å¯ans matrixä¾å¤æ·ä¿¡è鿝妿æ£äº¤æ§113print(ans)114# çµæè¡¨æåªæå4åä¿¡èäºç¸æ£äº¤...clock_sync.py
Source:clock_sync.py  
1import numpy as np2import cupy as cp3# import matplotlib.pyplot as plt4# By GuJi in WT&T, BUPT5def clock_sync(envelope, estimated_symbol_rate):6#     x = 1:1000000;7#     pwr = sin(x*2*pi*352.745/1000000+95.1534);8#     plot(pwr);9    envelope_normal = cp.asnumpy(envelope/cp.max(envelope))10    # fft_pwr = fft(envelope_normal);11    free_symbol_rate = estimated_symbol_rate12    loop_gain_k0 = free_symbol_rate*0.113    loop_gain_k1 = free_symbol_rate*0.0114    dll_dt_span = 0.115    t_symbol = 016    siglen = len(envelope_normal)17    clk_sample_pattern = np.zeros(siglen, dtype=np.bool)18    last_early_factor = 019    dll_symbol_rate = free_symbol_rate20    integral_dll_symbol_rate = 021    while True:22        t_symbol = t_symbol + 1/dll_symbol_rate23        if t_symbol+0.5/dll_symbol_rate>siglen-1:24            break25        t_early = t_symbol - dll_dt_span/dll_symbol_rate26        t_late = t_symbol + dll_dt_span/dll_symbol_rate27        late_factor = -envelope_normal[round(t_late)]+envelope_normal[round(t_early)]28#         d_error_factor = abs(late_factor)-abs(last_early_factor);29#         last_early_factor = late_factor;30        dll_symbol_rate = free_symbol_rate+loop_gain_k0*late_factor+integral_dll_symbol_rate31        # integral_dll_symbol_rate = integral_dll_symbol_rate + loop_gain_k1*late_factor;32        integral_dll_symbol_rate = integral_dll_symbol_rate + loop_gain_k1*(late_factor-integral_dll_symbol_rate)33        # dll_symbol_rate = dll_symbol_rate - loop_gain_k1*early_factor;34        # clk_sample_pattern(round(t_symbol)) = late_factor*10;35    36    loop_gain_k0 = free_symbol_rate*0.0137    loop_gain_k1 = free_symbol_rate*0.00138    39    while(True):40        t_symbol = t_symbol - 1/dll_symbol_rate41        if(t_symbol-0.5/dll_symbol_rate<0):42            break43        t_early = t_symbol + dll_dt_span/dll_symbol_rate44        t_late = t_symbol - dll_dt_span/dll_symbol_rate45        late_factor = -envelope_normal[round(t_late)]+envelope_normal[round(t_early)]46#         d_error_factor = abs(late_factor)-abs(last_early_factor);47#         last_early_factor = late_factor;48        dll_symbol_rate = free_symbol_rate+loop_gain_k0*late_factor+integral_dll_symbol_rate49        # integral_dll_symbol_rate = integral_dll_symbol_rate + loop_gain_k1*late_factor;50        integral_dll_symbol_rate = integral_dll_symbol_rate + loop_gain_k1*(late_factor-integral_dll_symbol_rate)51        # dll_symbol_rate = dll_symbol_rate - loop_gain_k1*early_factor;52        # clk_sample_pattern(round(t_symbol)) = late_factor*10;53    54    while(True):55        t_symbol = t_symbol + 1/dll_symbol_rate56        if(t_symbol+0.5/dll_symbol_rate>siglen-1):57            break58        t_early = t_symbol - dll_dt_span/dll_symbol_rate59        t_late = t_symbol + dll_dt_span/dll_symbol_rate60        late_factor = -envelope_normal[round(t_late)]+envelope_normal[round(t_early)]61#         d_error_factor = abs(late_factor)-abs(last_early_factor);62#         last_early_factor = late_factor;63        dll_symbol_rate = free_symbol_rate+loop_gain_k0*late_factor+integral_dll_symbol_rate64        # integral_dll_symbol_rate = integral_dll_symbol_rate + loop_gain_k1*late_factor;65        integral_dll_symbol_rate = integral_dll_symbol_rate + loop_gain_k1*(late_factor-integral_dll_symbol_rate)66        # dll_symbol_rate = dll_symbol_rate - loop_gain_k1*early_factor;67        clk_sample_pattern[round(t_symbol)] = 168    69    70    # plt.plot(envelope_normal)71    # plt.plot(clk_sample_pattern)72    # plt.show()...fmRRC.py
Source:fmRRC.py  
1#2# Comp Eng 3DY4 (Computer Systems Integration Project)3#4# Copyright by Nicola Nicolici5# Department of Electrical and Computer Engineering6# McMaster University7# Ontario, Canada8#910import numpy as np11import math1213def impulseResponseRootRaisedCosine(Fs, N_taps):1415	"""16	Root raised cosine (RRC) filter1718	Fs  		sampling rate at the output of the resampler in the RDS path19				sampling rate must be an integer multipler of 237520				this integer multiple is the number of samples per symbol2122	N_taps  	number of filter taps2324	"""2526	# duration for each symbol - should NOT be changed for RDS!27	T_symbol = 1/2375.02829	# roll-off factor (must be greater than 0 and smaller than 1)30	# for RDS a value in the range of 0.9 is a good trade-off between31	# the excess bandwidth and the size/duration of ripples in the time-domain32	beta = 0.903334	# the RRC inpulse response that will be computed in this function35	impulseResponseRRC = np.empty(N_taps)3637	for k in range(N_taps):38		t = float((k-N_taps/2))/Fs39		# we ignore the 1/T_symbol scale factor40		if t == 0.0: impulseResponseRRC[k] = 1.0 + beta*((4/math.pi)-1)41		elif t == -T_symbol/(4*beta) or t == T_symbol/(4*beta):42			impulseResponseRRC[k] = (beta/np.sqrt(2))*(((1+2/math.pi)* \43					(math.sin(math.pi/(4*beta)))) + ((1-2/math.pi)*(math.cos(math.pi/(4*beta)))))44		else: impulseResponseRRC[k] = (math.sin(math.pi*t*(1-beta)/T_symbol) +  \45					4*beta*(t/T_symbol)*math.cos(math.pi*t*(1+beta)/T_symbol))/ \46					(math.pi*t*(1-(4*beta*t/T_symbol)*(4*beta*t/T_symbol))/T_symbol)4748	# returns the RRC impulse response to be used by convolution49	return impulseResponseRRC5051if __name__ == "__main__":52
...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
