
The idea of processing the Loran-C signal here is very different 
to the common third zero crossing tracker.

It determines pulse positions by convolution with the complete pulse shape.
This is known as "matched filter" and handles a lot of noise gracefully.

The capture offset is needed to not overflow 16 bit buffer cells,
and is only a rough value determined over 2 GRI periods only to mostly
cancel antenna DC component for summation.

For later processing comparing both negative and positive amplitudes,
it is important that DC offset is as close as possible to zero. This is
done with the actual capture data after sampling is completed.

The convolution itself is nothing special, but as this needs a lot of clock
cycles, the filter kernel is completely unrolled in assembler for maximum speed.

After convolution, the buffer contains values whose amplitude correlates to
the Loran-C pulse amplitude at this location, with peaks when exactly matching
pulse positions. Note that Envelope-to-Cycle-Difference (ECD) is ignored here.

For detection of pulse trains, pulse polarity is important.
To accomplish this, the combination of the pulse convolution amplitdes at 
four points in time are observed. Only polarity pattern is important, since
polarity of antenna and its amplifier may not be known, so absolute values
are taken of the result of this calculation:

For Master pulse train: 
master(t) = abs{ ampl(t+0us) - ampl(t+2000us) + ampl(t+4000us) + ampl(4+6000us) }

For Slave pulse train:
slave(t)  = abs{ ampl(t+0us) + ampl(t+2000us) + ampl(t+4000us) - ampl(4+6000us) }

You can see the effect of convolution and pulse train matching in the included
example signal images. It is a good time to look at them now.

You can see that both the master and the slave pulse train matching have
characteristic shape when hit a pulse train.

A true hit will give a high central line and 4 lower sattelites,
a false hit, when a Master correlator hits a Slave pulse train and vice versa
looks like two somewhat high lines each having 2 sattelites.

Observe that a true hit always has higher amplitude than a false hit.

Detection algorithm is now simple:

Find the most intense amplitude in both Master and Slave matching.
This gives rise to the most intense pulse train in buffer,
note that location and which one, Master or Slave, has been stronger.

The sattelites have fixed spacing, so continue with excluding a range of 7000 us
in both directons of the just found location. 

Continue for as many pulse trains you expect.

For spacing, the 1994 Loran-C Signal specifications give this hint:
 
   Timing of Secondary Pulse Groups
   Secondary pulse groups are transmitted with the same GRI as
   the master pulse group and are linked in time to the master.
   The emission delays of secondary stations with respect to the
   master are selected to ensure that the following criteria are
   met within each chain wherever the signals can be received:

   a. The minimum time difference between any secondary and
       master is 10,900 microseconds.
   b. The minimum difference of any two time differences is
       9,900 microseconds.
   c. The maximum time difference is the Group Repetition
       Interval minus 9,900 microseconds.
   d. The minimum spacing between corresponding points of the
       last pulse of any station's group and the first pulse of
       the next group in the same chain is 2900 microseconds,
       except that the minimum spacing between the master's ninth
       pulse and the next secondary pulse (of the same chain) may
       be as little as 1900 microseconds. (This is a direct
       result of applying the first three criteria.)

The resulting locations in buffer can be used to calculate the Time Delays.


Pulse shape for calculation of coefficients:

const k : single = 1/65e-6;
      f : single = 100000;

  t := 0.000001 * i; // Step size 1 us.
  loranpuls := k*k*t*t * exp (-2*(k*t-1)) * sin(2*pi*f*t);
  puls[i] := round(886 * loranpuls(i) )

Generated coefficients in use:

