-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathall.patch
287 lines (275 loc) · 10.5 KB
/
all.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
--- wsjtx/lib/wsprd/wsprd.c 2023-11-08 12:48:12.718133943 -0500
+++ wsjtx/lib/wsprd/wsprd.c 2023-11-25 21:51:49.416349709 -0500
@@ -35,6 +35,7 @@
#include <stdint.h>
#include <time.h>
#include <fftw3.h>
+#include <stdbool.h>
#include "fano.h"
#include "jelinek.h"
@@ -537,11 +538,131 @@
}
return;
}
+
+/******************************************************************************
+ Calculate the doppler spread (w50) from g (estimated channel gain data, c(t))
+ *******************************************************************************/
+float dopspread(float *ci, float *cq, char *callsign)
+{
+ int i, j;
+ int nsym = 162;
+ int nspersym = 256;
+ int points = nsym * nspersym;
+ fftwf_plan plan;
+ fftwf_complex *g, *g_fft;
+ float *roi;
+ float df = 375.0/points;
+ float max_power = 0, total_power = 0, curr_power = 0;
+ int roi_points = 0;
+ int right_noise_points = 0;
+ int left_noise_points = 0;
+ float left_noise = 0, right_noise = 0, noise, freq;
+ float x25 = -1, x75 = -1, prev_power;
+ float doppler_spread;
+
+ /* take an FFT of c(t) from subtract_signal2() */
+ g = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * points);
+ for (i = 0; i < points; i++) {
+ g[i][0] = ci[i];
+ g[i][1] = cq[i];
+ }
+ g_fft = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * points);
+ plan = fftwf_plan_dft_1d(points, g, g_fft, FFTW_FORWARD, PATIENCE);
+ fftwf_execute(plan);
+
+ for (i = (-187.5 / df); i < (187.5 / df); i++) {
+ j = i;
+ if (j < 0) {
+ j = i + points;
+ }
+ }
+
+ /* pull out the region of interest (-4 to 4 Hz), shift the zero freq
+ * component to the center of the array, convert to power, and find the
+ * maximum power between -1 and 1 Hz */
+ roi = fftwf_malloc(sizeof(float) * ((8.0 / df) + 0.5));
+ roi_points = 0;
+ for (i = (-4.0 / df); i < (4.0 / df); i++) {
+ j = i;
+ if (j < 0) {
+ j = i + points;
+ }
+ roi[roi_points] = (g_fft[j][0] * g_fft[j][0]) + (g_fft[j][1] * g_fft[j][1]);
+ if ((i > (-1.0 / df)) && (i < 1.0 / df)) {
+ if (roi[roi_points] > max_power) {
+ max_power = roi[roi_points];
+ }
+ }
+ roi_points++;
+ }
+
+ /* scale the region of interest by the max power and find the average
+ * noise in the -4 and -2 Hz and 2 and 4 Hz regions */
+ for (i = 0; i < roi_points; i++) {
+ roi[i] = roi[i] / max_power;
+ freq = (i * df) - 4;
+ if ((freq > -4.0) && (freq < -2.0)) {
+ left_noise = left_noise + roi[i];
+ left_noise_points++;
+ } else if ((freq > 2.0) && (freq < 4.0)) {
+ right_noise = right_noise + roi[i];
+ right_noise_points++;
+ }
+ }
+ left_noise = left_noise / left_noise_points;
+ right_noise = right_noise / right_noise_points;
+
+ /* subtract out the noise using whichever noise side is lower and calculate
+ * the total power between -1 and 1 Hz */
+ noise = (left_noise > right_noise) ? right_noise : left_noise;
+ for (i = 0; i < roi_points; i++) {
+ roi[i] = roi[i] - noise;
+ freq = (i * df) - 4;
+ if ((freq > -1.0) && (freq < 1.0)) {
+ total_power += roi[i];
+ }
+ }
+
+ /* save the ROI
+ char filename[64];
+ sprintf(filename, "%s_roi.csv", callsign);
+ FILE *fp = fopen(filename, "w");
+ for (i = 0; i < roi_points; i++) {
+ fprintf(fp, "%f,%f\n", (i * df) - 4, roi[i]);
+ }
+ fclose(fp); */
+
+ /* find where the power reaches 25% of the total and 75% */
+ prev_power = 0.0;
+ for (i = ((-1 + 4) / df); i < ((1 + 4) / df); i++) {
+ curr_power += roi[i];
+ if ((curr_power >= (0.25 * total_power)) && (x25 < 0)) {
+ /* account for overshoot and perform a linear estimate */
+ x25 = i - (curr_power - (0.25 * total_power)) / (curr_power - prev_power);
+ }
+ if ((curr_power >=(0.75 * total_power)) && (x75 < 0)) {
+ x75 = i - (curr_power - (0.75 * total_power)) / (curr_power - prev_power);
+ }
+ prev_power = curr_power;
+ }
+
+ /* Doppler spread is the frequency difference between those points
+ using 1 + sqrt(diff) keeps the small values from fluctuating too widely */
+ doppler_spread = sqrt(1.0 + pow((x75 - x25), 2)) * df;
+
+ fftwf_destroy_plan(plan);
+ fftwf_free(g);
+ fftwf_free(g_fft);
+ fftwf_free(roi);
+
+ return doppler_spread;
+}
+
/******************************************************************************
Subtract the coherent component of a signal
*******************************************************************************/
-void subtract_signal2(float *id, float *qd, long np,
- float f0, int shift0, float drift0, unsigned char* channel_symbols)
+float subtract_signal2(float *id, float *qd, long np,
+ float f0, int shift0, float drift0, unsigned char* channel_symbols, char *callsign)
{
float dt=1.0/375.0, df=375.0/256.0;
float pi=4.*atan(1.0), twopidt, phi=0, dphi, cs;
@@ -550,7 +671,8 @@
int nc2=45000;
float *refi, *refq, *ci, *cq, *cfi, *cfq;
-
+ float doppler_spread;
+
refi=calloc(nc2,sizeof(float));
refq=calloc(nc2,sizeof(float));
ci=calloc(nc2,sizeof(float));
@@ -615,6 +737,8 @@
}
}
+ doppler_spread = dopspread(ci, cq, callsign);
+
// LPF
for (i=nfilt/2; i<45000-nfilt/2; i++) {
cfi[i]=0.0; cfq[i]=0.0;
@@ -651,7 +775,7 @@
free(cfi);
free(cfq);
- return;
+ return doppler_spread;
}
unsigned long writec2file(char *c2filename, int trmin, double freq
@@ -725,6 +849,7 @@
printf(" -v verbose mode (shows dupes)\n");
printf(" -w wideband mode - decode signals within +/- 150 Hz of center\n");
printf(" -z x (x is fano metric table bias, default is 0.45)\n");
+ printf(" -n no drift, does not attempt to follow a drifting frequency\n");
}
//***************************************************************************
@@ -764,6 +889,7 @@
clock_t t0,t00;
float tfano=0.0,treadwav=0.0,tcandidates=0.0,tsync0=0.0;
float tsync1=0.0,tsync2=0.0,tosd=0.0,ttotal=0.0;
+ float doppler_spread=0.0;
struct cand { float freq; float snr; int shift; float drift; float sync; };
struct cand candidates[200];
@@ -771,7 +897,7 @@
struct result { char date[7]; char time[5]; float sync; float snr;
float dt; double freq; char message[23]; float drift;
unsigned int cycles; int jitter; int blocksize; unsigned int metric;
- int nhardmin; int ipass; int decodetype;};
+ int nhardmin; int ipass; int decodetype; float doppler_spread; };
struct result decodes[50];
char *hashtab;
@@ -813,11 +939,12 @@
#include "./metric_tables.c"
int mettab[2][256];
+ bool nodrift=false;
idat=calloc(maxpts,sizeof(float));
qdat=calloc(maxpts,sizeof(float));
- while ( (c = getopt(argc, argv, "a:BcC:de:f:HJmo:qstwvz:")) !=-1 ) {
+ while ( (c = getopt(argc, argv, "a:BcC:de:f:HJmno:qstwvz:")) !=-1 ) {
switch (c) {
case 'a':
data_dir = optarg;
@@ -850,6 +977,9 @@
case 'm': //15-minute wspr mode
wspr_type = 15;
break;
+ case 'n': // no drift
+ nodrift = true;
+ break;
case 'o': //use ordered-statistics-decoder
ndepth=(int) strtol(optarg,NULL,10);
break;
@@ -1006,6 +1136,9 @@
maxdrift=0; // no drift for smaller frequency estimator variance
minsync2=0.10;
}
+ if(nodrift) {
+ maxdrift=0;
+ }
ndecodes_pass=0; // still needed?
for (i=0; i<nffts; i++) {
@@ -1426,10 +1559,11 @@
// Unpack the decoded message, update the hashtable, apply
// sanity checks on grid and power, and return
// call_loc_pow string and also callsign (for de-duping).
+ // subtract_signal2 also calculates the Doppler spread for the signal
noprint=unpk_(message,hashtab,loctab,call_loc_pow,callsign);
if( subtraction && !noprint ) {
if( get_wspr_channel_symbols(call_loc_pow, hashtab, loctab, channel_symbols) ) {
- subtract_signal2(idat, qdat, npoints, f1, shift1, drift1, channel_symbols);
+ doppler_spread = subtract_signal2(idat, qdat, npoints, f1, shift1, drift1, channel_symbols, callsign);
if(!osd_decode) nhardmin=count_hard_errors(symbols,channel_symbols);
} else {
break;
@@ -1473,6 +1607,7 @@
decodes[uniques-1].nhardmin=nhardmin;
decodes[uniques-1].ipass=ipass;
decodes[uniques-1].decodetype=osd_decode;
+ decodes[uniques-1].doppler_spread=doppler_spread;
}
}
}
@@ -1504,13 +1639,13 @@
decodes[i].time, decodes[i].snr,decodes[i].dt, decodes[i].freq,
(int)decodes[i].drift, decodes[i].message);
fprintf(fall_wspr,
- "%6s %4s %3.0f %5.2f %11.7f %-22s %2d %5.2f %2d %2d %4d %2d %3d %5u %5d\n",
+ "%6s %4s %3.0f %5.2f %11.7f %-22s %2d %5.2f %2d %2d %4d %2d %3d %5u %5d %6.3f\n",
decodes[i].date, decodes[i].time, decodes[i].snr,
decodes[i].dt, decodes[i].freq, decodes[i].message,
(int)decodes[i].drift, decodes[i].sync,
decodes[i].ipass+1,decodes[i].blocksize,decodes[i].jitter,
decodes[i].decodetype,decodes[i].nhardmin,decodes[i].cycles/81,
- decodes[i].metric);
+ decodes[i].metric, decodes[i].doppler_spread);
fprintf(fwsprd,
"%6s %4s %3d %3.0f %4.1f %10.6f %-22s %2d %5u %4d\n",
decodes[i].date, decodes[i].time, (int)(10*decodes[i].sync),
--- wsjtx/lib/fst4_decode.f90 2023-11-25 21:51:35.906349879 -0500
+++ wsjtx/lib/fst4_decode.f90 2023-11-25 21:51:20.415211696 -0500
@@ -988,13 +988,13 @@
do i=-ia,ia !Find freq range that has 50% of signal power
sum2=sum2 + ss(i)-avg
if(sum2.ge.0.25*sum1 .and. xi1.eq.-999.0) then
- xi1=i - 1 + (sum2-0.25*sum1)/(sum2-sum2z)
+ xi1=i - 1 + (0.25*sum1-sum2)/(sum2-sum2z)
endif
if(sum2.ge.0.50*sum1 .and. xi2.eq.-999.0) then
- xi2=i - 1 + (sum2-0.50*sum1)/(sum2-sum2z)
+ xi2=i - 1 + (0.50*sum1-sum2)/(sum2-sum2z)
endif
if(sum2.ge.0.75*sum1) then
- xi3=i - 1 + (sum2-0.75*sum1)/(sum2-sum2z)
+ xi3=i - 1 + (0.75*sum1-sum2)/(sum2-sum2z)
exit
endif
sum2z=sum2