import matplotlib.pyplot as plt
from sk_dsp_comm import digitalcom as dc
from scipy import signal
from numpy import array
hc = array([1.0, 0.1, -0.05, 0.15, 0.2, 0.05]) # impulse response spanning five symbols
x1,b1,IQ_data1 = dc.qam_bb(50000,1,'16qam')
x_out = dc.ofdm_tx(IQ_data1,32,64,0,True,0)
x1,b1,IQ_data1 = dc.qam_bb(50000,1,'16qam')
x_out = dc.ofdm_tx(IQ_data1,32,64,0,True,0)
c_out = signal.lfilter(hc,1,x_out) # Apply channel distortion
r_out = dc.cpx_awgn(c_out,100,64/32) # Es/N0 = 100 dB
z_out,H = dc.ofdm_rx(r_out,32,64,-1,True,0,alpha=0.95,ht=hc)
plt.plot(z_out[200:].real,z_out[200:].imag,'.')
plt.xlabel('In-Phase')
plt.ylabel('Quadrature')
plt.axis('equal')
plt.grid()
plt.show()
#
# Another example with noise using a 10 symbol cyclic prefix and channel estimation:
#
x_out = dc.ofdm_tx(IQ_data1,32,64,100,True,10)
c_out = signal.lfilter(hc,1,x_out) # Apply channel distortion
r_out = dc.cpx_awgn(c_out,25,64/32) # Es/N0 = 25 dB
z_out,H = dc.ofdm_rx(r_out,32,64,100,True,10,alpha=0.95,ht=hc);
plt.figure() # if channel estimation is turned on need this
plt.plot(z_out[-2000:].real,z_out[-2000:].imag,'.') # allow settling time
plt.xlabel('In-Phase')
plt.ylabel('Quadrature')
plt.axis('equal')
plt.grid()
plt.show()