0 0
1 1
2 6
3 12
4 13
5 0
6 -27
7 -58
8 -74
9 -56
10 0
11 79
12 147
13 167
14 116
15 0
16 -143
17 -252
18 -274
19 -183
20 0
21 210
22 362
23 384
24 251
25 0
26 -277
27 -468
28 -488
29 -314
30 0
31 337
32 564
33 581
34 370
35 0
36 -390
37 -646
38 -661
39 -417
40 0
41 434
42 714
43 726
44 455
45 0
46 -468
47 -767
48 -775
49 -484
50 0
51 493
52 805
53 810
54 504
55 0
56 -510
57 -829
58 -832
59 -516
60 0
61 519
62 841
63 842
64 521
65 0
66 -521
67 -842
68 -841
69 -519
70 0
71 517
72 834
73 831
74 512
75 0
76 -508
77 -817
78 -813
79 -500
80 0
81 494
82 795
83 790
84 485
85 0
86 -478
87 -767
88 -761
89 -467
90 0
91 459
92 736
93 729
94 446
95 0
96 -438
97 -701
98 -694
99 -424
100 0
101 415
102 665
103 657
104 402
105 0
106 -392
107 -627
108 -620
109 -378
110 0
111 369
112 589
113 582
114 355
115 0
116 -345
117 -551
118 -544
119 -331
120 0
121 322
122 514
123 506
124 309
125 0
126 -300
127 -477
128 -470
129 -286
130 0
131 278
132 442
133 435
134 265
135 0
136 -257
137 -408
138 -402
139 -244
140 0
141 236
142 376
143 370
144 225
145 0
146 -217
147 -346
148 -340
149 -206
150 0
151 199
152 317
153 311
154 189
155 0
156 -182
157 -290
158 -285
159 -173
160 0
161 167
162 265
163 260
164 158
165 0
166 -152
167 -241
168 -237
169 -144
170 0
171 138
172 219
173 215
174 130
175 0
176 -125
177 -199
178 -195
179 -118
180 0
181 114
182 181
183 177
184 107
185 0
186 -103
187 -163
188 -160
189 -97
190 0
191 93
192 148
193 145
194 88
195 0
196 -84
197 -133
198 -131
199 -79
200 0
201 76
202 120
203 118
204 71
205 0
206 -68
207 -108
208 -106
209 -64
210 0
211 61
212 97
213 95
214 58
215 0
216 -55
217 -87
218 -86
219 -52
220 0
221 50
222 78
223 77
224 46
225 0
226 -44
227 -70
228 -69
229 -42
230 0
231 40
232 63
233 62
234 37
235 0
236 -36
237 -56
238 -55
239 -33
240 0
241 32
242 50
243 49
244 30
245 0
246 -28
247 -45
248 -44
249 -27
250 0
251 25
252 40
253 39
254 24
255 0
256 -23
257 -36
258 -35
259 -21
260 0
261 20
262 32
263 31
264 19
265 0
266 -18
267 -28
268 -28
269 -17
270 0
271 16
272 25
273 25
274 15
275 0
276 -14
277 -22
278 -22
279 -13
280 0
281 13
282 20
283 20
284 12
285 0
286 -11
287 -18
288 -17
289 -10
290 0
291 10
292 16
293 15
294 9
295 0
296 -9
297 -14
298 -14
299 -8
300 0
301 8
302 12
303 12
304 7
305 0
306 -7
307 -11
308 -11
309 -6
310 0
311 6
312 10
313 9
314 6
315 0
316 -5
317 -9
318 -8
319 -5
320 0
321 5
322 8
323 7
324 4
325 0
326 -4
327 -7
328 -7
329 -4
330 0
331 4
332 6
333 6
334 3
335 0
336 -3
337 -5
338 -5
339 -3
340 0
341 3
342 5
343 5
344 3
345 0
346 -3
347 -4
348 -4
349 -2
350 0
351 2
352 4
353 4
354 2
355 0
356 -2
357 -3
358 -3
359 -2
360 0
361 2
362 3
363 3
364 2
365 0
366 -2
367 -2
368 -2
369 -1
370 0
371 1
372 2
373 2
374 1
375 0
376 -1
377 -2
378 -2
379 -1
380 0
381 1
382 2
383 2
384 1
385 0
386 -1
387 -1
388 -1
389 -1
390 0
391 1
392 1
393 1
394 1
395 0
396 -1
397 -1
398 -1
399 -1
400 0
401 1
402 1
403 1
404 1
405 0
406 -1
407 -1
408 -1
409 -1
410 0
411 0
412 1
413 1
414 0
415 0
416 0
417 -1
418 -1
419 0
420 0
421 0
422 1
423 1
424 0
425 0
426 0
427 -1
428 -1
429 0
430 0
431 0
432 0
433 0
434 0
435 0
436 0
437 0
438 0
439 0
440 0
441 0
442 0
443 0
444 0
445 0
446 0
447 0
448 0
449 0
450 0
451 0
452 0
453 0
454 0
455 0
456 0
457 0
458 0
459 0
460 0
461 0
462 0
463 0
464 0
465 0
466 0
467 0
468 0
469 0
470 0
471 0
472 0
473 0
474 0
475 0
476 0
477 0
478 0
479 0
480 0
481 0
482 0
483 0
484 0
485 0
486 0
487 0
488 0
489 0
490 0
491 0
492 0
493 0
494 0
495 0
496 0
497 0
498 0
499 0
500 0

  # Sum of coefficients: -1 Sum of absolute coefficients: 65473 Number of coefficients <> 0: 336

