def square(x_arr, fill_f V_maximum):
dim_x = np.shape(x_arr)[0]
V = np.zeros(dim_x)
V[0:int(dim_x*fill_f)] = V_maximum
return V
dim = 256 # number sampling points in real space of for the periodic potential
x=np.linspace(-a/2,a/2,dim) # x points of unit cell in real space
dx = x[1]-x[0] # spatial sampling
V_max = 5.0 # potential amplitude
fill_fraction = 0.5 # fill fraction of the potential
V = square(x,fill_fraction,V_max)V_fft = np.fft.fft(V,norm='forward') # compute full fftV_fft = np.fft.fft(V,norm='forward') # compute full fft
V_fft_shift = np.fft.fftshift(V_fft) # shift fftV_fft = np.fft.fft(V,norm='forward') # compute full fft
V_fft_shift = np.fft.fftshift(V_fft) # shift fft
k_fft = np.fft.fftshift(np.fft.fftfreq(len(V),dx*1e9)) # compute spatial fft frequenciesV_fft_r = np.fft.rfft(V,norm='forward') # compute fft
k_fft_r = np.fft.rfftfreq(len(V),dx*1e9) # compute fft spatial frequencies