-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmix2.c
1718 lines (1706 loc) · 54 KB
/
mix2.c
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) <2012> <Leif Asbrink>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify,
// merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include "globdef.h"
#include "uidef.h"
#include "fft1def.h"
#include "fft3def.h"
#include "sigdef.h"
#include "seldef.h"
#include "screendef.h"
#include "blnkdef.h"
#define ZZ 0.000000001
void detect_fm(void);
float mix2_phase=0;
void fft3_mix2(void)
{
int i, j, k, ia, ib, ic, id, ix, iy, pb, p0, sizhalf;
int last_point;
float latest_hold_max1;
int latest_hold_pos1;
float latest_hold_max2;
int latest_hold_pos2;
float ampfac,cg_mid;
float big;
int nn, mm;
int pa, resamp;
#define NOISE_FILTERS 2
#define NOISE_POINTS 5
float noise[2*NOISE_FILTERS];
float *carr;
float t1,t2,t3,t4,t5;
float r1,r2,c1,c2,c3;
float noise_floor, a2, b2, re, im;
float noi2, sina, a2s, b2s;
float sellim_correction, fac;
double dr3, dt1, dt2, dt3, dt4, dr4;
carr=&fft3_tmp[twice_rxchan*mix2.size];
resamp=fft3_size/mix2.size;
noise_floor=0;
sizhalf=mix2.size/2;
if(sw_onechan)
{
nn=2*(mix2.size-1);
if(genparm[CW_DECODE_ENABLE] != 0)
{
// Compute the power within several narrow filters near the passband.
// Get the average while excluding large values.
// This way occasional signals outside our filter will not
// be included in the noise floor.
mm=bg_flatpoints+2*bg_curvpoints+NOISE_SEP;
t3=BIGFLOAT;
for(k=0; k<NOISE_FILTERS; k++)
{
t1=0;
t2=0;
for(i=0; i<NOISE_POINTS; i++)
{
j=mm+i+k*(NOISE_POINTS+NOISE_SEP);
t1+=fft3_slowsum[fft3_size/2-bg_first_xpoint+j];
t2+=fft3_slowsum[fft3_size/2-bg_first_xpoint-j];
}
noise[2*k]=t1;
noise[2*k+1]=t2;
if(t1<t3)t3=t1;
if(t2<t3)t3=t2;
}
k=0;
t1=0;
t3*=1.5;
for(i=0; i<2*NOISE_FILTERS; i++)
{
if(noise[i] < t3)
{
t1+=noise[i];
k++;
}
}
noise_floor=t1/(k*NOISE_POINTS);
}
if(bg.mixer_mode == 1)
{
// Filter and decimate in the frequency domain.
// Select mix2.size points centered at fft3_size/2, and move them
// to fft3_tmp while multiplying with the baseband filter function.
p0=fft3_px+fft3_size;
k=fft3_size/2;
for(i=0; i<sizhalf; i++)
{
fft3_tmp[2*i ]=fft3[p0+2*i ]*bg_filterfunc[k+i];
fft3_tmp[2*i+1]=fft3[p0+2*i+1]*bg_filterfunc[k+i];
}
for(i=0; i<sizhalf; i++)
{
fft3_tmp[nn-2*i ]=fft3[p0-2*i-2]*bg_filterfunc[k-i-1];
fft3_tmp[nn-2*i+1]=fft3[p0-2*i-1]*bg_filterfunc[k-i-1];
}
fftback(mix2.size, mix2.n, fft3_tmp, mix2.table, mix2.permute,
yieldflag_ndsp_mix2);
// Store baseb_raw as the time function we obtain from the back transformation.
if(genparm[THIRD_FFT_SINPOW] == 2)
{
for(i=0; i<sizhalf; i++)
{
baseb_raw[2*baseb_pa+2*i ]+=fft3_tmp[2*i];
baseb_raw[2*baseb_pa+2*i+1]+=fft3_tmp[2*i+1];
}
p0=(baseb_pa+sizhalf)&baseband_mask;
for(i=0; i<(int)mix2.size; i++)
{
baseb_raw[2*p0+i]=fft3_tmp[mix2.size+i];
}
}
else
{
p0=baseb_pa;
k=mix2.interleave_points-2*(mix2.crossover_points/2);
j=k/2+mix2.crossover_points;
ia=2*mix2.crossover_points;
for(i=0; i<ia; i+=2)
{
baseb_raw[2*p0 ]=baseb_raw[2*p0 ]*mix2.cos2win[i>>1]+fft3_tmp[i+k ]*mix2.sin2win[i>>1];
baseb_raw[2*p0+1]=baseb_raw[2*p0+1]*mix2.cos2win[i>>1]+fft3_tmp[i+k+1]*mix2.sin2win[i>>1];
p0=(p0+1)&baseband_mask;
}
ib=mix2.new_points+2+2*(mix2.crossover_points/2);
for(i=ia; i<ib; i+=2)
{
baseb_raw[2*p0 ]=fft3_tmp[i+k ]*mix2.window[j];
baseb_raw[2*p0+1]=fft3_tmp[i+k+1]*mix2.window[j];
p0=(p0+1)&baseband_mask;
j++;
}
j--;
ic=2*mix2.new_points;
for(i=ib; i<ic; i+=2)
{
j--;
baseb_raw[2*p0 ]=fft3_tmp[i+k ]*mix2.window[j];
baseb_raw[2*p0+1]=fft3_tmp[i+k+1]*mix2.window[j];
p0=(p0+1)&baseband_mask;
}
id=2*(mix2.crossover_points+mix2.new_points);
for(i=ic; i<id; i+=2)
{
baseb_raw[2*p0 ]=fft3_tmp[i+k ];
baseb_raw[2*p0+1]=fft3_tmp[i+k+1];
p0=(p0+1)&baseband_mask;
}
}
}
if(bg.mixer_mode == 2)
{
// Use a FIR filter
// We have valid data in timf3 up to (timf3_py+2*fft3_size-1)
// The length of the FIR is basebraw_fir_pts
// The last FIR starts at timf3_py+2*chan*(fft3_size-basebraw_fir_pts)
// The first transform starts at timf3_py+2*chan*(fft3_size-
// basebraw_fir_pts-fft3_new_points)
// The resampling rate is fft3_size/mix2.size
p0=baseb_pa;
for(k=1; k<=(int)mix2.new_points; k++)
{
pa=(timf3_py+2*(1-basebraw_fir_pts+fft3_size-fft3_new_points+k*resamp)+
timf3_size)&timf3_mask;
mm=pa;
t1=timf3_float[pa ]*basebraw_fir[basebraw_fir_pts/2];
t2=timf3_float[pa+1]*basebraw_fir[basebraw_fir_pts/2];
if( (k&255) == 255)lir_sched_yield();
for(i=basebraw_fir_pts/2-1; i>=0; i--)
{
pa=(pa+2)&timf3_mask;
mm=(mm-2+timf3_size)&timf3_mask;
t1+=(timf3_float[pa ]+timf3_float[mm ])*basebraw_fir[i];
t2+=(timf3_float[pa+1]+timf3_float[mm+1])*basebraw_fir[i];
}
baseb_raw[2*p0 ]=t1;
baseb_raw[2*p0+1]=t2;
p0=(p0+1)&baseband_mask;
}
}
if(fm_pilot_size == 0)
{
// Select mix2.size points centered at fft3_size/2, and move them
// to carr while multiplying with a filter function that is
// bg.coh_factor times narrower than the baseband filter function
k=fft3_size/2;
for(i=0; i<sizhalf; i++)
{
carr[2*i ]=fft3[fft3_px+fft3_size+2*i ]*bg_carrfilter[k+i];
carr[2*i+1]=fft3[fft3_px+fft3_size+2*i+1]*bg_carrfilter[k+i];
}
for(i=0; i<sizhalf; i++)
{
carr[nn-2*i ]=fft3[fft3_px+fft3_size-2*i-2]*bg_carrfilter[k-i-1];
carr[nn-2*i+1]=fft3[fft3_px+fft3_size-2*i-1]*bg_carrfilter[k-i-1];
}
}
}
else
{
nn=4*(mix2.size-1);
// !!!!!!!!!!!!!! There are two rx channels. !!!!!!!!!!!!!!!!!!
if( genparm[CW_DECODE_ENABLE] != 0)
{
// Compute the power within several narrow filters near the passband.
// Get the average while excluding large values.
// This way occasional signals outside our filter will not
// be included in the noise floor.
mm=bg_flatpoints+2*bg_curvpoints+NOISE_SEP;
t3=BIGFLOAT;
for(k=0; k<NOISE_FILTERS; k++)
{
t1=0;
t2=0;
for(i=0; i<NOISE_POINTS; i++)
{
j=mm+i+k*(NOISE_POINTS+NOISE_SEP);
t1+=fft3_slowsum[2*(fft3_size/2-bg_first_xpoint+j)];
t2+=fft3_slowsum[2*(fft3_size/2-bg_first_xpoint-j)];
}
noise[2*k]=t1;
noise[2*k+1]=t2;
if(t1<t3)t3=t1;
if(t2<t3)t3=t2;
}
k=0;
t1=0;
t3*=1.5;
for(i=0; i<2*NOISE_FILTERS; i++)
{
if(noise[i] < t3)
{
t1+=noise[i];
k++;
}
}
noise_floor=t1/(k*NOISE_POINTS);
}
// Select mix2.size points centered at fft3_size/2, and move them
// to fft3_tmp while multiplying with the baseband filter function.
// Transform the polarization at the same time.
// We fill fft3_tmp even when the filter and decimation will be
// made in the time domain with a FIR filter in order to have
// the polarization computed here by use of the fft3 spectrum.
a2=0;
b2=0;
re=0;
im=0;
p0=fft3_px+2*fft3_size;
k=fft3_size/2;
for(i=0; i<sizhalf; i++)
{
if(bg_filterfunc[k+i] == 0)
{
fft3_tmp[4*i ]=0;
fft3_tmp[4*i+1]=0;
fft3_tmp[4*i+2]=0;
fft3_tmp[4*i+3]=0;
}
else
{
t1=fft3[p0+4*i ];
t2=fft3[p0+4*i+1];
t3=fft3[p0+4*i+2];
t4=fft3[p0+4*i+3];
fft3_tmp[4*i ]=(pg.c1*t1+pg.c2*t3+pg.c3*t4)*bg_filterfunc[k+i];
fft3_tmp[4*i+1]=(pg.c1*t2+pg.c2*t4-pg.c3*t3)*bg_filterfunc[k+i];
fft3_tmp[4*i+2]=(pg.c1*t3-pg.c2*t1+pg.c3*t2)*bg_filterfunc[k+i];
fft3_tmp[4*i+3]=(pg.c1*t4-pg.c2*t2-pg.c3*t1)*bg_filterfunc[k+i];
r1=P4SCALE*(fft3_slowsum[fft3_size-2*bg_first_xpoint+2*i]-noise_floor);
if(r1 > 0 && pg.adapt == 0)
{
a2+=r1*(fft3_tmp[4*i ]*fft3_tmp[4*i ]+
fft3_tmp[4*i+1]*fft3_tmp[4*i+1]);
b2+=r1*(fft3_tmp[4*i+2]*fft3_tmp[4*i+2]+
fft3_tmp[4*i+3]*fft3_tmp[4*i+3]);
re+=r1*(fft3_tmp[4*i ]*fft3_tmp[4*i+2]+
fft3_tmp[4*i+1]*fft3_tmp[4*i+3]);
im+=r1*(-fft3_tmp[4*i ]*fft3_tmp[4*i+3]+
fft3_tmp[4*i+1]*fft3_tmp[4*i+2]);
}
}
}
for(i=0; i<sizhalf; i++)
{
if(bg_filterfunc[k-i-1] == 0)
{
fft3_tmp[nn-4*i ]=0;
fft3_tmp[nn-4*i+1]=0;
fft3_tmp[nn-4*i+2]=0;
fft3_tmp[nn-4*i+3]=0;
}
else
{
t1=fft3[p0-4*i-4];
t2=fft3[p0-4*i-3];
t3=fft3[p0-4*i-2];
t4=fft3[p0-4*i-1];
fft3_tmp[nn-4*i ]=(pg.c1*t1+pg.c2*t3+pg.c3*t4)*bg_filterfunc[k-i-1];
fft3_tmp[nn-4*i+1]=(pg.c1*t2+pg.c2*t4-pg.c3*t3)*bg_filterfunc[k-i-1];
fft3_tmp[nn-4*i+2]=(pg.c1*t3-pg.c2*t1+pg.c3*t2)*bg_filterfunc[k-i-1];
fft3_tmp[nn-4*i+3]=(pg.c1*t4-pg.c2*t2-pg.c3*t1)*bg_filterfunc[k-i-1];
r1=P4SCALE*(fft3_slowsum[fft3_size-2*bg_first_xpoint-2*i]-noise_floor);
if(r1 > 0 && pg.adapt == 0)
{
a2+=r1*(fft3_tmp[nn-4*i ]*fft3_tmp[nn-4*i ]+
fft3_tmp[nn-4*i+1]*fft3_tmp[nn-4*i+1]);
b2+=r1*(fft3_tmp[nn-4*i+2]*fft3_tmp[nn-4*i+2]+
fft3_tmp[nn-4*i+3]*fft3_tmp[nn-4*i+3]);
re+=r1*(fft3_tmp[nn-4*i ]*fft3_tmp[nn-4*i+2]+
fft3_tmp[nn-4*i+1]*fft3_tmp[nn-4*i+3]);
im+=r1*(-fft3_tmp[nn-4*i ]*fft3_tmp[nn-4*i+3]+
fft3_tmp[nn-4*i+1]*fft3_tmp[nn-4*i+2]);
}
}
}
// In case the polarization is already correct, a2 is large because
// it is S+N while the other numbers are small, containing noise only.
// Now, to follow the polarization correctly for really weak
// signals do not just use the data as they come here.
// Store the result in poleval_data and adjust pol first when it
// is quite certain that a new set of coefficients is better.
if(pg.adapt != 0)goto good_poldata;
poleval_data[poleval_pointer].a2=a2;
poleval_data[poleval_pointer].b2=b2;
poleval_data[poleval_pointer].re=re;
poleval_data[poleval_pointer].im=im;
for(i=0; i<poleval_pointer; i++)
{
a2+=poleval_data[i].a2;
b2+=poleval_data[i].b2;
re+=poleval_data[i].re;
im+=poleval_data[i].im;
}
poleval_pointer++;
if(poleval_pointer<POLEVAL_SIZE/5)goto good_poldata;
// Check afcsub.c or blank1 .c for an explanation how pol
// coefficients are calculated.
// If we shall change pol coefficients now, we must be sure that
// the phase angle between a and b is accurate.
// Step through the data and sum the square of the phase deviation.
// Note that the phase is two dimensional.
// The angle between polarization planes and the phase angle
// between voltages.
t1=a2+b2;
if(t1 == 0)goto bad_poldata;
a2/=t1;
b2/=t1;
re/=t1;
im/=t1;
r1=0;
r2=0;
for(i=0; i<poleval_pointer; i++)
{
t1=poleval_data[i].a2+poleval_data[i].b2;
t2=re*t1;
t3=im*t1;
r1+=poleval_data[i].re*poleval_data[i].re+
poleval_data[i].im*poleval_data[i].im;
r2+=-(t2-poleval_data[i].re)*(t2-poleval_data[i].re)+
(t3-poleval_data[i].im)*(t3-poleval_data[i].im);
}
r2/=r1;
if(r2 >0.2)goto bad_poldata;
t2=re*re+im*im;
noi2=a2*b2-t2;
if(noi2 > 0.12)goto bad_poldata;
a2s=a2-noi2;
b2s=b2-noi2;
if(b2s <=0.0001 || t2 == 0)
{
poleval_pointer=0;
if(b2 > a2)
{
t1=atan2(pg.c2,pg.c3);
t2=pg.c1;
pg.c1=sqrt(pg.c2*pg.c2+pg.c3*pg.c3);
pg.c2=t2*cos(t1);
pg.c3=t2*sin(t1);
// The signs of c2 and c3 are most probably incorrect here!!! ööö
// but the situation is unusual and probably t2=0 always when
// b2=1 and a2=0. Check and make sure the new pol parameters give
// the orthogonal polarization.....
}
goto good_poldata;
}
if(a2s > 0)
{
c1=sqrt(a2s);
sina=sqrt(b2s);
c2=sina*re/sqrt(t2);
c3=-sina*im/sqrt(t2);
t1=sqrt(c1*c1+c2*c2+c3*c3);
if(c2 < 0)t1=-t1;
c1/=t1;
c2/=t1;
c3/=t1;
}
else
{
if(a2 > b2)
{
c1=1;
c2=0;
}
else
{
c1=0;
c2=1;
}
c3=0;
}
// The current a and b signals were produced by:
// re_a=pg.c1*re_x+pg.c2*re_y+pg.c3*im_y (1)
// im_a=pg.c1*im_x+pg.c2*im_y-pg.c3*re_y (2)
// re_b=pg.c1*re_y-pg.c2*re_x+pg.c3*im_x (3)
// im_b=pg.c1*im_y-pg.c2*im_x-pg.c3*re_x (4)
// We have now found that improved a and b signals will be obtained from:
// new_re_a=c1*re_a+c2*re_b+c3*im_b (5)
// new_im_a=c1*im_a+c2*im_b-c3*re_b (6)
// new_re_b=c1*re_b-c2*re_a+c3*im_a (7)
// new_im_b=c1*im_b-c2*im_a-c3*re_a (8)
// Eliminate the old a and b signals
// new_re_a=c1*(pg.c1*re_x+pg.c2*re_y+pg.c3*im_y)
// +c2*(pg.c1*re_y-pg.c2*re_x+pg.c3*im_x)
// +c3*(pg.c1*im_y-pg.c2*im_x-pg.c3*re_x)
// new_re_a=c1*pg.c1*re_x+c1*pg.c2*re_y+c1*pg.c3*im_y
// +c2*pg.c1*re_y-c2*pg.c2*re_x+c2*pg.c3*im_x
// +c3*pg.c1*im_y-c3*pg.c2*im_x-c3*pg.c3*re_x
// new_re_a=(c1*pg.c1-c2*pg.c2-c3*pg.c3)*re_x
// -(c3*pg.c2-c2*pg.c3)*im_x
// +(c1*pg.c2+c2*pg.c1)*re_y
// +(c1*pg.c3+c3*pg.c1)*im_y
t1=c1*pg.c1-c2*pg.c2-c3*pg.c3;
t2=c3*pg.c2-c2*pg.c3;
t3=c1*pg.c2+c2*pg.c1;
t4=c1*pg.c3+c3*pg.c1;
// We want t2 to be zero so we adjust the phase.
c1=sqrt(t1*t1+t2*t2);
r2=sqrt(t3*t3+t4*t4);
r1=atan2(t3,t4)+atan2(t1,t2);
c2=-r2*cos(r1);
c3=r2*sin(r1);
t1=sqrt(c1*c1+c2*c2+c3*c3);
if(t1 > 0)
{
t2=c1*pg.c1+c2*pg.c2+c3*pg.c3;
if(t2 < 0)t1=-t1;
c1/=t1;
c2/=t1;
c3/=t1;
t1=pg.avg-1;
pg.c1=(t1*pg.c1+c1)/pg.avg;
pg.c2=(t1*pg.c2+c2)/pg.avg;
pg.c3=(t1*pg.c3+c3)/pg.avg;
t1=sqrt(pg.c1*pg.c1+pg.c2*pg.c2+pg.c3*pg.c3);
if(pg.c2 < 0)t1=-t1;
pg.c1/=t1;
pg.c2/=t1;
pg.c3/=t1;
if(recent_time-show_pol_time > 0.1)
{
sc[SC_SHOW_POL]++;
show_pol_time=current_time();
}
}
poleval_pointer=0;
goto good_poldata;
bad_poldata:;
if(poleval_pointer > 3*POLEVAL_SIZE/4)
{
j=poleval_pointer;
k=POLEVAL_SIZE/4;
poleval_pointer=0;
for(i=k; i<j; i++)
{
poleval_data[poleval_pointer].a2=poleval_data[poleval_pointer+k].a2;
poleval_data[poleval_pointer].b2=poleval_data[poleval_pointer+k].b2;
poleval_data[poleval_pointer].re=poleval_data[poleval_pointer+k].re;
poleval_data[poleval_pointer].im=poleval_data[poleval_pointer+k].im;
poleval_pointer++;
}
}
good_poldata:;
// Select mix2.size points centered at fft3_size/2, and move them
// to fft3_tmp while multiplying with a filter function that is
// bg.coh_factor times narrower than the baseband filter function
// Just process the first polarization.
// The user is responsible for the polarization to be right!
if(fm_pilot_size == 0)
{
nn=2*(mix2.size-1);
k=fft3_size/2;
p0=fft3_px+2*fft3_size;
for(i=0; i<sizhalf; i++)
{
carr[2*i ]=fft3[p0+4*i ]*bg_carrfilter[k+i];
carr[2*i+1]=fft3[p0+4*i+1]*bg_carrfilter[k+i];
}
for(i=0; i<sizhalf; i++)
{
carr[nn-2*i ]=fft3[p0+2*nn-4*i ]*bg_carrfilter[k-i-1];
carr[nn-2*i+1]=fft3[p0+2*nn-4*i+1]*bg_carrfilter[k-i-1];
}
}
if(bg.mixer_mode == 1)
{
dual_fftback(mix2.size, mix2.n, fft3_tmp,
mix2.table, mix2.permute, yieldflag_ndsp_mix2);
// Store baseb_raw and baseb_raw_orthog.
if(genparm[THIRD_FFT_SINPOW] == 2)
{
for(i=0; i<sizhalf; i++)
{
baseb_raw[2*baseb_pa+2*i ]+=fft3_tmp[4*i ];
baseb_raw[2*baseb_pa+2*i+1]+=fft3_tmp[4*i+1];
baseb_raw_orthog[2*baseb_pa+2*i ]+=fft3_tmp[4*i+2];
baseb_raw_orthog[2*baseb_pa+2*i+1]+=fft3_tmp[4*i+3];
}
k=sizhalf;
p0=(baseb_pa+sizhalf)&baseband_mask;
for(i=0; i<sizhalf; i++)
{
baseb_raw[2*p0+2*i ]=fft3_tmp[4*(i+k) ];
baseb_raw[2*p0+2*i+1]=fft3_tmp[4*(i+k)+1];
baseb_raw_orthog[2*p0+2*i ]=fft3_tmp[4*(i+k)+2];
baseb_raw_orthog[2*p0+2*i+1]=fft3_tmp[4*(i+k)+3];
}
}
else
{
p0=baseb_pa;
k=mix2.interleave_points-2*(mix2.crossover_points/2);
j=k/2+mix2.crossover_points;
k*=2;
ia=2*mix2.crossover_points;
for(i=0; i<ia; i+=2)
{
baseb_raw[2*p0 ]=baseb_raw[2*p0 ]*mix2.cos2win[i>>1]+fft3_tmp[2*i+k ]*mix2.sin2win[i>>1];
baseb_raw[2*p0+1]=baseb_raw[2*p0+1]*mix2.cos2win[i>>1]+fft3_tmp[2*i+k+1]*mix2.sin2win[i>>1];
baseb_raw_orthog[2*p0 ]=baseb_raw_orthog[2*p0 ]*mix2.cos2win[i>>1]+
fft3_tmp[2*i+k+2]*mix2.sin2win[i>>1];
baseb_raw_orthog[2*p0+1]=baseb_raw_orthog[2*p0+1]*mix2.cos2win[i>>1]+
fft3_tmp[2*i+k+3]*mix2.sin2win[i>>1];
p0=(p0+1)&baseband_mask;
}
ib=mix2.new_points+2+2*(mix2.crossover_points/2);
for(i=ia; i<ib; i+=2)
{
baseb_raw[2*p0 ]=fft3_tmp[2*i+k ]*mix2.window[j];
baseb_raw[2*p0+1]=fft3_tmp[2*i+k+1]*mix2.window[j];
baseb_raw_orthog[2*p0 ]=fft3_tmp[2*i+k+2]*mix2.window[j];
baseb_raw_orthog[2*p0+1]=fft3_tmp[2*i+k+3]*mix2.window[j];
p0=(p0+1)&baseband_mask;
j++;
}
j--;
ic=2*mix2.new_points;
for(i=ib; i<ic; i+=2)
{
j--;
baseb_raw[2*p0 ]=fft3_tmp[2*i+k ]*mix2.window[j];
baseb_raw[2*p0+1]=fft3_tmp[2*i+k+1]*mix2.window[j];
baseb_raw_orthog[2*p0 ]=fft3_tmp[2*i+k+2]*mix2.window[j];
baseb_raw_orthog[2*p0+1]=fft3_tmp[2*i+k+3]*mix2.window[j];
p0=(p0+1)&baseband_mask;
}
id=2*(mix2.crossover_points+mix2.new_points);
for(i=ic; i<id; i+=2)
{
baseb_raw[2*p0 ]=fft3_tmp[2*i+k ];
baseb_raw[2*p0+1]=fft3_tmp[2*i+k+1];
baseb_raw_orthog[2*p0 ]=fft3_tmp[2*i+k+2];
baseb_raw_orthog[2*p0+1]=fft3_tmp[2*i+k+3];
p0=(p0+1)&baseband_mask;
}
}
}
if(bg.mixer_mode == 2)
{
// Use a FIR filter
// We have valid data in timf3 up to (timf3_py+2*fft3_size-1)
// The length of the FIR is basebraw_fir_pts
// The last FIR starts at timf3_py+2*chan*(fft3_size-basebraw_fir_pts)
// The first transform starts at timf3_py+2*chan*(fft3_size-
// basebraw_fir_pts-fft3_new_points)
// The resampling rate is fft3_size/mix2.size
p0=baseb_pa;
for(k=1; k<=(int)mix2.new_points; k++)
{
pa=(timf3_py+4*(1-basebraw_fir_pts+fft3_size-fft3_new_points+k*resamp)
+timf3_size)&timf3_mask;
mm=pa;
t1=timf3_float[pa ]*basebraw_fir[basebraw_fir_pts/2];
t2=timf3_float[pa+1]*basebraw_fir[basebraw_fir_pts/2];
t3=timf3_float[pa+2]*basebraw_fir[basebraw_fir_pts/2];
t4=timf3_float[pa+3]*basebraw_fir[basebraw_fir_pts/2];
if( (k&127) == 127)lir_sched_yield();
for(i=basebraw_fir_pts/2-1; i>=0; i--)
{
pa=(pa+4)&timf3_mask;
mm=(mm-4+timf3_size)&timf3_mask;
t1+=(timf3_float[pa ]+timf3_float[mm ])*basebraw_fir[i];
t2+=(timf3_float[pa+1]+timf3_float[mm+1])*basebraw_fir[i];
t3+=(timf3_float[pa+2]+timf3_float[mm+2])*basebraw_fir[i];
t4+=(timf3_float[pa+3]+timf3_float[mm+3])*basebraw_fir[i];
}
baseb_raw[2*p0 ]=pg.c1*t1+pg.c2*t3+pg.c3*t4;
baseb_raw[2*p0+1]=pg.c1*t2+pg.c2*t4-pg.c3*t3;
baseb_raw_orthog[2*p0 ]=pg.c1*t3-pg.c2*t1+pg.c3*t2;
baseb_raw_orthog[2*p0+1]=pg.c1*t4-pg.c2*t2-pg.c3*t1;
p0=(p0+1)&baseband_mask;
}
}
}
if(fm_pilot_size == 0)
{
if(bg.mixer_mode == 1)
{
// Filter and decimate in the frequency domain.
// We already stored the selected part of the spectrum in carr.
// take the back transform and construct the time function
// of baseb_carrier
fftback(mix2.size, mix2.n, carr,mix2.table,mix2.permute,
yieldflag_ndsp_mix2);
// Store baseb_raw and baseb_carrier.
// Compute baseb, the product of the carrier and the signal.
if(genparm[THIRD_FFT_SINPOW] == 2)
{
for(i=0; i<sizhalf; i++)
{
baseb_carrier[2*baseb_pa+2*i ]+=carr[2*i ];
baseb_carrier[2*baseb_pa+2*i+1]+=carr[2*i+1];
}
p0=(baseb_pa+sizhalf)&baseband_mask;
k=mix2.size;
for(i=0; i<k; i++)
{
baseb_carrier[2*p0+i]=carr[i+k];
}
}
else
{
p0=baseb_pa;
k=mix2.interleave_points-2*(mix2.crossover_points/2);
j=k/2+mix2.crossover_points;
ia=2*mix2.crossover_points;
for(i=0; i<ia; i+=2)
{
baseb_carrier[2*p0 ]=baseb_carrier[2*p0 ]*mix2.cos2win[i>>1]+carr[i+k ]*mix2.sin2win[i>>1];
baseb_carrier[2*p0+1]=baseb_carrier[2*p0+1]*mix2.cos2win[i>>1]+carr[i+k+1]*mix2.sin2win[i>>1];
p0=(p0+1)&baseband_mask;
}
ib=mix2.new_points+2+2*(mix2.crossover_points/2);
for(i=ia; i<ib; i+=2)
{
baseb_carrier[2*p0 ]=carr[i+k ]*mix2.window[j];
baseb_carrier[2*p0+1]=carr[i+k+1]*mix2.window[j];
p0=(p0+1)&baseband_mask;
j++;
}
j--;
ic=2*mix2.new_points;
for(i=ib; i<ic; i+=2)
{
j--;
baseb_carrier[2*p0 ]=carr[i+k ]*mix2.window[j];
baseb_carrier[2*p0+1]=carr[i+k+1]*mix2.window[j];
p0=(p0+1)&baseband_mask;
}
id=2*(mix2.crossover_points+mix2.new_points);
for(i=ic; i<id; i+=2)
{
baseb_carrier[2*p0 ]=carr[i+k ];
baseb_carrier[2*p0+1]=carr[i+k+1];
p0=(p0+1)&baseband_mask;
}
}
}
if(bg.mixer_mode == 2)
{
// Filter and decimate in the frequency domain.
// Use a FIR filter
// We have valid data in timf3 up to (timf3_py+2*fft3_size-1)
// The length of the FIR is basebcarr_fir_pts
// The last FIR starts at timf3_py+2*chan*(fft3_size-basebcarr_fir_pts)
// The first transform starts at timf3_py+2*chan*(fft3_size-
// basebcarr_fir_pts-fft3_new_points)
// The resampling rate is fft3_size/mix2.size
p0=baseb_pa;
if(sw_onechan)
{
for(k=1; k<=(int)mix2.new_points; k++)
{
pa=(timf3_py+2*(1-basebcarr_fir_pts+fft3_size-fft3_new_points+k*resamp)+timf3_size)&timf3_mask;
mm=pa;
t1=timf3_float[pa ]*basebcarr_fir[basebcarr_fir_pts/2];
t2=timf3_float[pa+1]*basebcarr_fir[basebcarr_fir_pts/2];
if( (k&255) == 255)lir_sched_yield();
for(i=basebcarr_fir_pts/2-1; i>=0; i--)
{
pa=(pa+2)&timf3_mask;
mm=(mm-2+timf3_size)&timf3_mask;
t1+=(timf3_float[pa ]+timf3_float[mm ])*basebcarr_fir[i];
t2+=(timf3_float[pa+1]+timf3_float[mm+1])*basebcarr_fir[i];
}
baseb_carrier[2*p0 ]=t1;
baseb_carrier[2*p0+1]=t2;
p0=(p0+1)&baseband_mask;
}
}
else
{
for(k=1; k<=(int)mix2.new_points; k++)
{
pa=(timf3_py+4*(1-basebcarr_fir_pts+fft3_size-fft3_new_points+k*resamp)+timf3_size)&timf3_mask;
mm=pa;
t1=timf3_float[pa ]*basebcarr_fir[basebcarr_fir_pts/2];
t2=timf3_float[pa+1]*basebcarr_fir[basebcarr_fir_pts/2];
t3=timf3_float[pa+2]*basebcarr_fir[basebcarr_fir_pts/2];
t4=timf3_float[pa+3]*basebcarr_fir[basebcarr_fir_pts/2];
if( (k&127) == 127)lir_sched_yield();
for(i=basebcarr_fir_pts/2-1; i>=0; i--)
{
pa=(pa+4)&timf3_mask;
mm=(mm-4+timf3_size)&timf3_mask;
t1+=(timf3_float[pa ]+timf3_float[mm ])*basebcarr_fir[i];
t2+=(timf3_float[pa+1]+timf3_float[mm+1])*basebcarr_fir[i];
t3+=(timf3_float[pa+2]+timf3_float[mm+2])*basebcarr_fir[i];
t4+=(timf3_float[pa+3]+timf3_float[mm+3])*basebcarr_fir[i];
}
baseb_carrier[2*p0 ]=pg.c1*t1+pg.c2*t3+pg.c3*t4;
baseb_carrier[2*p0+1]=pg.c1*t2+pg.c2*t4-pg.c3*t3;
p0=(p0+1)&baseband_mask;
}
}
}
}
if(genparm[CW_DECODE_ENABLE] != 0)
{
// We want cw decoding. Compute baseb_wb_raw, a signal with a bandwidth
// that is at least two times bigger than the bandwidth of the
// filtered signal. (see computation of baseband_sampling_speed in
// baseb_graph.c)
if(sw_onechan)
{
for(i=0; i<sizhalf; i++)
{
fft3_tmp[2*i ]=fft3[fft3_px+fft3_size+2*i ];
fft3_tmp[2*i+1]=fft3[fft3_px+fft3_size+2*i+1];
}
nn=2*(mix2.size-1);
for(i=0; i<sizhalf; i++)
{
fft3_tmp[nn-2*i ]=fft3[fft3_px+fft3_size-2*i-2];
fft3_tmp[nn-2*i+1]=fft3[fft3_px+fft3_size-2*i-1];
}
}
else
{
// !!!!!!!!!!!!!! There are two rx channels. !!!!!!!!!!!!!!!!!!
// Select mix2.size points centered at fft3_size/2, and move them
// to fft3_tmp. Transform the polarization at the same time.
for(i=0; i<sizhalf; i++)
{
fft3_tmp[2*i ]=pg.c1*fft3[fft3_px+2*fft3_size+4*i ]+
pg.c2*fft3[fft3_px+2*fft3_size+4*i+2]+
pg.c3*fft3[fft3_px+2*fft3_size+4*i+3];
fft3_tmp[2*i+1]=pg.c1*fft3[fft3_px+2*fft3_size+4*i+1]+
pg.c2*fft3[fft3_px+2*fft3_size+4*i+3]-
pg.c3*fft3[fft3_px+2*fft3_size+4*i+2];
}
nn=2*(mix2.size-1);
for(i=0; i<sizhalf; i++)
{
fft3_tmp[nn-2*i ]=pg.c1*fft3[fft3_px+2*fft3_size-4*i-4]+
pg.c2*fft3[fft3_px+2*fft3_size-4*i-2]+
pg.c3*fft3[fft3_px+2*fft3_size-4*i-1];
fft3_tmp[nn-2*i+1]=pg.c1*fft3[fft3_px+2*fft3_size-4*i-3]+
pg.c2*fft3[fft3_px+2*fft3_size-4*i-1]-
pg.c3*fft3[fft3_px+2*fft3_size-4*i-2];
}
}
fftback(mix2.size, mix2.n, fft3_tmp,
mix2.table, mix2.permute, yieldflag_ndsp_mix2);
// Store baseb_wb_raw
if(genparm[THIRD_FFT_SINPOW] == 2)
{
for(i=0; i<sizhalf; i++)
{
baseb_wb_raw[2*baseb_pa+2*i ]+=fft3_tmp[2*i ];
baseb_wb_raw[2*baseb_pa+2*i+1]+=fft3_tmp[2*i+1];
}
k=sizhalf;
p0=(baseb_pa+sizhalf)&baseband_mask;
for(i=0; i<sizhalf; i++)
{
baseb_wb_raw[2*p0+2*i ]=fft3_tmp[2*(i+k) ];
baseb_wb_raw[2*p0+2*i+1]=fft3_tmp[2*(i+k)+1];
}
}
else
{
p0=baseb_pa;
k=mix2.interleave_points-2*(mix2.crossover_points/2);
j=k/2+mix2.crossover_points;
ia=2*mix2.crossover_points;
for(i=0; i<ia; i+=2)
{
baseb_wb_raw[2*p0 ]=baseb_wb_raw[2*p0 ]*mix2.cos2win[i>>1]+fft3_tmp[i+k ]*mix2.sin2win[i>>1];
baseb_wb_raw[2*p0+1]=baseb_wb_raw[2*p0+1]*mix2.cos2win[i>>1]+fft3_tmp[i+k+1]*mix2.sin2win[i>>1];
p0=(p0+1)&baseband_mask;
}
ib=mix2.new_points+2+2*(mix2.crossover_points/2);
for(i=ia; i<ib; i+=2)
{
baseb_wb_raw[2*p0 ]=fft3_tmp[i+k ]*mix2.window[j];
baseb_wb_raw[2*p0+1]=fft3_tmp[i+k+1]*mix2.window[j];
p0=(p0+1)&baseband_mask;
j++;
}
j--;
ic=2*mix2.new_points;
for(i=ib; i<ic; i+=2)
{
j--;
baseb_wb_raw[2*p0 ]=fft3_tmp[i+k ]*mix2.window[j];
baseb_wb_raw[2*p0+1]=fft3_tmp[i+k+1]*mix2.window[j];
p0=(p0+1)&baseband_mask;
}
id=2*(mix2.crossover_points+mix2.new_points);
for(i=ic; i<id; i+=2)
{
baseb_wb_raw[2*p0 ]=fft3_tmp[i+k ];
baseb_wb_raw[2*p0+1]=fft3_tmp[i+k+1];
p0=(p0+1)&baseband_mask;
}
}
}
last_point=(baseb_pa+mix2.new_points)&baseband_mask;
ampfac=cg_size*daout_gain/bg_amplimit;
// *******************************************************************
// Calculate the amplitude of the signal and the amplitude of the carrier.
// Store sines and cosines of the carrier phase.
// Make an I/Q demodulator using the carrier phase.
// Use this "zero level" coherent detect data to make the upper coherent
// graph that will help the user select coherence ratio for unstable
// signals.
if(fm_pilot_size == 0)
{
t2=0;
t5=0;
cg_mid=cg_size/2;
big=0.499*cg_size;
ia=baseb_pa;
i=(baseb_pa+baseband_mask)&baseband_mask;
if(genparm[CW_DECODE_ENABLE] != 0 || bg.agc_flag == 1)
{
t2=baseb_upthreshold[i];
}
if(bg.agc_flag == 2)
{
t2=baseb_upthreshold[2*i ];
t5=baseb_upthreshold[2*i+1];
}
t3=0;
t4=0;
if(bg_twopol == 0)
{
while(ia != last_point)
{
baseb_totpwr[ia]=baseb_raw[2*ia ]*baseb_raw[2*ia ]+
baseb_raw[2*ia+1]*baseb_raw[2*ia+1];
t4+=baseb_totpwr[ia];
if(t3 < baseb_totpwr[ia])t3=baseb_totpwr[ia];
baseb_carrier_ampl[ia]=sqrt(baseb_carrier[2*ia ]*baseb_carrier[2*ia ]+
baseb_carrier[2*ia+1]*baseb_carrier[2*ia+1]);
if(genparm[CW_DECODE_ENABLE] != 0 || bg.agc_flag == 1)
{
t2*=cg_decay_factor;
if(t2 < baseb_totpwr[ia])t2=baseb_totpwr[ia];
baseb_upthreshold[ia]=t2;
}
if(baseb_carrier_ampl[ia]==0)
{
baseb_carrier_ampl[ia]=0.0000000000001;
}
else
{
baseb_carrier[2*ia ]/=baseb_carrier_ampl[ia];
baseb_carrier[2*ia+1]/=baseb_carrier_ampl[ia];
}
baseb[2*ia ]=baseb_carrier[2*ia ]*baseb_raw[2*ia ]+
baseb_carrier[2*ia+1]*baseb_raw[2*ia+1];
baseb[2*ia+1]=baseb_carrier[2*ia ]*baseb_raw[2*ia+1]-
baseb_carrier[2*ia+1]*baseb_raw[2*ia ];
if(bg.agc_flag == 2)
{
baseb[2*ia ]-=baseb_carrier_ampl[ia];
t2*=cg_decay_factor;
if(t2 < baseb[2*ia ]*baseb[2*ia ])t2=baseb[2*ia ]*baseb[2*ia ];
baseb_upthreshold[2*ia ]=t2;
t5*=cg_decay_factor;
if(t5 < baseb[2*ia+1]*baseb[2*ia+1])t5=baseb[2*ia+1]*baseb[2*ia+1];
baseb_upthreshold[2*ia+1]=t5;
}
r1=ampfac*baseb[2*ia ];
r2=ampfac*baseb[2*ia+1];
if(genparm[CW_DECODE_ENABLE] != 0)
{
baseb_fit[2*ia ]=0;
baseb_fit[2*ia+1]=0;
baseb_envelope[2*ia ]=0;
baseb_envelope[2*ia+1]=0;
}
ia=(ia+1)&baseband_mask;
if(fabs(r1)>big || fabs(r2)>big)
{
t1=big/sqrt(r1*r1+r2*r2);
r1*=t1;
r2*=t1;
}
ix=cg_mid+r1;
iy=cg_mid+r2;
cg_map[iy*cg_size+ix]+=1;
}
}
else
{
while(ia != last_point)
{
baseb_totpwr[ia]=baseb_raw[2*ia ]*baseb_raw[2*ia ]+
baseb_raw[2*ia+1]*baseb_raw[2*ia+1];
t4+=baseb_totpwr[ia];
if(t3 < baseb_totpwr[ia])t3=baseb_totpwr[ia];
baseb_carrier_ampl[ia]=sqrt(baseb_carrier[2*ia ]*baseb_carrier[2*ia ]+
baseb_carrier[2*ia+1]*baseb_carrier[2*ia+1]);
if(genparm[CW_DECODE_ENABLE] != 0 || bg.agc_flag == 1)
{
t2*=cg_decay_factor;
if(t2 < baseb_totpwr[ia])t2=baseb_totpwr[ia];
baseb_upthreshold[ia]=t2;
}
if(baseb_carrier_ampl[ia]==0)
{
baseb_carrier_ampl[ia]=0.0000000000001;
}
else
{
baseb_carrier[2*ia ]/=baseb_carrier_ampl[ia];
baseb_carrier[2*ia+1]/=baseb_carrier_ampl[ia];
}
baseb[2*ia ]=baseb_carrier[2*ia ]*baseb_raw[2*ia ]+
baseb_carrier[2*ia+1]*baseb_raw[2*ia+1];
baseb[2*ia+1]=baseb_carrier[2*ia ]*baseb_raw[2*ia+1]-
baseb_carrier[2*ia+1]*baseb_raw[2*ia ];
if(bg.agc_flag == 2)
{
t2*=cg_decay_factor;
if(t2 < baseb_totpwr[ia])t2=baseb_totpwr[ia];
baseb_upthreshold[2*ia]=t2;
t5*=cg_decay_factor;
if(t5 < baseb_raw_orthog[2*ia ]*baseb_raw_orthog[2*ia ]+
baseb_raw_orthog[2*ia+1]*baseb_raw_orthog[2*ia+1])
t5=baseb_raw_orthog[2*ia ]*baseb_raw_orthog[2*ia ]+
baseb_raw_orthog[2*ia+1]*baseb_raw_orthog[2*ia+1];
baseb_upthreshold[2*ia+1]=t5;
}
r1=ampfac*baseb[2*ia ];
r2=ampfac*baseb[2*ia+1];
if(genparm[CW_DECODE_ENABLE] != 0)
{
baseb_fit[2*ia ]=0;
baseb_fit[2*ia+1]=0;
baseb_envelope[2*ia ]=0;
baseb_envelope[2*ia+1]=0;