@@ -46,46 +46,47 @@ def snr_est_test(model, snr_target, h, Nw):
46
46
47
47
Nc = model .Nc
48
48
Pc = np .array (model .pilot_gain * model .P )
49
- print (np .sum (Pc ))
50
49
51
50
# matrix of transmitted pilots for time window
52
- # time steps across rows, carrioer across cols
51
+ # time steps across rows, carrier across cols
53
52
Pcn = np .zeros ((Nw ,Nc ), dtype = np .complex64 )
54
53
for n in np .arange (Nw ):
55
54
Pcn [n ,:]= Pc
56
55
57
56
# sequence of noise samples
58
- Es = np .dot (Pc , np . conj ( Pc )) / Nc # energy per symbol
57
+ Es = np .sum (Pc ** 2 ) / Nc # energy per symbol
59
58
No = Es / snr_target # noise per symbol
60
59
sigma = np .sqrt (No )/ (2 ** 0.5 )
61
60
n = sigma * (np .random .normal (size = (Nw ,Nc )) + 1j * np .random .normal (size = (Nw ,Nc )))
62
-
61
+ print ( Es , No , sigma , np . var ( n ), np . var ( Pcn ), np . sum ( np . abs ( Pcn ) ** 2 ))
63
62
# matrix of received pilots plus noise samples
64
63
Pcn_hat = h * Pcn + n
65
64
66
65
# phase corrected received pilots
67
66
Rcn_hat = np .abs (h )* Pcn + n
68
67
69
- # remove pilot modulation to map to one point
70
- Z = Rcn_hat / Pcn
68
+ # calculate S1 two ways to test expression
69
+
70
+ S1 = np .sum (np .abs (Pcn_hat )** 2 )
71
+ S1_first = np .sum (np .abs (h * Pcn )** 2 )
72
+ S1_second = np .sum (2 * (h * Pcn * n ).real )
73
+ #S1_second = np.sum(h*Pcn*np.conj(n) + np.conj(h*Pcn)*n)
74
+ S1_third = np .sum (np .abs (n )** 2 )
75
+ S1_sum = S1_first + S1_second + S1_third
76
+ print (f"S1_first: { S1_first :5.2f} S1_second: { S1_second :5.2f} S1_third: { S1_third :5.2f} " )
77
+ print (f"S1: { S1 :5.2f} S1_sum: { S1_sum :5.2f} " )
71
78
72
79
# calculate SNR est
73
- S1 = np .abs (np .sum (Z ))
74
- S2 = np .sum (Z .imag * np .conj (Z .imag ))
75
- print (np .sum (Z ))
76
- print (f"S1: { S1 :f} S2: { S2 } " )
80
+ S2 = np .sum (np .abs (Rcn_hat .imag )** 2 )
81
+ print (S1 , S2 )
82
+ #print(f"S1: {S1:f} S2: {S2:f}")
77
83
78
- snr_est = S1 / (2 * S2 )
84
+ snr_est = S1 / (2 * S2 ) - 1
79
85
80
86
# actual snr as check, should be same as snr_target
81
- snr_check = np .sum (Pcn * np .conj ( Pcn ))/ np .sum (n * np .conj (n ))
82
- print (f"S: { np .sum (Pcn * np .conj ( Pcn )). real :f} N: { np .sum (n * np .conj (n )). real } " )
87
+ snr_check = np .sum (np .abs ( h * Pcn )** 2 )/ np .sum (np .abs (n )** 2 )
88
+ print (f"S: { np .sum (np .abs ( h * Pcn )** 2 ) :f} N: { np .sum (np .abs (n )** 2 ) } " )
83
89
print (f"snr:target { snr_target :5.2f} snr_check: { snr_check .real :5.2f} snr_est: { snr_est :5.2f} " )
84
- plt .figure (1 )
85
- plt .plot (Rcn_hat .real , Rcn_hat .imag ,'b+' )
86
- plt .plot (Z .real , Z .imag ,'r+' )
87
- plt .show ()
88
- quit ()
89
90
90
91
return snr_est ,snr_check
91
92
@@ -99,7 +100,7 @@ def snr_est_test(model, snr_target, h, Nw):
99
100
def single (snrdB , h , Nw ):
100
101
snr_est , snr_check = snr_est_test (model , 10 ** (snrdB / 10 ), h , Nw )
101
102
#print(f"snrdB: {snrdB:5.2f} snrdB_check: {10*np.log10(snr_check):5.2f} snrdB_est: {10*np.log10(snr_est):5.2f}")
102
- print (f"snrdB: { snrdB :5.2f} snrdB_check: { 10 * np .log10 (snr_check ):5.2f} " )
103
+ print (f"snrdB: { snrdB :5.2f} snrdB_check: { 10 * np .log10 (snr_check ):5.2f} snrdB_est: { 10 * np . log10 ( snr_est ):5.2f } " )
103
104
104
105
# run over a sequence of timesteps
105
106
def sequence (Ntimesteps , EsNodB , h ):
@@ -161,8 +162,11 @@ def sweep(Ntimesteps, h):
161
162
if len (args .h_file ):
162
163
h = np .fromfile (args .h_file ,dtype = np .float32 )
163
164
h = h .reshape ((- 1 ,model .Nc ))
165
+ print (h .shape )
164
166
# sample once every modem frame
165
- h = h [:model .Ns + 1 :]
167
+ h = h [::model .Ns + 1 ,:]
168
+ h = h [:Nw ,:]
169
+ print (h .shape )
166
170
else :
167
171
h = 0.5 * np .ones ((Nw ,model .Nc ))
168
172
print (h .shape )
0 commit comments