@@ -457,7 +457,7 @@ void config_usb(
457
457
}
458
458
459
459
// Sampling frequency
460
- if (rtlsdr_set_sample_rate (dev,itpp::round (1920000 *correction))<0 ) {
460
+ if (rtlsdr_set_sample_rate (dev,itpp::round (960000 *correction))<0 ) {
461
461
cerr << " Error: unable to set sampling rate" << endl;
462
462
exit (-1 );
463
463
}
@@ -486,16 +486,16 @@ void config_usb(
486
486
}
487
487
uint32 n_read=0 ;
488
488
int n_read_current;
489
- #define BLOCK_SIZE 16 *16384
489
+ #define BLOCK_SIZE ( 16 *16384 )
490
490
uint8 * buffer=(uint8 *)malloc (BLOCK_SIZE*sizeof (uint8));
491
491
while (true ) {
492
492
if (rtlsdr_read_sync (dev,buffer,BLOCK_SIZE,&n_read_current)<0 ) {
493
493
cerr << " Error: synchronous read failed" << endl;
494
- break ;
494
+ exit (- 1 ) ;
495
495
}
496
496
if (n_read_current<BLOCK_SIZE) {
497
497
cerr << " Error: short read; samples lost" << endl;
498
- break ;
498
+ exit (- 1 ) ;
499
499
}
500
500
n_read+=n_read_current;
501
501
if (n_read>2880000 *2 )
@@ -610,7 +610,14 @@ void read_datafile(
610
610
cout << " read itpp format" << endl;
611
611
return ;
612
612
} else {
613
- itpp_ext::rtl_sdr_to_cvec (filename,sig_tx);
613
+ cvec sig_tx_pre;
614
+ itpp_ext::rtl_sdr_to_cvec (filename,sig_tx_pre);
615
+ sig_tx.set_size (length (sig_tx_pre)*2 -10 );
616
+ for (int32 t=0 ;t<length (sig_tx);t+=2 ) {
617
+ // FIXME: Do proper interpolation
618
+ sig_tx (t)=sig_tx_pre (t>>1 );
619
+ sig_tx (t+1 )=(sig_tx_pre (t>>1 )+sig_tx_pre ((t>>1 )+1 ))/2 ;
620
+ }
614
621
// Drop several seconds while AGC converges.
615
622
sig_tx=sig_tx (FS_LTE/16 *4 ,-1 );
616
623
}
@@ -628,7 +635,7 @@ class rtl_wrap {
628
635
// Destructor
629
636
~rtl_wrap ();
630
637
complex <double > get_samp ();
631
- void reset ();
638
+ // void reset();
632
639
private:
633
640
bool use_recorded_data;
634
641
cvec sig_tx;
@@ -637,6 +644,10 @@ class rtl_wrap {
637
644
double noise_power_sqrt;
638
645
bool repeat;
639
646
bool rtl_sdr_format;
647
+ bool phase_even;
648
+ complex <double > samp_d1;
649
+ complex <double > samp_d2;
650
+ // FILE * file;
640
651
};
641
652
rtl_wrap::rtl_wrap (
642
653
rtlsdr_dev_t * dev,
@@ -650,6 +661,16 @@ rtl_wrap::rtl_wrap(
650
661
use_recorded_data=urd;
651
662
repeat=rpt;
652
663
rtl_sdr_format=rsdf;
664
+ phase_even=true ;
665
+ samp_d1=complex <double > (0 ,0 );
666
+ samp_d2=complex <double > (0 ,0 );
667
+ // cout << "Opening log file" << endl;
668
+ // file=fopen("tracker_log.dat","wb");
669
+ // if (!file) {
670
+ // cerr << "Error: could not open ddata capture log file" << endl;
671
+ // exit(-1);
672
+ // }
673
+ // cout << "Log file opened!" << endl;
653
674
if (isfinite (noise_power)) {
654
675
noise_power_sqrt=sqrt (noise_power);
655
676
} else {
@@ -680,7 +701,7 @@ complex <double> rtl_wrap::get_samp() {
680
701
complex <double > samp;
681
702
if (use_recorded_data) {
682
703
// samp=sig_tx(offset);
683
- samp=0 *sig_tx (offset)+(1 .0 *J)*exp (J*((double )(cnt++))*2 *pi /10000000 )*sig_tx (mod (offset-5000 ,length (sig_tx)));;
704
+ samp=1 *sig_tx (offset)+(0 .0 *J)*exp (J*((double )(cnt++))*2 *pi /10000000 )*sig_tx (mod (offset-5000 ,length (sig_tx)));;
684
705
offset=mod (offset+1 ,length (sig_tx));
685
706
if ((offset==0 )&&(!repeat)) {
686
707
// Not that if N complex samples are read from the file and repeat is
@@ -697,6 +718,10 @@ complex <double> rtl_wrap::get_samp() {
697
718
cerr << " Error: synchronous read failed" << endl;
698
719
exit (-1 );
699
720
}
721
+ // if (fwrite(buffer, 1, n_read, file)!=(size_t)n_read) {
722
+ // cerr<<"Error: Short write, samples lost, exiting!" << endl;
723
+ // exit(-1);
724
+ // }
700
725
if (n_read<BLOCK_SIZE) {
701
726
cerr << " Error: short read; samples lost" << endl;
702
727
exit (-1 );
@@ -711,9 +736,25 @@ complex <double> rtl_wrap::get_samp() {
711
736
return samp;
712
737
}
713
738
}
739
+ /*
740
+ complex <double> rtl_wrap::get_samp() {
741
+ complex <double> samp;
742
+ if (phase_even==true) {
743
+ samp_d2=samp_d1;
744
+ samp_d1=get_samp_pre();
745
+ samp=samp_d1;
746
+ } else {
747
+ samp=(samp_d1+samp_d2)/2;
748
+ }
749
+ phase_even=!phase_even;
750
+ return samp;
751
+ }
752
+ */
753
+ /*
714
754
void rtl_wrap::reset() {
715
755
offset=0;
716
756
}
757
+ */
717
758
718
759
// Perform an initial cell search solely for the purpose of calibrating
719
760
// the oscillator.
@@ -740,9 +781,10 @@ double kalibrate(
740
781
list <Cell> detected_cells;
741
782
// Loop until a cell is found
742
783
while (detected_cells.size ()<1 ) {
784
+ cvec capbuf;
743
785
// Fill capture buffer either from a file or from live data.
744
- cvec capbuf (153600 );
745
786
if (use_recorded_data) {
787
+ capbuf.set_size (153600 );
746
788
cvec cbload;
747
789
read_datafile (filename,rtl_sdr_format,cbload);
748
790
// it_ifile itf(filename);
@@ -758,7 +800,7 @@ double kalibrate(
758
800
} else {
759
801
capture_data (fc,correction,false ,false ," ." ,capbuf);
760
802
}
761
- cout << " Capbuf power: " << db10 (sigpower (capbuf)) << " dB" << endl;
803
+ // cout << "Capbuf power: " << db10(sigpower(capbuf)) << " dB" << endl;
762
804
if (isfinite (noise_power))
763
805
capbuf+=blnoise (length (capbuf))*sqrt (noise_power);
764
806
@@ -1400,15 +1442,15 @@ int8 do_mib_decode(
1400
1442
// Did we find it?
1401
1443
if (crc_est==c_est (24 ,-1 )) {
1402
1444
// YES!
1403
- cout << " MIB SUCCESS!" << endl;
1445
+ cout << " Cell ID " << tracked_cell. n_id_cell << " MIB SUCCESS!" << endl;
1404
1446
mib_fifo_synchronized=1 ;
1405
1447
mib_fifo_decode_failures=0 ;
1406
1448
for (uint8 t=0 ;t<16 ;t++) {
1407
1449
mib_fifo.pop_front ();
1408
1450
}
1409
1451
} else {
1410
1452
// No :(
1411
- cout << " MIB failure!" << endl;
1453
+ cout << " Cell ID " << tracked_cell. n_id_cell << " MIB failure!" << endl;
1412
1454
if (mib_fifo_synchronized) {
1413
1455
mib_fifo_decode_failures++;
1414
1456
for (uint8 t=0 ;t<16 ;t++) {
@@ -1424,7 +1466,7 @@ int8 do_mib_decode(
1424
1466
1425
1467
// 10ms of time increases mib_fifo_decode_failures by 0.25.
1426
1468
// After several seconds of MIB decoding failures, drop the cell.
1427
- if (mib_fifo_decode_failures>=400 ) {
1469
+ if (mib_fifo_decode_failures>=100 ) {
1428
1470
cout << " Dropped a cell!" << endl;
1429
1471
boost::mutex::scoped_lock lock (tracked_cell.mutex );
1430
1472
tracked_cell.kill_me =true ;
@@ -1764,20 +1806,21 @@ void searcher_proc(
1764
1806
cout << " cell ID: " << (*iterator).n_id_cell () << endl;
1765
1807
cout << " RX power level: " << db10 ((*iterator).pss_pow ) << " dB" << endl;
1766
1808
cout << " residual frequency offset: " << (*iterator).freq_superfine << " Hz" << endl;
1767
- cout << " Frame start " << (*iterator).frame_start << endl;
1809
+ cout << " frame start: " << (*iterator).frame_start << endl;
1768
1810
}
1769
1811
1770
1812
// Launch a cell tracker process!
1771
1813
k_factor=k_factor;
1772
- cout << " Timing error is purposely introduced here!!!" << endl;
1773
- tracked_cell_t * new_cell = new tracked_cell_t ((*iterator).n_id_cell (),(*iterator).n_ports ,(*iterator).cp_type ,(*iterator).frame_start /k_factor+capbuf_sync.late +global_1);
1814
+ // cout << "Timing error is purposely introduced here!!!" << endl;
1815
+ // tracked_cell_t * new_cell = new tracked_cell_t((*iterator).n_id_cell(),(*iterator).n_ports,(*iterator).cp_type,(*iterator).frame_start/k_factor+capbuf_sync.late+global_1);
1816
+ tracked_cell_t * new_cell = new tracked_cell_t ((*iterator).n_id_cell (),(*iterator).n_ports ,(*iterator).cp_type ,(*iterator).frame_start /k_factor+capbuf_sync.late );
1774
1817
(*new_cell).thread =boost::thread (tracker_proc,boost::ref (*new_cell),boost::ref (global_thread_data));
1775
1818
{
1776
1819
boost::mutex::scoped_lock lock (tracked_cell_list.mutex );
1777
1820
tracked_cell_list.tracked_cells .push_back (new_cell);
1778
1821
}
1779
- cout << " Only one cell is allowed to be detected!!!" << endl;
1780
- sleep (1000000 );
1822
+ // cout << "Only one cell is allowed to be detected!!!" << endl;
1823
+ // sleep(1000000);
1781
1824
1782
1825
++iterator;
1783
1826
}
@@ -1887,7 +1930,7 @@ int main(
1887
1930
{
1888
1931
boost::mutex::scoped_lock lock (capbuf_sync.mutex );
1889
1932
if ((capbuf_sync.request )&&(!searcher_capbuf_filling)&&(abs (WRAP (sample_time-0 ,-19200.0 /2 ,19200.0 /2 ))<0.5 )) {
1890
- cout << " searcher data cap beginning" << endl;
1933
+ // cout << "searcher data cap beginning" << endl;
1891
1934
capbuf_sync.request =false ;
1892
1935
searcher_capbuf_filling=true ;
1893
1936
searcher_capbuf_idx=0 ;
@@ -1903,7 +1946,7 @@ int main(
1903
1946
searcher_capbuf_filling=false ;
1904
1947
boost::mutex::scoped_lock lock (capbuf_sync.mutex );
1905
1948
capbuf_sync.condition .notify_one ();
1906
- cout << " searcher data cap finished" << endl;
1949
+ // cout << "searcher data cap finished" << endl;
1907
1950
}
1908
1951
}
1909
1952
0 commit comments