
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/72.5e-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(795 * loranpuls(i) )

Generated coefficients in use:

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