diff --git a/conf/gnss-sdr.conf b/conf/gnss-sdr.conf index 3e70d5040..986a6856a 100644 --- a/conf/gnss-sdr.conf +++ b/conf/gnss-sdr.conf @@ -29,8 +29,8 @@ GNSS-SDR.SUPL_CI=0x31b0 SignalSource.implementation=File_Signal_Source ;#filename: path to file with the captured GNSS signal samples to be processed -SignalSource.filename=/media/DATALOGGER/Agilent GPS Generator/cap2/agilent_cap2.dat - +;SignalSource.filename=/media/DATALOGGER/Agilent GPS Generator/cap2/agilent_cap2.dat +SignalSource.filename=/media/DATA/Proyectos/Signals/cttc_2012_07_26/cp_cttc_2012_07_26_n3_4Msps.dat ;#item_type: Type and resolution for each of the signal samples. Use only gr_complex in this version. SignalSource.item_type=gr_complex @@ -272,21 +272,25 @@ Acquisition.item_type=gr_complex ;#if: Signal intermediate frequency in [Hz] Acquisition.if=0 ;#sampled_ms: Signal block duration for the acquisition signal detection [ms] -Acquisition.sampled_ms=1 +Acquisition.coherent_integration_time_ms=1 ;#implementation: Acquisition algorithm selection for this channel: [GPS_L1_CA_PCPS_Acquisition] or [Galileo_E1_PCPS_Ambiguous_Acquisition] Acquisition.implementation=GPS_L1_CA_PCPS_Acquisition -;#threshold: Acquisition threshold +;#threshold: Acquisition threshold. It will be ignored if pfa is defined. Acquisition.threshold=0.005 -;#pfa: Acquisition false alarm probability. This option overrides the threshold option. Only use with implementations: [GPS_L1_CA_PCPS_Acquisition] or [Galileo_E1_PCPS_Ambiguous_Acquisition] +;#pfa: Acquisition false alarm probability. This option overrides the threshold option. Only use with implementations: [GPS_L1_CA_PCPS_Acquisition] or [Galileo_E1_PCPS_Ambiguous_Acquisition] Acquisition.pfa=0.0001 ;#doppler_max: Maximum expected Doppler shift [Hz] Acquisition.doppler_max=10000 ;#doppler_max: Doppler step in the grid search [Hz] Acquisition.doppler_step=500 +;#bit_transition_flag: Enable or disable a strategy to deal with bit transitions in GPS signals: process two dwells and take +maximum test statistics. Only use with implementation: [GPS_L1_CA_PCPS_Acquisition] (should not be used for Galileo_E1_PCPS_Ambiguous_Acquisition]) +Acquisition.bit_transition_flag=false +;#max_dwells: Maximum number of consecutive dwells to be processed. It will be ignored if bit_transition_flag=true +Acquisition.max_dwells=1 ;######### ACQUISITION CHANNELS CONFIG ###### -;#The following options are specific to each channel and overwrite the generic options - +;#The following options are specific to each channel and overwrite the generic options ;######### ACQUISITION CH 0 CONFIG ############ ;Acquisition0.implementation=GPS_L1_CA_PCPS_Acquisition diff --git a/conf/gnss-sdr_acq_CCCWSR.conf b/conf/gnss-sdr_acq_CCCWSR.conf new file mode 100644 index 000000000..f7f4f4a57 --- /dev/null +++ b/conf/gnss-sdr_acq_CCCWSR.conf @@ -0,0 +1,391 @@ +; Default configuration file +; You can define your own receiver and invoke it by doing +; gnss-sdr --config_file=my_GNSS_SDR_configuration.conf +; + +[GNSS-SDR] + +;######### GLOBAL OPTIONS ################## +;internal_fs_hz: Internal signal sampling frequency after the signal conditioning stage [Hz]. +GNSS-SDR.internal_fs_hz=4000000 + +;######### CONTROL_THREAD CONFIG ############ +ControlThread.wait_for_flowgraph=false + +;######### SUPL RRLP GPS assistance configuration ##### +GNSS-SDR.SUPL_gps_enabled=false +GNSS-SDR.SUPL_read_gps_assistance_xml=true +GNSS-SDR.SUPL_gps_ephemeris_server=supl.nokia.com +GNSS-SDR.SUPL_gps_ephemeris_port=7275 +GNSS-SDR.SUPL_gps_acquisition_server=supl.google.com +GNSS-SDR.SUPL_gps_acquisition_port=7275 +GNSS-SDR.SUPL_MCC=244 +GNSS-SDR.SUPL_MNS=5 +GNSS-SDR.SUPL_LAC=0x59e2 +GNSS-SDR.SUPL_CI=0x31b0 + +;######### SIGNAL_SOURCE CONFIG ############ +;#implementation: Use [File_Signal_Source] or [UHD_Signal_Source] or [GN3S_Signal_Source] (experimental) +SignalSource.implementation=File_Signal_Source + +;#filename: path to file with the captured GNSS signal samples to be processed +SignalSource.filename=/media/DATALOGGER/Agilent GPS Generator/cap2/agilent_cap2.dat + +;#item_type: Type and resolution for each of the signal samples. Use only gr_complex in this version. +SignalSource.item_type=gr_complex + +;#sampling_frequency: Original Signal sampling frequency in [Hz] +SignalSource.sampling_frequency=4000000 + +;#freq: RF front-end center frequency in [Hz] +SignalSource.freq=1575420000 + +;#gain: Front-end Gain in [dB] +SignalSource.gain=60 + +;#subdevice: UHD subdevice specification (for USRP1 use A:0 or B:0) +SignalSource.subdevice=B:0 + +;#samples: Number of samples to be processed. Notice that 0 indicates the entire file. +SignalSource.samples=0 + +;#repeat: Repeat the processing file. Disable this option in this version +SignalSource.repeat=false + +;#dump: Dump the Signal source data to a file. Disable this option in this version +SignalSource.dump=false + +SignalSource.dump_filename=../data/signal_source.dat + + +;#enable_throttle_control: Enabling this option tells the signal source to keep the delay between samples in post processing. +; it helps to not overload the CPU, but the processing time will be longer. +SignalSource.enable_throttle_control=false + + +;######### SIGNAL_CONDITIONER CONFIG ############ +;## It holds blocks to change data type, filter and resample input data. + +;#implementation: Use [Pass_Through] or [Signal_Conditioner] +;#[Pass_Through] disables this block and the [DataTypeAdapter], [InputFilter] and [Resampler] blocks +;#[Signal_Conditioner] enables this block. Then you have to configure [DataTypeAdapter], [InputFilter] and [Resampler] blocks +;SignalConditioner.implementation=Signal_Conditioner +SignalConditioner.implementation=Pass_Through + +;######### DATA_TYPE_ADAPTER CONFIG ############ +;## Changes the type of input data. Please disable it in this version. +;#implementation: [Pass_Through] disables this block +DataTypeAdapter.implementation=Pass_Through + +;######### INPUT_FILTER CONFIG ############ +;## Filter the input data. Can be combined with frequency translation for IF signals + +;#implementation: Use [Pass_Through] or [Fir_Filter] or [Freq_Xlating_Fir_Filter] +;#[Pass_Through] disables this block +;#[Fir_Filter] enables a FIR Filter +;#[Freq_Xlating_Fir_Filter] enables FIR filter and a composite frequency translation that shifts IF down to zero Hz. + +;InputFilter.implementation=Fir_Filter +;InputFilter.implementation=Freq_Xlating_Fir_Filter +InputFilter.implementation=Pass_Through + +;#dump: Dump the filtered data to a file. +InputFilter.dump=false + +;#dump_filename: Log path and filename. +InputFilter.dump_filename=../data/input_filter.dat + +;#The following options are used in the filter design of Fir_Filter and Freq_Xlating_Fir_Filter implementation. +;#These options are based on parameters of gnuradio's function: gr_remez. +;#These function calculates the optimal (in the Chebyshev/minimax sense) FIR filter inpulse reponse given a set of band edges, the desired reponse on those bands, and the weight given to the error in those bands. + +;#input_item_type: Type and resolution for input signal samples. Use only gr_complex in this version. +InputFilter.input_item_type=gr_complex + +;#outut_item_type: Type and resolution for output filtered signal samples. Use only gr_complex in this version. +InputFilter.output_item_type=gr_complex + +;#taps_item_type: Type and resolution for the taps of the filter. Use only float in this version. +InputFilter.taps_item_type=float + +;#number_of_taps: Number of taps in the filter. Increasing this parameter increases the processing time +InputFilter.number_of_taps=5 + +;#number_of _bands: Number of frequency bands in the filter. +InputFilter.number_of_bands=2 + +;#bands: frequency at the band edges [ b1 e1 b2 e2 b3 e3 ...]. +;#Frequency is in the range [0, 1], with 1 being the Nyquist frequency (Fs/2) +;#The number of band_begin and band_end elements must match the number of bands + +InputFilter.band1_begin=0.0 +InputFilter.band1_end=0.45 +InputFilter.band2_begin=0.55 +InputFilter.band2_end=1.0 + +;#ampl: desired amplitude at the band edges [ a(b1) a(e1) a(b2) a(e2) ...]. +;#The number of ampl_begin and ampl_end elements must match the number of bands + +InputFilter.ampl1_begin=1.0 +InputFilter.ampl1_end=1.0 +InputFilter.ampl2_begin=0.0 +InputFilter.ampl2_end=0.0 + +;#band_error: weighting applied to each band (usually 1). +;#The number of band_error elements must match the number of bands +InputFilter.band1_error=1.0 +InputFilter.band2_error=1.0 + +;#filter_type: one of "bandpass", "hilbert" or "differentiator" +InputFilter.filter_type=bandpass + +;#grid_density: determines how accurately the filter will be constructed. +;The minimum value is 16; higher values are slower to compute the filter. +InputFilter.grid_density=16 + +;#The following options are used only in Freq_Xlating_Fir_Filter implementation. +;#InputFilter.IF is the intermediate frequency (in Hz) shifted down to zero Hz + +InputFilter.sampling_frequency=4000000 +InputFilter.IF=0 + + + +;######### RESAMPLER CONFIG ############ +;## Resamples the input data. + +;#implementation: Use [Pass_Through] or [Direct_Resampler] +;#[Pass_Through] disables this block +;#[Direct_Resampler] enables a resampler that implements a nearest neigbourhood interpolation +;Resampler.implementation=Direct_Resampler +Resampler.implementation=Pass_Through + +;#dump: Dump the resamplered data to a file. +Resampler.dump=false +;#dump_filename: Log path and filename. +Resampler.dump_filename=../data/resampler.dat + +;#item_type: Type and resolution for each of the signal samples. Use only gr_complex in this version. +Resampler.item_type=gr_complex + +;#sample_freq_in: the sample frequency of the input signal +Resampler.sample_freq_in=8000000 + +;#sample_freq_out: the desired sample frequency of the output signal +Resampler.sample_freq_out=4000000 + + +;######### CHANNELS GLOBAL CONFIG ############ +;#count: Number of available satellite channels. +Channels.count=6 +;#in_acquisition: Number of channels simultaneously acquiring +Channels.in_acquisition=1 +;#system: GPS, GLONASS, Galileo, SBAS or Compass +;#if the option is disabled by default is assigned GPS +Channel.system=Galileo + +;#signal: +;# "1C" GPS L1 C/A +;# "1P" GPS L1 P +;# "1W" GPS L1 Z-tracking and similar (AS on) +;# "1Y" GPS L1 Y +;# "1M" GPS L1 M +;# "1N" GPS L1 codeless +;# "2C" GPS L2 C/A +;# "2D" GPS L2 L1(C/A)+(P2-P1) semi-codeless +;# "2S" GPS L2 L2C (M) +;# "2L" GPS L2 L2C (L) +;# "2X" GPS L2 L2C (M+L) +;# "2P" GPS L2 P +;# "2W" GPS L2 Z-tracking and similar (AS on) +;# "2Y" GPS L2 Y +;# "2M" GPS GPS L2 M +;# "2N" GPS L2 codeless +;# "5I" GPS L5 I +;# "5Q" GPS L5 Q +;# "5X" GPS L5 I+Q +;# "1C" GLONASS G1 C/A +;# "1P" GLONASS G1 P +;# "2C" GLONASS G2 C/A (Glonass M) +;# "2P" GLONASS G2 P +;# "1A" GALILEO E1 A (PRS) +;# "1B" GALILEO E1 B (I/NAV OS/CS/SoL) +;# "1C" GALILEO E1 C (no data) +;# "1X" GALILEO E1 B+C +;# "1Z" GALILEO E1 A+B+C +;# "5I" GALILEO E5a I (F/NAV OS) +;# "5Q" GALILEO E5a Q (no data) +;# "5X" GALILEO E5a I+Q +;# "7I" GALILEO E5b I +;# "7Q" GALILEO E5b Q +;# "7X" GALILEO E5b I+Q +;# "8I" GALILEO E5 I +;# "8Q" GALILEO E5 Q +;# "8X" GALILEO E5 I+Q +;# "6A" GALILEO E6 A +;# "6B" GALILEO E6 B +;# "6C" GALILEO E6 C +;# "6X" GALILEO E6 B+C +;# "6Z" GALILEO E6 A+B+C +;# "1C" SBAS L1 C/A +;# "5I" SBAS L5 I +;# "5Q" SBAS L5 Q +;# "5X" SBAS L5 I+Q +;# "2I" COMPASS E2 I +;# "2Q" COMPASS E2 Q +;# "2X" COMPASS E2 IQ +;# "7I" COMPASS E5b I +;# "7Q" COMPASS E5b Q +;# "7X" COMPASS E5b IQ +;# "6I" COMPASS E6 I +;# "6Q" COMPASS E6 Q +;# "6X" COMPASS E6 IQ +;#if the option is disabled by default is assigned "1C" GPS L1 C/A +Channel.signal=1B + +;######### SPECIFIC CHANNELS CONFIG ###### +;#The following options are specific to each channel and overwrite the generic options + +;######### CHANNEL 0 CONFIG ############ + +Channel0.system=Galileo +Channel0.signal=1B + +;#satellite: Satellite PRN ID for this channel. Disable this option to random search +Channel0.satellite=11 + +;######### CHANNEL 1 CONFIG ############ + +Channel1.system=Galileo +Channel1.signal=1B +Channel1.satellite=18 + + +;######### ACQUISITION GLOBAL CONFIG ############ + +;#dump: Enable or disable the acquisition internal data file logging [true] or [false] +Acquisition.dump=false +;#filename: Log path and filename +Acquisition.dump_filename=./acq_dump.dat +;#item_type: Type and resolution for each of the signal samples. Use only gr_complex in this version. +Acquisition.item_type=gr_complex +;#if: Signal intermediate frequency in [Hz] +Acquisition.if=0 +;#sampled_ms: Signal block duration for the acquisition signal detection [ms] +Acquisition.coherent_integration_time_ms=4 +;#implementation: Acquisition algorithm selection for this channel: [Galileo_E1_PCPS_CCCWSR_Ambiguous_Acquisition] +Acquisition.implementation=Galileo_E1_PCPS_CCCWSR_Ambiguous_Acquisition +;#threshold: Acquisition threshold. +Acquisition.threshold=0.0025 +;#doppler_max: Maximum expected Doppler shift [Hz] +Acquisition.doppler_max=10000 +;#doppler_max: Doppler step in the grid search [Hz] +Acquisition.doppler_step=500 +;#max_dwells: Maximum number of consecutive dwells to be processed. It will be ignored if bit_transition_flag=true +Acquisition.max_dwells=1 + +;######### ACQUISITION CHANNELS CONFIG ###### +;#The following options are specific to each channel and overwrite the generic options + +;######### ACQUISITION CH 0 CONFIG ############ +;Acquisition0.implementation=Galileo_E1_PCPS_CCCWSR_Ambiguous_Acquisition +;Acquisition0.threshold=0.0025 +;Acquisition0.doppler_max=10000 +;Acquisition0.doppler_step=250 + +;#repeat_satellite: Use only jointly with the satellite PRN ID option. The default value is false +;Acquisition0.repeat_satellite = false + +;######### ACQUISITION CH 1 CONFIG ############ +;Acquisition1.implementation=Galileo_E1_PCPS_CCCWSR_Ambiguous_Acquisition +;Acquisition1.threshold=0.0025 +;Acquisition1.doppler_max=10000 +;Acquisition1.doppler_step=250 +;Acquisition1.repeat_satellite = false + +;######### TRACKING GLOBAL CONFIG ############ + +;#implementation: Selected tracking algorithm: [GPS_L1_CA_DLL_PLL_Tracking] or [GPS_L1_CA_DLL_FLL_PLL_Tracking] +Tracking.implementation=GPS_L1_CA_DLL_PLL_Optim_Tracking +;#item_type: Type and resolution for each of the signal samples. Use only [gr_complex] in this version. +Tracking.item_type=gr_complex + +;#sampling_frequency: Signal Intermediate Frequency in [Hz] +Tracking.if=0 + +;#dump: Enable or disable the Tracking internal binary data file logging [true] or [false] +Tracking.dump=false + +;#dump_filename: Log path and filename. Notice that the tracking channel will add "x.dat" where x is the channel number. +Tracking.dump_filename=./tracking_ch_ + +;#pll_bw_hz: PLL loop filter bandwidth [Hz] +Tracking.pll_bw_hz=50.0; + +;#dll_bw_hz: DLL loop filter bandwidth [Hz] +Tracking.dll_bw_hz=2.0; + +;#fll_bw_hz: FLL loop filter bandwidth [Hz] +Tracking.fll_bw_hz=10.0; + +;#order: PLL/DLL loop filter order [2] or [3] +Tracking.order=3; + +;#early_late_space_chips: correlator early-late space [chips]. Use [0.5] +Tracking.early_late_space_chips=0.5; + +;######### TELEMETRY DECODER CONFIG ############ +;#implementation: Use [GPS_L1_CA_Telemetry_Decoder] for GPS L1 C/A. +TelemetryDecoder.implementation=GPS_L1_CA_Telemetry_Decoder +TelemetryDecoder.dump=false + +;######### OBSERVABLES CONFIG ############ +;#implementation: Use [GPS_L1_CA_Observables] for GPS L1 C/A. +Observables.implementation=GPS_L1_CA_Observables + +;#dump: Enable or disable the Observables internal binary data file logging [true] or [false] +Observables.dump=false + +;#dump_filename: Log path and filename. +Observables.dump_filename=./observables.dat + + +;######### PVT CONFIG ############ +;#implementation: Position Velocity and Time (PVT) implementation algorithm: Use [GPS_L1_CA_PVT] in this version. +PVT.implementation=GPS_L1_CA_PVT + +;#averaging_depth: Number of PVT observations in the moving average algorithm +PVT.averaging_depth=10 + +;#flag_average: Enables the PVT averaging between output intervals (arithmetic mean) [true] or [false] +PVT.flag_averaging=true + +;#output_rate_ms: Period between two PVT outputs. Notice that the minimum period is equal to the tracking integration time (for GPS CA L1 is 1ms) [ms] +PVT.output_rate_ms=100 + +;#display_rate_ms: Position console print (std::out) interval [ms]. Notice that output_rate_ms<=display_rate_ms. +PVT.display_rate_ms=500 + +;# RINEX, KML, and NMEA output configuration + +;#dump_filename: Log path and filename without extension. Notice that PVT will add ".dat" to the binary dump and ".kml" to GoogleEarth dump. +PVT.dump_filename=./PVT + +;#nmea_dump_filename: NMEA log path and filename +PVT.nmea_dump_filename=./gnss_sdr_pvt.nmea; + +;#flag_nmea_tty_port: Enable or disable the NMEA log to a serial TTY port (Can be used with real hardware or virtual one) +PVT.flag_nmea_tty_port=true; + +;#nmea_dump_devname: serial device descriptor for NMEA logging +PVT.nmea_dump_devname=/dev/pts/4 + + +;#dump: Enable or disable the PVT internal binary data file logging [true] or [false] +PVT.dump=false + +;######### OUTPUT_FILTER CONFIG ############ +;# Receiver output filter: Leave this block disabled in this version +OutputFilter.implementation=Null_Sink_Output_Filter +OutputFilter.filename=data/gnss-sdr.dat +OutputFilter.item_type=gr_complex diff --git a/conf/gnss-sdr_acq_Tong.conf b/conf/gnss-sdr_acq_Tong.conf new file mode 100644 index 000000000..255cdb0af --- /dev/null +++ b/conf/gnss-sdr_acq_Tong.conf @@ -0,0 +1,393 @@ +; Default configuration file +; You can define your own receiver and invoke it by doing +; gnss-sdr --config_file=my_GNSS_SDR_configuration.conf +; + +[GNSS-SDR] + +;######### GLOBAL OPTIONS ################## +;internal_fs_hz: Internal signal sampling frequency after the signal conditioning stage [Hz]. +GNSS-SDR.internal_fs_hz=4000000 + +;######### CONTROL_THREAD CONFIG ############ +ControlThread.wait_for_flowgraph=false + +;######### SUPL RRLP GPS assistance configuration ##### +GNSS-SDR.SUPL_gps_enabled=false +GNSS-SDR.SUPL_read_gps_assistance_xml=true +GNSS-SDR.SUPL_gps_ephemeris_server=supl.nokia.com +GNSS-SDR.SUPL_gps_ephemeris_port=7275 +GNSS-SDR.SUPL_gps_acquisition_server=supl.google.com +GNSS-SDR.SUPL_gps_acquisition_port=7275 +GNSS-SDR.SUPL_MCC=244 +GNSS-SDR.SUPL_MNS=5 +GNSS-SDR.SUPL_LAC=0x59e2 +GNSS-SDR.SUPL_CI=0x31b0 + +;######### SIGNAL_SOURCE CONFIG ############ +;#implementation: Use [File_Signal_Source] or [UHD_Signal_Source] or [GN3S_Signal_Source] (experimental) +SignalSource.implementation=File_Signal_Source + +;#filename: path to file with the captured GNSS signal samples to be processed +SignalSource.filename=/media/DATALOGGER/Agilent GPS Generator/cap2/agilent_cap2.dat + +;#item_type: Type and resolution for each of the signal samples. Use only gr_complex in this version. +SignalSource.item_type=gr_complex + +;#sampling_frequency: Original Signal sampling frequency in [Hz] +SignalSource.sampling_frequency=4000000 + +;#freq: RF front-end center frequency in [Hz] +SignalSource.freq=1575420000 + +;#gain: Front-end Gain in [dB] +SignalSource.gain=60 + +;#subdevice: UHD subdevice specification (for USRP1 use A:0 or B:0) +SignalSource.subdevice=B:0 + +;#samples: Number of samples to be processed. Notice that 0 indicates the entire file. +SignalSource.samples=0 + +;#repeat: Repeat the processing file. Disable this option in this version +SignalSource.repeat=false + +;#dump: Dump the Signal source data to a file. Disable this option in this version +SignalSource.dump=false + +SignalSource.dump_filename=../data/signal_source.dat + + +;#enable_throttle_control: Enabling this option tells the signal source to keep the delay between samples in post processing. +; it helps to not overload the CPU, but the processing time will be longer. +SignalSource.enable_throttle_control=false + + +;######### SIGNAL_CONDITIONER CONFIG ############ +;## It holds blocks to change data type, filter and resample input data. + +;#implementation: Use [Pass_Through] or [Signal_Conditioner] +;#[Pass_Through] disables this block and the [DataTypeAdapter], [InputFilter] and [Resampler] blocks +;#[Signal_Conditioner] enables this block. Then you have to configure [DataTypeAdapter], [InputFilter] and [Resampler] blocks +;SignalConditioner.implementation=Signal_Conditioner +SignalConditioner.implementation=Pass_Through + +;######### DATA_TYPE_ADAPTER CONFIG ############ +;## Changes the type of input data. Please disable it in this version. +;#implementation: [Pass_Through] disables this block +DataTypeAdapter.implementation=Pass_Through + +;######### INPUT_FILTER CONFIG ############ +;## Filter the input data. Can be combined with frequency translation for IF signals + +;#implementation: Use [Pass_Through] or [Fir_Filter] or [Freq_Xlating_Fir_Filter] +;#[Pass_Through] disables this block +;#[Fir_Filter] enables a FIR Filter +;#[Freq_Xlating_Fir_Filter] enables FIR filter and a composite frequency translation that shifts IF down to zero Hz. + +;InputFilter.implementation=Fir_Filter +;InputFilter.implementation=Freq_Xlating_Fir_Filter +InputFilter.implementation=Pass_Through + +;#dump: Dump the filtered data to a file. +InputFilter.dump=false + +;#dump_filename: Log path and filename. +InputFilter.dump_filename=../data/input_filter.dat + +;#The following options are used in the filter design of Fir_Filter and Freq_Xlating_Fir_Filter implementation. +;#These options are based on parameters of gnuradio's function: gr_remez. +;#These function calculates the optimal (in the Chebyshev/minimax sense) FIR filter inpulse reponse given a set of band edges, the desired reponse on those bands, and the weight given to the error in those bands. + +;#input_item_type: Type and resolution for input signal samples. Use only gr_complex in this version. +InputFilter.input_item_type=gr_complex + +;#outut_item_type: Type and resolution for output filtered signal samples. Use only gr_complex in this version. +InputFilter.output_item_type=gr_complex + +;#taps_item_type: Type and resolution for the taps of the filter. Use only float in this version. +InputFilter.taps_item_type=float + +;#number_of_taps: Number of taps in the filter. Increasing this parameter increases the processing time +InputFilter.number_of_taps=5 + +;#number_of _bands: Number of frequency bands in the filter. +InputFilter.number_of_bands=2 + +;#bands: frequency at the band edges [ b1 e1 b2 e2 b3 e3 ...]. +;#Frequency is in the range [0, 1], with 1 being the Nyquist frequency (Fs/2) +;#The number of band_begin and band_end elements must match the number of bands + +InputFilter.band1_begin=0.0 +InputFilter.band1_end=0.45 +InputFilter.band2_begin=0.55 +InputFilter.band2_end=1.0 + +;#ampl: desired amplitude at the band edges [ a(b1) a(e1) a(b2) a(e2) ...]. +;#The number of ampl_begin and ampl_end elements must match the number of bands + +InputFilter.ampl1_begin=1.0 +InputFilter.ampl1_end=1.0 +InputFilter.ampl2_begin=0.0 +InputFilter.ampl2_end=0.0 + +;#band_error: weighting applied to each band (usually 1). +;#The number of band_error elements must match the number of bands +InputFilter.band1_error=1.0 +InputFilter.band2_error=1.0 + +;#filter_type: one of "bandpass", "hilbert" or "differentiator" +InputFilter.filter_type=bandpass + +;#grid_density: determines how accurately the filter will be constructed. +;The minimum value is 16; higher values are slower to compute the filter. +InputFilter.grid_density=16 + +;#The following options are used only in Freq_Xlating_Fir_Filter implementation. +;#InputFilter.IF is the intermediate frequency (in Hz) shifted down to zero Hz + +InputFilter.sampling_frequency=4000000 +InputFilter.IF=0 + + + +;######### RESAMPLER CONFIG ############ +;## Resamples the input data. + +;#implementation: Use [Pass_Through] or [Direct_Resampler] +;#[Pass_Through] disables this block +;#[Direct_Resampler] enables a resampler that implements a nearest neigbourhood interpolation +;Resampler.implementation=Direct_Resampler +Resampler.implementation=Pass_Through + +;#dump: Dump the resamplered data to a file. +Resampler.dump=false +;#dump_filename: Log path and filename. +Resampler.dump_filename=../data/resampler.dat + +;#item_type: Type and resolution for each of the signal samples. Use only gr_complex in this version. +Resampler.item_type=gr_complex + +;#sample_freq_in: the sample frequency of the input signal +Resampler.sample_freq_in=8000000 + +;#sample_freq_out: the desired sample frequency of the output signal +Resampler.sample_freq_out=4000000 + + +;######### CHANNELS GLOBAL CONFIG ############ +;#count: Number of available satellite channels. +Channels.count=6 +;#in_acquisition: Number of channels simultaneously acquiring +Channels.in_acquisition=1 +;#system: GPS, GLONASS, Galileo, SBAS or Compass +;#if the option is disabled by default is assigned GPS +Channel.system=GPS + +;#signal: +;# "1C" GPS L1 C/A +;# "1P" GPS L1 P +;# "1W" GPS L1 Z-tracking and similar (AS on) +;# "1Y" GPS L1 Y +;# "1M" GPS L1 M +;# "1N" GPS L1 codeless +;# "2C" GPS L2 C/A +;# "2D" GPS L2 L1(C/A)+(P2-P1) semi-codeless +;# "2S" GPS L2 L2C (M) +;# "2L" GPS L2 L2C (L) +;# "2X" GPS L2 L2C (M+L) +;# "2P" GPS L2 P +;# "2W" GPS L2 Z-tracking and similar (AS on) +;# "2Y" GPS L2 Y +;# "2M" GPS GPS L2 M +;# "2N" GPS L2 codeless +;# "5I" GPS L5 I +;# "5Q" GPS L5 Q +;# "5X" GPS L5 I+Q +;# "1C" GLONASS G1 C/A +;# "1P" GLONASS G1 P +;# "2C" GLONASS G2 C/A (Glonass M) +;# "2P" GLONASS G2 P +;# "1A" GALILEO E1 A (PRS) +;# "1B" GALILEO E1 B (I/NAV OS/CS/SoL) +;# "1C" GALILEO E1 C (no data) +;# "1X" GALILEO E1 B+C +;# "1Z" GALILEO E1 A+B+C +;# "5I" GALILEO E5a I (F/NAV OS) +;# "5Q" GALILEO E5a Q (no data) +;# "5X" GALILEO E5a I+Q +;# "7I" GALILEO E5b I +;# "7Q" GALILEO E5b Q +;# "7X" GALILEO E5b I+Q +;# "8I" GALILEO E5 I +;# "8Q" GALILEO E5 Q +;# "8X" GALILEO E5 I+Q +;# "6A" GALILEO E6 A +;# "6B" GALILEO E6 B +;# "6C" GALILEO E6 C +;# "6X" GALILEO E6 B+C +;# "6Z" GALILEO E6 A+B+C +;# "1C" SBAS L1 C/A +;# "5I" SBAS L5 I +;# "5Q" SBAS L5 Q +;# "5X" SBAS L5 I+Q +;# "2I" COMPASS E2 I +;# "2Q" COMPASS E2 Q +;# "2X" COMPASS E2 IQ +;# "7I" COMPASS E5b I +;# "7Q" COMPASS E5b Q +;# "7X" COMPASS E5b IQ +;# "6I" COMPASS E6 I +;# "6Q" COMPASS E6 Q +;# "6X" COMPASS E6 IQ +;#if the option is disabled by default is assigned "1C" GPS L1 C/A +Channel.signal=1C + +;######### SPECIFIC CHANNELS CONFIG ###### +;#The following options are specific to each channel and overwrite the generic options + +;######### CHANNEL 0 CONFIG ############ + +Channel0.system=GPS +Channel0.signal=1C + +;#satellite: Satellite PRN ID for this channel. Disable this option to random search +Channel0.satellite=11 + +;######### CHANNEL 1 CONFIG ############ + +Channel1.system=GPS +Channel1.signal=1C +Channel1.satellite=18 + + +;######### ACQUISITION GLOBAL CONFIG ############ + +;#dump: Enable or disable the acquisition internal data file logging [true] or [false] +Acquisition.dump=false +;#filename: Log path and filename +Acquisition.dump_filename=./acq_dump.dat +;#item_type: Type and resolution for each of the signal samples. Use only gr_complex in this version. +Acquisition.item_type=gr_complex +;#if: Signal intermediate frequency in [Hz] +Acquisition.if=0 +;#sampled_ms: Signal block duration for the acquisition signal detection [ms] +Acquisition.coherent_integration_time_ms=1 +;#implementation: Acquisition algorithm selection for this channel: [GPS_L1_CA_PCPS_Tong_Acquisition] or [Galileo_E1_PCPS_Tong_Ambiguous_Acquisition] +Acquisition.implementation=GPS_L1_CA_PCPS_Tong_Acquisition +;#threshold: Acquisition threshold. +Acquisition.threshold=0.004 +;#doppler_max: Maximum expected Doppler shift [Hz] +Acquisition.doppler_max=10000 +;#doppler_max: Doppler step in the grid search [Hz] +Acquisition.doppler_step=500 +;#tong_init_val: Initial value for the Tong counter. +Acquisition.tong_init_val=5 +;#tong_max_val: Maximum value for the Tong counter. +Acquisition.tong_max_val=10 + +;######### ACQUISITION CHANNELS CONFIG ###### +;#The following options are specific to each channel and overwrite the generic options + +;######### ACQUISITION CH 0 CONFIG ############ +;Acquisition0.implementation=GPS_L1_CA_PCPS_Tong_Acquisition +;Acquisition0.threshold=0.004 +;Acquisition0.doppler_max=10000 +;Acquisition0.doppler_step=250 + +;#repeat_satellite: Use only jointly with the satellite PRN ID option. The default value is false +;Acquisition0.repeat_satellite = false + +;######### ACQUISITION CH 1 CONFIG ############ +;Acquisition1.implementation=GPS_L1_CA_PCPS_Tong_Acquisition +;Acquisition1.threshold=0.004 +;Acquisition1.doppler_max=10000 +;Acquisition1.doppler_step=250 +;Acquisition1.repeat_satellite = false + +;######### TRACKING GLOBAL CONFIG ############ + +;#implementation: Selected tracking algorithm: [GPS_L1_CA_DLL_PLL_Tracking] or [GPS_L1_CA_DLL_FLL_PLL_Tracking] +Tracking.implementation=GPS_L1_CA_DLL_PLL_Optim_Tracking +;#item_type: Type and resolution for each of the signal samples. Use only [gr_complex] in this version. +Tracking.item_type=gr_complex + +;#sampling_frequency: Signal Intermediate Frequency in [Hz] +Tracking.if=0 + +;#dump: Enable or disable the Tracking internal binary data file logging [true] or [false] +Tracking.dump=false + +;#dump_filename: Log path and filename. Notice that the tracking channel will add "x.dat" where x is the channel number. +Tracking.dump_filename=./tracking_ch_ + +;#pll_bw_hz: PLL loop filter bandwidth [Hz] +Tracking.pll_bw_hz=50.0; + +;#dll_bw_hz: DLL loop filter bandwidth [Hz] +Tracking.dll_bw_hz=2.0; + +;#fll_bw_hz: FLL loop filter bandwidth [Hz] +Tracking.fll_bw_hz=10.0; + +;#order: PLL/DLL loop filter order [2] or [3] +Tracking.order=3; + +;#early_late_space_chips: correlator early-late space [chips]. Use [0.5] +Tracking.early_late_space_chips=0.5; + +;######### TELEMETRY DECODER CONFIG ############ +;#implementation: Use [GPS_L1_CA_Telemetry_Decoder] for GPS L1 C/A. +TelemetryDecoder.implementation=GPS_L1_CA_Telemetry_Decoder +TelemetryDecoder.dump=false + +;######### OBSERVABLES CONFIG ############ +;#implementation: Use [GPS_L1_CA_Observables] for GPS L1 C/A. +Observables.implementation=GPS_L1_CA_Observables + +;#dump: Enable or disable the Observables internal binary data file logging [true] or [false] +Observables.dump=false + +;#dump_filename: Log path and filename. +Observables.dump_filename=./observables.dat + + +;######### PVT CONFIG ############ +;#implementation: Position Velocity and Time (PVT) implementation algorithm: Use [GPS_L1_CA_PVT] in this version. +PVT.implementation=GPS_L1_CA_PVT + +;#averaging_depth: Number of PVT observations in the moving average algorithm +PVT.averaging_depth=10 + +;#flag_average: Enables the PVT averaging between output intervals (arithmetic mean) [true] or [false] +PVT.flag_averaging=true + +;#output_rate_ms: Period between two PVT outputs. Notice that the minimum period is equal to the tracking integration time (for GPS CA L1 is 1ms) [ms] +PVT.output_rate_ms=100 + +;#display_rate_ms: Position console print (std::out) interval [ms]. Notice that output_rate_ms<=display_rate_ms. +PVT.display_rate_ms=500 + +;# RINEX, KML, and NMEA output configuration + +;#dump_filename: Log path and filename without extension. Notice that PVT will add ".dat" to the binary dump and ".kml" to GoogleEarth dump. +PVT.dump_filename=./PVT + +;#nmea_dump_filename: NMEA log path and filename +PVT.nmea_dump_filename=./gnss_sdr_pvt.nmea; + +;#flag_nmea_tty_port: Enable or disable the NMEA log to a serial TTY port (Can be used with real hardware or virtual one) +PVT.flag_nmea_tty_port=true; + +;#nmea_dump_devname: serial device descriptor for NMEA logging +PVT.nmea_dump_devname=/dev/pts/4 + + +;#dump: Enable or disable the PVT internal binary data file logging [true] or [false] +PVT.dump=false + +;######### OUTPUT_FILTER CONFIG ############ +;# Receiver output filter: Leave this block disabled in this version +OutputFilter.implementation=Null_Sink_Output_Filter +OutputFilter.filename=data/gnss-sdr.dat +OutputFilter.item_type=gr_complex diff --git a/src/algorithms/acquisition/adapters/CMakeLists.txt b/src/algorithms/acquisition/adapters/CMakeLists.txt index 57ce9e1d3..631ad5f78 100644 --- a/src/algorithms/acquisition/adapters/CMakeLists.txt +++ b/src/algorithms/acquisition/adapters/CMakeLists.txt @@ -17,10 +17,15 @@ # set(ACQ_ADAPTER_SOURCES - galileo_e1_pcps_ambiguous_acquisition.cc - gps_l1_ca_pcps_acquisition.cc + gps_l1_ca_pcps_acquisition.cc + gps_l1_ca_pcps_multithread_acquisition.cc gps_l1_ca_pcps_assisted_acquisition.cc gps_l1_ca_pcps_acquisition_fine_doppler.cc + gps_l1_ca_pcps_tong_acquisition.cc + galileo_e1_pcps_ambiguous_acquisition.cc + galileo_e1_pcps_cccwsr_ambiguous_acquisition.cc + galileo_e1_pcps_tong_ambiguous_acquisition.cc + galileo_e1_pcps_8ms_ambiguous_acquisition.cc ) include_directories( diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.cc new file mode 100644 index 000000000..307f8168c --- /dev/null +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.cc @@ -0,0 +1,312 @@ +/*! + * \file galileo_e1_pcps_8ms_ambiguous_acquisition.cc + * \brief Adapts a Galileo PCPS 8ms acquisition block to an + * AcquisitionInterface for Galileo E1 Signals + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "galileo_e1_pcps_8ms_ambiguous_acquisition.h" +#include "galileo_e1_signal_processing.h" +#include "Galileo_E1.h" +#include "configuration_interface.h" +#include +#include +#include +#include +#include +#include + +using google::LogMessage; + +GalileoE1Pcps8msAmbiguousAcquisition::GalileoE1Pcps8msAmbiguousAcquisition( + ConfigurationInterface* configuration, std::string role, + unsigned int in_streams, unsigned int out_streams, + boost::shared_ptr queue) : + role_(role), in_streams_(in_streams), out_streams_(out_streams), queue_(queue) +{ + configuration_ = configuration; + std::string default_item_type = "gr_complex"; + std::string default_dump_filename = "../data/acquisition.dat"; + + DLOG(INFO) << "role " << role; + + item_type_ = configuration_->property(role + ".item_type", + default_item_type); + + fs_in_ = configuration_->property("GNSS-SDR.internal_fs_hz", 4000000); + if_ = configuration_->property(role + ".ifreq", 0); + dump_ = configuration_->property(role + ".dump", false); + shift_resolution_ = configuration_->property(role + ".doppler_max", 15); + sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 4); + + if (sampled_ms_ % 4 != 0) + { + sampled_ms_ = (int)(sampled_ms_/4) * 4; + LOG_AT_LEVEL(WARNING) << "coherent_integration_time should be multiple of " + << "Galileo code length (4 ms). coherent_integration_time = " + << sampled_ms_ << " ms will be used."; + + } + + max_dwells_ = configuration_->property(role + ".max_dwells", 1); + + dump_filename_ = configuration_->property(role + ".dump_filename", + default_dump_filename); + + //--- Find number of samples per spreading code (4 ms) ----------------- + + code_length_ = round( + fs_in_ + / (Galileo_E1_CODE_CHIP_RATE_HZ + / Galileo_E1_B_CODE_LENGTH_CHIPS)); + + vector_length_ = code_length_ * (int)(sampled_ms_/4); + + int samples_per_ms = code_length_ / 4; + + code_ = new gr_complex[vector_length_]; + + if (item_type_.compare("gr_complex") == 0) + { + item_size_ = sizeof(gr_complex); + acquisition_cc_ = galileo_pcps_8ms_make_acquisition_cc(sampled_ms_, max_dwells_, + shift_resolution_, if_, fs_in_, samples_per_ms, code_length_, + queue_, dump_, dump_filename_); + stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_, vector_length_); + DLOG(INFO) << "stream_to_vector(" + << stream_to_vector_->unique_id() << ")"; + DLOG(INFO) << "acquisition(" << acquisition_cc_->unique_id() + << ")"; + } + else + { + LOG_AT_LEVEL(WARNING) << item_type_ + << " unknown acquisition item type"; + } +} + + +GalileoE1Pcps8msAmbiguousAcquisition::~GalileoE1Pcps8msAmbiguousAcquisition() +{ + delete[] code_; +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::set_channel(unsigned int channel) +{ + channel_ = channel; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel(channel_); + } +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::set_threshold(float threshold) +{ + + float pfa = configuration_->property(role_+ boost::lexical_cast(channel_) + ".pfa", 0.0); + + if(pfa==0.0) pfa = configuration_->property(role_+".pfa", 0.0); + + if(pfa==0.0) + { + threshold_ = threshold; + } + else + { + threshold_ = calculate_threshold(pfa); + } + + DLOG(INFO) <<"Channel "<set_threshold(threshold_); + } +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::set_doppler_max(unsigned int doppler_max) +{ + doppler_max_ = doppler_max; + + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_max(doppler_max_); + } +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::set_doppler_step(unsigned int doppler_step) +{ + doppler_step_ = doppler_step; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_step(doppler_step_); + } +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::set_channel_queue( + concurrent_queue *channel_internal_queue) +{ + channel_internal_queue_ = channel_internal_queue; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel_queue(channel_internal_queue_); + } +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::set_gnss_synchro( + Gnss_Synchro* gnss_synchro) +{ + gnss_synchro_ = gnss_synchro; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_gnss_synchro(gnss_synchro_); + } +} + + +signed int +GalileoE1Pcps8msAmbiguousAcquisition::mag() +{ + if (item_type_.compare("gr_complex") == 0) + { + return acquisition_cc_->mag(); + } + else + { + return 0; + } +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::init() +{ + acquisition_cc_->init(); + set_local_code(); +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::set_local_code() +{ + if (item_type_.compare("gr_complex") == 0) + { + bool cboc = configuration_->property( + "Acquisition" + boost::lexical_cast(channel_) + + ".cboc", false); + + std::complex * code = new std::complex[code_length_]; + + galileo_e1_code_gen_complex_sampled(code, gnss_synchro_->Signal, + cboc, gnss_synchro_->PRN, fs_in_, 0, false); + + for (unsigned int i = 0; i < sampled_ms_/4; i++) + { + memcpy(&(code_[i*code_length_]), code, + sizeof(gr_complex)*code_length_); + } + + acquisition_cc_->set_local_code(code_); + + delete[] code; + } +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::reset() +{ + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_active(true); + } +} + +float GalileoE1Pcps8msAmbiguousAcquisition::calculate_threshold(float pfa) +{ + unsigned int frequency_bins = 0; + for (int doppler = (int)(-doppler_max_); doppler <= (int)doppler_max_; doppler += doppler_step_) + { + frequency_bins++; + } + + DLOG(INFO) <<"Channel "<connect(stream_to_vector_, 0, acquisition_cc_, 0); + } +} + + +void +GalileoE1Pcps8msAmbiguousAcquisition::disconnect(gr::top_block_sptr top_block) +{ + if (item_type_.compare("gr_complex") == 0) + { + top_block->disconnect(stream_to_vector_, 0, acquisition_cc_, 0); + } +} + + +gr::basic_block_sptr GalileoE1Pcps8msAmbiguousAcquisition::get_left_block() +{ + return stream_to_vector_; +} + + +gr::basic_block_sptr GalileoE1Pcps8msAmbiguousAcquisition::get_right_block() +{ + return acquisition_cc_; +} + diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.h b/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.h new file mode 100644 index 000000000..8cd210b65 --- /dev/null +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.h @@ -0,0 +1,159 @@ +/*! + * \file galileo_e1_pcps_8ms_ambiguous_acquisition.h + * \brief Adapts a PCPS 8ms acquisition block to an + * AcquisitionInterface for Galileo E1 Signals + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_GALILEO_E1_PCPS_8MS_AMBIGUOUS_ACQUISITION_H_ +#define GNSS_SDR_GALILEO_E1_PCPS_8MS_AMBIGUOUS_ACQUISITION_H_ + +#include "gnss_synchro.h" +#include "acquisition_interface.h" +#include "galileo_pcps_8ms_acquisition_cc.h" +#include +#include + +class ConfigurationInterface; + +/*! + * \brief Adapts a PCPS 8ms acquisition block to an + * AcquisitionInterface for Galileo E1 Signals + */ +class GalileoE1Pcps8msAmbiguousAcquisition: public AcquisitionInterface +{ +public: + GalileoE1Pcps8msAmbiguousAcquisition(ConfigurationInterface* configuration, + std::string role, unsigned int in_streams, + unsigned int out_streams, boost::shared_ptr queue); + + virtual ~GalileoE1Pcps8msAmbiguousAcquisition(); + + std::string role() + { + return role_; + } + + /*! + * \brief Returns "Galileo_E1_PCPS_8ms_Ambiguous_Acquisition" + */ + std::string implementation() + { + return "Galileo_E1_PCPS_8ms_Ambiguous_Acquisition"; + } + size_t item_size() + { + return item_size_; + } + + void connect(gr::top_block_sptr top_block); + void disconnect(gr::top_block_sptr top_block); + gr::basic_block_sptr get_left_block(); + gr::basic_block_sptr get_right_block(); + + /*! + * \brief Set acquisition/tracking common Gnss_Synchro object pointer + * to efficiently exchange synchronization data between acquisition and + * tracking blocks + */ + void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro); + + /*! + * \brief Set acquisition channel unique ID + */ + void set_channel(unsigned int channel); + + /*! + * \brief Set statistics threshold of PCPS algorithm + */ + void set_threshold(float threshold); + + /*! + * \brief Set maximum Doppler off grid search + */ + void set_doppler_max(unsigned int doppler_max); + + /*! + * \brief Set Doppler steps for the grid search + */ + void set_doppler_step(unsigned int doppler_step); + + /*! + * \brief Set tracking channel internal queue + */ + void set_channel_queue(concurrent_queue *channel_internal_queue); + + /*! + * \brief Initializes acquisition algorithm. + */ + void init(); + + /*! + * \brief Sets local code for Galileo E1 PCPS acquisition algorithm. + */ + void set_local_code(); + + /*! + * \brief Returns the maximum peak of grid search + */ + signed int mag(); + + /*! + * \brief Restart acquisition algorithm + */ + void reset(); + +private: + ConfigurationInterface* configuration_; + galileo_pcps_8ms_acquisition_cc_sptr acquisition_cc_; + gr::blocks::stream_to_vector::sptr stream_to_vector_; + size_t item_size_; + std::string item_type_; + unsigned int vector_length_; + unsigned int code_length_; + unsigned int channel_; + float threshold_; + unsigned int doppler_max_; + unsigned int doppler_step_; + unsigned int shift_resolution_; + unsigned int sampled_ms_; + unsigned int max_dwells_; + long fs_in_; + long if_; + bool dump_; + std::string dump_filename_; + std::complex * code_; + Gnss_Synchro * gnss_synchro_; + std::string role_; + unsigned int in_streams_; + unsigned int out_streams_; + boost::shared_ptr queue_; + concurrent_queue *channel_internal_queue_; + float calculate_threshold(float pfa); +}; + +#endif /* GNSS_SDR_GALILEO_E1_PCPS_8MS_AMBIGUOUS_ACQUISITION_H_ */ diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.cc index f00287c1a..533626c2e 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.cc +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.cc @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------- * - * Copyright (C) 2010-2011 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) * * GNSS-SDR is a software defined Global Navigation * Satellite Systems receiver @@ -61,30 +61,51 @@ GalileoE1PcpsAmbiguousAcquisition::GalileoE1PcpsAmbiguousAcquisition( if_ = configuration_->property(role + ".ifreq", 0); dump_ = configuration_->property(role + ".dump", false); shift_resolution_ = configuration_->property(role + ".doppler_max", 15); - sampled_ms_ = configuration_->property(role + ".sampled_ms", 4); + sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 4); + + if (sampled_ms_ % 4 != 0) + { + sampled_ms_ = (int)(sampled_ms_/4) * 4; + LOG_AT_LEVEL(WARNING) << "coherent_integration_time should be multiple of " + << "Galileo code length (4 ms). coherent_integration_time = " + << sampled_ms_ << " ms will be used."; + + } + + bit_transition_flag_ = configuration_->property(role + ".bit_transition_flag", false); + + if (!bit_transition_flag_) + { + max_dwells_ = configuration_->property(role + ".max_dwells", 1); + } + else + { + max_dwells_ = 2; + } + dump_filename_ = configuration_->property(role + ".dump_filename", default_dump_filename); //--- Find number of samples per spreading code (4 ms) ----------------- - vector_length_ = round( + code_length_ = round( fs_in_ / (Galileo_E1_CODE_CHIP_RATE_HZ / Galileo_E1_B_CODE_LENGTH_CHIPS)); - int samples_per_ms = vector_length_ / 4; + vector_length_ = code_length_ * (int)(sampled_ms_/4); - vector_length_ = samples_per_ms * 4; + int samples_per_ms = code_length_ / 4; - code_ = new gr_complex[samples_per_ms*sampled_ms_]; + code_ = new gr_complex[vector_length_]; if (item_type_.compare("gr_complex") == 0) { item_size_ = sizeof(gr_complex); - acquisition_cc_ = pcps_make_acquisition_cc(sampled_ms_, - shift_resolution_, if_, fs_in_, samples_per_ms, vector_length_, - queue_, dump_, dump_filename_); - stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_, samples_per_ms * sampled_ms_); + acquisition_cc_ = pcps_make_acquisition_cc(sampled_ms_, max_dwells_, + shift_resolution_, if_, fs_in_, samples_per_ms, code_length_, + bit_transition_flag_, queue_, dump_, dump_filename_); + stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_, vector_length_); DLOG(INFO) << "stream_to_vector(" << stream_to_vector_->unique_id() << ")"; DLOG(INFO) << "acquisition(" << acquisition_cc_->unique_id() @@ -124,13 +145,13 @@ GalileoE1PcpsAmbiguousAcquisition::set_threshold(float threshold) if(pfa==0.0) pfa = configuration_->property(role_+".pfa", 0.0); if(pfa==0.0) - { - threshold_ = threshold; - } + { + threshold_ = threshold; + } else - { - threshold_ = calculate_threshold(pfa); - } + { + threshold_ = calculate_threshold(pfa); + } DLOG(INFO) <<"Channel "<(channel_) + ".cboc", false); - std::complex * code = new std::complex[vector_length_]; + std::complex * code = new std::complex[code_length_]; galileo_e1_code_gen_complex_sampled(code, gnss_synchro_->Signal, cboc, gnss_synchro_->PRN, fs_in_, 0, false); for (unsigned int i = 0; i < sampled_ms_/4; i++) { - memcpy(&(code_[i*vector_length_]), code, - sizeof(gr_complex)*vector_length_); + memcpy(&(code_[i*code_length_]), code, + sizeof(gr_complex)*code_length_); } acquisition_cc_->set_local_code(code_); + + delete[] code; } } @@ -255,14 +277,14 @@ float GalileoE1PcpsAmbiguousAcquisition::calculate_threshold(float pfa) DLOG(INFO) <<"Channel "< +#include +#include +#include +#include +#include +#include + + +using google::LogMessage; + +GalileoE1PcpsCccwsrAmbiguousAcquisition::GalileoE1PcpsCccwsrAmbiguousAcquisition( + ConfigurationInterface* configuration, std::string role, + unsigned int in_streams, unsigned int out_streams, + boost::shared_ptr queue) : + role_(role), in_streams_(in_streams), out_streams_(out_streams), queue_(queue) +{ + configuration_ = configuration; + std::string default_item_type = "gr_complex"; + std::string default_dump_filename = "../data/acquisition.dat"; + + DLOG(INFO) << "role " << role; + + item_type_ = configuration_->property(role + ".item_type", + default_item_type); + + fs_in_ = configuration_->property("GNSS-SDR.internal_fs_hz", 4000000); + if_ = configuration_->property(role + ".ifreq", 0); + dump_ = configuration_->property(role + ".dump", false); + shift_resolution_ = configuration_->property(role + ".doppler_max", 15); + sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 4); + + if (sampled_ms_ % 4 != 0) + { + sampled_ms_ = (int)(sampled_ms_/4) * 4; + LOG_AT_LEVEL(WARNING) << "coherent_integration_time should be multiple of " + << "Galileo code length (4 ms). coherent_integration_time = " + << sampled_ms_ << " ms will be used."; + } + + max_dwells_ = configuration_->property(role + ".max_dwells", 1); + + dump_filename_ = configuration_->property(role + ".dump_filename", + default_dump_filename); + + //--- Find number of samples per spreading code (4 ms) ----------------- + + code_length_ = round( + fs_in_ + / (Galileo_E1_CODE_CHIP_RATE_HZ + / Galileo_E1_B_CODE_LENGTH_CHIPS)); + + vector_length_ = code_length_ * (int)(sampled_ms_/4); + + int samples_per_ms = code_length_ / 4; + + code_data_ = new gr_complex[vector_length_]; + code_pilot_ = new gr_complex[vector_length_]; + + if (item_type_.compare("gr_complex") == 0) + { + item_size_ = sizeof(gr_complex); + acquisition_cc_ = pcps_cccwsr_make_acquisition_cc(sampled_ms_, max_dwells_, + shift_resolution_, if_, fs_in_, samples_per_ms, code_length_, + queue_, dump_, dump_filename_); + stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_, vector_length_); + DLOG(INFO) << "stream_to_vector(" + << stream_to_vector_->unique_id() << ")"; + DLOG(INFO) << "acquisition(" << acquisition_cc_->unique_id() + << ")"; + } + else + { + LOG_AT_LEVEL(WARNING) << item_type_ + << " unknown acquisition item type"; + } +} + + +GalileoE1PcpsCccwsrAmbiguousAcquisition::~GalileoE1PcpsCccwsrAmbiguousAcquisition() +{ + delete[] code_data_; + delete[] code_pilot_; +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::set_channel(unsigned int channel) +{ + channel_ = channel; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel(channel_); + } +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::set_threshold(float threshold) +{ + +// float pfa = configuration_->property(role_+ boost::lexical_cast(channel_) + ".pfa", 0.0); + +// if(pfa==0.0) pfa = configuration_->property(role_+".pfa", 0.0); + +// if(pfa==0.0) +// { +// threshold_ = threshold; +// } +// else +// { +// threshold_ = calculate_threshold(pfa); +// } + + threshold_ = threshold; + + DLOG(INFO) <<"Channel "<set_threshold(threshold_); + } +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::set_doppler_max(unsigned int doppler_max) +{ + doppler_max_ = doppler_max; + + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_max(doppler_max_); + } +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::set_doppler_step(unsigned int doppler_step) +{ + doppler_step_ = doppler_step; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_step(doppler_step_); + } +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::set_channel_queue( + concurrent_queue *channel_internal_queue) +{ + channel_internal_queue_ = channel_internal_queue; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel_queue(channel_internal_queue_); + } +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::set_gnss_synchro( + Gnss_Synchro* gnss_synchro) +{ + gnss_synchro_ = gnss_synchro; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_gnss_synchro(gnss_synchro_); + } +} + + +signed int +GalileoE1PcpsCccwsrAmbiguousAcquisition::mag() +{ + if (item_type_.compare("gr_complex") == 0) + { + return acquisition_cc_->mag(); + } + else + { + return 0; + } +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::init() +{ + acquisition_cc_->init(); + set_local_code(); +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::set_local_code() +{ + if (item_type_.compare("gr_complex") == 0) + { + bool cboc = configuration_->property( + "Acquisition" + boost::lexical_cast(channel_) + + ".cboc", false); + + char signal[3]; + + strcpy(signal, "1B"); + + galileo_e1_code_gen_complex_sampled(code_data_, signal, + cboc, gnss_synchro_->PRN, fs_in_, 0, false); + + strcpy(signal, "1C"); + + galileo_e1_code_gen_complex_sampled(code_pilot_, signal, + cboc, gnss_synchro_->PRN, fs_in_, 0, false); + + acquisition_cc_->set_local_code(code_data_, code_pilot_); + } +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::reset() +{ + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_active(true); + } +} + + +float GalileoE1PcpsCccwsrAmbiguousAcquisition::calculate_threshold(float pfa) +{ + return 0.0; +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::connect(gr::top_block_sptr top_block) +{ + if (item_type_.compare("gr_complex") == 0) + { + top_block->connect(stream_to_vector_, 0, acquisition_cc_, 0); + } + +} + + +void +GalileoE1PcpsCccwsrAmbiguousAcquisition::disconnect(gr::top_block_sptr top_block) +{ + if (item_type_.compare("gr_complex") == 0) + { + top_block->disconnect(stream_to_vector_, 0, acquisition_cc_, 0); + } +} + + +gr::basic_block_sptr GalileoE1PcpsCccwsrAmbiguousAcquisition::get_left_block() +{ + return stream_to_vector_; +} + + +gr::basic_block_sptr GalileoE1PcpsCccwsrAmbiguousAcquisition::get_right_block() +{ + return acquisition_cc_; +} + diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.h b/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.h new file mode 100644 index 000000000..99135d7d1 --- /dev/null +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.h @@ -0,0 +1,158 @@ +/*! + * \file galileo_e1_pcps_cccwsr_ambiguous_acquisition.h + * \brief Adapts a PCPS CCCWSR acquisition block to an AcquisitionInterface for + * Galileo E1 Signals + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_GALILEO_E1_PCPS_CCCWSR_AMBIGUOUS_ACQUISITION_H_ +#define GNSS_SDR_GALILEO_E1_PCPS_CCCWSR_AMBIGUOUS_ACQUISITION_H_ + +#include "gnss_synchro.h" +#include "acquisition_interface.h" +#include "pcps_cccwsr_acquisition_cc.h" +#include +#include + +class ConfigurationInterface; + +/*! + * \brief Adapts a PCPS CCCWSR acquisition block to an AcquisitionInterface + * for Galileo E1 Signals + */ +class GalileoE1PcpsCccwsrAmbiguousAcquisition: public AcquisitionInterface +{ +public: + GalileoE1PcpsCccwsrAmbiguousAcquisition(ConfigurationInterface* configuration, + std::string role, unsigned int in_streams, + unsigned int out_streams, boost::shared_ptr queue); + + virtual ~GalileoE1PcpsCccwsrAmbiguousAcquisition(); + + std::string role() + { + return role_; + } + + /*! + * \brief Returns "Galileo_E1_PCPS_CCCWSR_Ambiguous_Acquisition" + */ + std::string implementation() + { + return "Galileo_E1_PCPS_CCCWSR_Ambiguous_Acquisition"; + } + size_t item_size() + { + return item_size_; + } + + void connect(gr::top_block_sptr top_block); + void disconnect(gr::top_block_sptr top_block); + gr::basic_block_sptr get_left_block(); + gr::basic_block_sptr get_right_block(); + + /*! + * \brief Set acquisition/tracking common Gnss_Synchro object pointer + * to efficiently exchange synchronization data between acquisition and + * tracking blocks + */ + void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro); + + /*! + * \brief Set acquisition channel unique ID + */ + void set_channel(unsigned int channel); + + /*! + * \brief Set statistics threshold of CCCWSR algorithm + */ + void set_threshold(float threshold); + + /*! + * \brief Set maximum Doppler off grid search + */ + void set_doppler_max(unsigned int doppler_max); + + /*! + * \brief Set Doppler steps for the grid search + */ + void set_doppler_step(unsigned int doppler_step); + + /*! + * \brief Set tracking channel internal queue + */ + void set_channel_queue(concurrent_queue *channel_internal_queue); + + /*! + * \brief Initializes acquisition algorithm. + */ + void init(); + + void set_local_code(); + + /*! + * \brief Returns the maximum peak of grid search + */ + signed int mag(); + + /*! + * \brief Restart acquisition algorithm + */ + void reset(); + +private: + ConfigurationInterface* configuration_; + pcps_cccwsr_acquisition_cc_sptr acquisition_cc_; + gr::blocks::stream_to_vector::sptr stream_to_vector_; + size_t item_size_; + std::string item_type_; + unsigned int vector_length_; + unsigned int code_length_; + //unsigned int satellite_; + unsigned int channel_; + float threshold_; + unsigned int doppler_max_; + unsigned int doppler_step_; + unsigned int shift_resolution_; + unsigned int sampled_ms_; + unsigned int max_dwells_; + long fs_in_; + long if_; + bool dump_; + std::string dump_filename_; + std::complex * code_data_; + std::complex * code_pilot_; + Gnss_Synchro * gnss_synchro_; + std::string role_; + unsigned int in_streams_; + unsigned int out_streams_; + boost::shared_ptr queue_; + concurrent_queue *channel_internal_queue_; + float calculate_threshold(float pfa); +}; + +#endif /* GNSS_SDR_GALILEO_E1_PCPS_CCCWSR_AMBIGUOUS_ACQUISITION_H_ */ diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.cc new file mode 100644 index 000000000..12a42361a --- /dev/null +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.cc @@ -0,0 +1,316 @@ +/*! + * \file galileo_e1_pcps_tong_ambiguous_acquisition.cc + * \brief Adapts a PCPS Tong acquisition block to an Acq1uisitionInterface for + * Galileo E1 Signals + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2011 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "galileo_e1_pcps_tong_ambiguous_acquisition.h" +#include "galileo_e1_signal_processing.h" +#include "Galileo_E1.h" +#include "configuration_interface.h" +#include +#include +#include +#include +#include +#include + +using google::LogMessage; + +GalileoE1PcpsTongAmbiguousAcquisition::GalileoE1PcpsTongAmbiguousAcquisition( + ConfigurationInterface* configuration, std::string role, + unsigned int in_streams, unsigned int out_streams, + boost::shared_ptr queue) : + role_(role), in_streams_(in_streams), out_streams_(out_streams), queue_(queue) +{ + configuration_ = configuration; + std::string default_item_type = "gr_complex"; + std::string default_dump_filename = "../data/acquisition.dat"; + + DLOG(INFO) << "role " << role; + + item_type_ = configuration_->property(role + ".item_type", + default_item_type); + + fs_in_ = configuration_->property("GNSS-SDR.internal_fs_hz", 4000000); + if_ = configuration_->property(role + ".ifreq", 0); + dump_ = configuration_->property(role + ".dump", false); + shift_resolution_ = configuration_->property(role + ".doppler_max", 15); + sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 4); + + if (sampled_ms_ % 4 != 0) + { + sampled_ms_ = (int)(sampled_ms_/4) * 4; + LOG_AT_LEVEL(WARNING) << "coherent_integration_time should be multiple of " + << "Galileo code length (4 ms). coherent_integration_time = " + << sampled_ms_ << " ms will be used."; + + } + + tong_init_val_ = configuration->property(role + ".tong_init_val", 1); + tong_max_val_ = configuration->property(role + ".tong_max_val", 2); + + dump_filename_ = configuration_->property(role + ".dump_filename", + default_dump_filename); + + //--- Find number of samples per spreading code (4 ms) ----------------- + + code_length_ = round( + fs_in_ + / (Galileo_E1_CODE_CHIP_RATE_HZ + / Galileo_E1_B_CODE_LENGTH_CHIPS)); + + vector_length_ = code_length_ * (int)(sampled_ms_/4); + + int samples_per_ms = code_length_ / 4; + + code_ = new gr_complex[vector_length_]; + + if (item_type_.compare("gr_complex") == 0) + { + item_size_ = sizeof(gr_complex); + acquisition_cc_ = pcps_tong_make_acquisition_cc(sampled_ms_, shift_resolution_, + if_, fs_in_, samples_per_ms, code_length_, tong_init_val_, + tong_max_val_, queue_, dump_, dump_filename_); + + stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_, vector_length_); + DLOG(INFO) << "stream_to_vector(" + << stream_to_vector_->unique_id() << ")"; + DLOG(INFO) << "acquisition(" << acquisition_cc_->unique_id() + << ")"; + } + else + { + LOG_AT_LEVEL(WARNING) << item_type_ + << " unknown acquisition item type"; + } +} + + +GalileoE1PcpsTongAmbiguousAcquisition::~GalileoE1PcpsTongAmbiguousAcquisition() +{ + delete[] code_; +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::set_channel(unsigned int channel) +{ + channel_ = channel; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel(channel_); + } +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::set_threshold(float threshold) +{ + + float pfa = configuration_->property(role_+ boost::lexical_cast(channel_) + ".pfa", 0.0); + + if(pfa==0.0) pfa = configuration_->property(role_+".pfa", 0.0); + + if(pfa==0.0) + { + threshold_ = threshold; + } + else + { + threshold_ = calculate_threshold(pfa); + } + + DLOG(INFO) <<"Channel "<set_threshold(threshold_); + } +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::set_doppler_max(unsigned int doppler_max) +{ + doppler_max_ = doppler_max; + + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_max(doppler_max_); + } +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::set_doppler_step(unsigned int doppler_step) +{ + doppler_step_ = doppler_step; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_step(doppler_step_); + } + +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::set_channel_queue( + concurrent_queue *channel_internal_queue) +{ + channel_internal_queue_ = channel_internal_queue; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel_queue(channel_internal_queue_); + } +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::set_gnss_synchro( + Gnss_Synchro* gnss_synchro) +{ + gnss_synchro_ = gnss_synchro; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_gnss_synchro(gnss_synchro_); + } +} + + +signed int +GalileoE1PcpsTongAmbiguousAcquisition::mag() +{ + if (item_type_.compare("gr_complex") == 0) + { + return acquisition_cc_->mag(); + } + else + { + return 0; + } +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::init() +{ + acquisition_cc_->init(); + set_local_code(); +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::set_local_code() +{ + if (item_type_.compare("gr_complex") == 0) + { + bool cboc = configuration_->property( + "Acquisition" + boost::lexical_cast(channel_) + + ".cboc", false); + + std::complex * code = new std::complex[code_length_]; + + galileo_e1_code_gen_complex_sampled(code, gnss_synchro_->Signal, + cboc, gnss_synchro_->PRN, fs_in_, 0, false); + + for (unsigned int i = 0; i < sampled_ms_/4; i++) + { + memcpy(&(code_[i*code_length_]), code, + sizeof(gr_complex)*code_length_); + } + + acquisition_cc_->set_local_code(code_); + + delete[] code; + } +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::reset() +{ + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_active(true); + } +} + + +float GalileoE1PcpsTongAmbiguousAcquisition::calculate_threshold(float pfa) +{ + unsigned int frequency_bins = 0; + for (int doppler = (int)(-doppler_max_); doppler <= (int)doppler_max_; doppler += doppler_step_) + { + frequency_bins++; + } + + DLOG(INFO) <<"Channel "<connect(stream_to_vector_, 0, acquisition_cc_, 0); + } +} + + +void +GalileoE1PcpsTongAmbiguousAcquisition::disconnect(gr::top_block_sptr top_block) +{ + if (item_type_.compare("gr_complex") == 0) + { + top_block->disconnect(stream_to_vector_, 0, acquisition_cc_, 0); + } +} + + +gr::basic_block_sptr GalileoE1PcpsTongAmbiguousAcquisition::get_left_block() +{ + return stream_to_vector_; +} + + +gr::basic_block_sptr GalileoE1PcpsTongAmbiguousAcquisition::get_right_block() +{ + return acquisition_cc_; +} + diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.h b/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.h new file mode 100644 index 000000000..f33281f21 --- /dev/null +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.h @@ -0,0 +1,161 @@ +/*! + * \file galileo_e1_pcps_tong_ambiguous_acquisition.h + * \brief Adapts a PCPS Tong acquisition block to an AcquisitionInterface for + * Galileo E1 Signals + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_GALILEO_E1_PCPS_TONG_AMBIGUOUS_ACQUISITION_H_ +#define GNSS_SDR_GALILEO_E1_PCPS_TONG_AMBIGUOUS_ACQUISITION_H_ + +#include "gnss_synchro.h" +#include "acquisition_interface.h" +#include "pcps_tong_acquisition_cc.h" +#include +#include + +class ConfigurationInterface; + +/*! + * \brief Adapts a PCPS Tong acquisition block to an AcquisitionInterface + * for Galileo E1 Signals + */ +class GalileoE1PcpsTongAmbiguousAcquisition: public AcquisitionInterface +{ +public: + GalileoE1PcpsTongAmbiguousAcquisition(ConfigurationInterface* configuration, + std::string role, unsigned int in_streams, + unsigned int out_streams, boost::shared_ptr queue); + + virtual ~GalileoE1PcpsTongAmbiguousAcquisition(); + + std::string role() + { + return role_; + } + + /*! + * \brief Returns "Galileo_E1_PCPS_Tong_Ambiguous_Acquisition" + */ + std::string implementation() + { + return "Galileo_E1_PCPS_Tong_Ambiguous_Acquisition"; + } + size_t item_size() + { + return item_size_; + } + + void connect(gr::top_block_sptr top_block); + void disconnect(gr::top_block_sptr top_block); + gr::basic_block_sptr get_left_block(); + gr::basic_block_sptr get_right_block(); + + /*! + * \brief Set acquisition/tracking common Gnss_Synchro object pointer + * to efficiently exchange synchronization data between acquisition and + * tracking blocks + */ + void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro); + + /*! + * \brief Set acquisition channel unique ID + */ + void set_channel(unsigned int channel); + + /*! + * \brief Set statistics threshold of TONG algorithm + */ + void set_threshold(float threshold); + + /*! + * \brief Set maximum Doppler off grid search + */ + void set_doppler_max(unsigned int doppler_max); + + /*! + * \brief Set Doppler steps for the grid search + */ + void set_doppler_step(unsigned int doppler_step); + + /*! + * \brief Set tracking channel internal queue + */ + void set_channel_queue(concurrent_queue *channel_internal_queue); + + /*! + * \brief Initializes acquisition algorithm. + */ + void init(); + + /*! + * \brief Sets local code for Galileo E1 TONG acquisition algorithm. + */ + void set_local_code(); + + /*! + * \brief Returns the maximum peak of grid search + */ + signed int mag(); + + /*! + * \brief Restart acquisition algorithm + */ + void reset(); + +private: + ConfigurationInterface* configuration_; + pcps_tong_acquisition_cc_sptr acquisition_cc_; + gr::blocks::stream_to_vector::sptr stream_to_vector_; + size_t item_size_; + std::string item_type_; + unsigned int vector_length_; + unsigned int code_length_; + bool bit_transition_flag_; + unsigned int channel_; + float threshold_; + unsigned int doppler_max_; + unsigned int doppler_step_; + unsigned int shift_resolution_; + unsigned int sampled_ms_; + unsigned int tong_init_val_; + unsigned int tong_max_val_; + long fs_in_; + long if_; + bool dump_; + std::string dump_filename_; + std::complex * code_; + Gnss_Synchro * gnss_synchro_; + std::string role_; + unsigned int in_streams_; + unsigned int out_streams_; + boost::shared_ptr queue_; + concurrent_queue *channel_internal_queue_; + float calculate_threshold(float pfa); +}; + +#endif /* GNSS_SDR_GALILEO_E1_PCPS_TONG_AMBIGUOUS_ACQUISITION_H_ */ diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc index fc59fd4eb..a606d954f 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc @@ -1,10 +1,11 @@ /*! * \file gps_l1_ca_pcps_acquisition.cc * \brief Adapts a PCPS acquisition block to an AcquisitionInterface for - * GPS L1 C/A Signals + * GPS L1 C/A signals * \authors
    *
  • Javier Arribas, 2011. jarribas(at)cttc.es *
  • Luis Esteve, 2012. luis(at)epsilon-formacion.com + *
  • Marc Molina, 2013. marc.molina.pena(at)gmail.com *
* * ------------------------------------------------------------------------- @@ -57,33 +58,45 @@ GpsL1CaPcpsAcquisition::GpsL1CaPcpsAcquisition( DLOG(INFO) << "role " << role; -// std::cout << "role " << role_ << std::endl; - item_type_ = configuration_->property(role + ".item_type", default_item_type); fs_in_ = configuration_->property("GNSS-SDR.internal_fs_hz", 2048000); if_ = configuration_->property(role + ".ifreq", 0); dump_ = configuration_->property(role + ".dump", false); - shift_resolution_ = configuration_->property(role + ".doppler_max", 10000); - sampled_ms_ = configuration_->property(role + ".sampled_ms", 1); + shift_resolution_ = configuration_->property(role + ".doppler_max", 15); + sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 1); + + bit_transition_flag_ = configuration_->property(role + ".bit_transition_flag", false); + + if (!bit_transition_flag_) + { + max_dwells_ = configuration_->property(role + ".max_dwells", 1); + } + else + { + max_dwells_ = 2; + } + dump_filename_ = configuration_->property(role + ".dump_filename", default_dump_filename); //--- Find number of samples per spreading code ------------------------- - vector_length_ = round(fs_in_ + code_length_ = round(fs_in_ / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS)); - code_= new gr_complex[vector_length_ * sampled_ms_]; + vector_length_ = code_length_ * sampled_ms_; + + code_= new gr_complex[vector_length_]; if (item_type_.compare("gr_complex") == 0) { item_size_ = sizeof(gr_complex); - acquisition_cc_ = pcps_make_acquisition_cc(sampled_ms_, - shift_resolution_, if_, fs_in_, vector_length_, vector_length_, queue_, - dump_, dump_filename_); + acquisition_cc_ = pcps_make_acquisition_cc(sampled_ms_, max_dwells_, + shift_resolution_, if_, fs_in_, code_length_, code_length_, + bit_transition_flag_, queue_, dump_, dump_filename_); - stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_, vector_length_*sampled_ms_); + stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_, vector_length_); DLOG(INFO) << "stream_to_vector(" << stream_to_vector_->unique_id() << ")"; @@ -154,9 +167,9 @@ void GpsL1CaPcpsAcquisition::set_doppler_step(unsigned int doppler_step) { doppler_step_ = doppler_step; if (item_type_.compare("gr_complex") == 0) - { - acquisition_cc_->set_doppler_step(doppler_step_); - } + { + acquisition_cc_->set_doppler_step(doppler_step_); + } } @@ -185,13 +198,13 @@ void GpsL1CaPcpsAcquisition::set_gnss_synchro(Gnss_Synchro* gnss_synchro) signed int GpsL1CaPcpsAcquisition::mag() { if (item_type_.compare("gr_complex") == 0) - { - return acquisition_cc_->mag(); - } + { + return acquisition_cc_->mag(); + } else - { - return 0; - } + { + return 0; + } } @@ -201,24 +214,28 @@ void GpsL1CaPcpsAcquisition::init() set_local_code(); } + void GpsL1CaPcpsAcquisition::set_local_code() { if (item_type_.compare("gr_complex") == 0) { - std::complex* code = new std::complex[vector_length_]; + std::complex* code = new std::complex[code_length_]; gps_l1_ca_code_gen_complex_sampled(code, gnss_synchro_->PRN, fs_in_, 0); for (unsigned int i = 0; i < sampled_ms_; i++) { - memcpy(&(code_[i*vector_length_]), code, - sizeof(gr_complex)*vector_length_); + memcpy(&(code_[i*code_length_]), code, + sizeof(gr_complex)*code_length_); } acquisition_cc_->set_local_code(code_); + + delete[] code; } } + void GpsL1CaPcpsAcquisition::reset() { if (item_type_.compare("gr_complex") == 0) @@ -227,6 +244,7 @@ void GpsL1CaPcpsAcquisition::reset() } } + float GpsL1CaPcpsAcquisition::calculate_threshold(float pfa) { //Calculate the threshold @@ -243,12 +261,13 @@ float GpsL1CaPcpsAcquisition::calculate_threshold(float pfa) double exponent = 1/(double)ncells; double val = pow(1.0-pfa,exponent); double lambda = double(vector_length_); - boost::math::exponential_distribution mydist (lambda); + boost::math::exponential_distribution mydist (lambda); float threshold = (float)quantile(mydist,val); return threshold; } + void GpsL1CaPcpsAcquisition::connect(gr::top_block_sptr top_block) { if (item_type_.compare("gr_complex") == 0) diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.h index 93aede7b8..2e56e6e01 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.h +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.h @@ -5,6 +5,7 @@ * \authors
    *
  • Javier Arribas, 2011. jarribas(at)cttc.es *
  • Luis Esteve, 2012. luis(at)epsilon-formacion.com + *
  • Marc Molina, 2013. marc.molina.pena(at)gmail.com *
* * ------------------------------------------------------------------------- @@ -119,7 +120,6 @@ public: /*! * \brief Sets local code for GPS L1/CA PCPS acquisition algorithm. */ - void set_local_code(); /*! @@ -139,13 +139,15 @@ private: size_t item_size_; std::string item_type_; unsigned int vector_length_; - //unsigned int satellite_; + unsigned int code_length_; + bool bit_transition_flag_; unsigned int channel_; float threshold_; unsigned int doppler_max_; unsigned int doppler_step_; unsigned int shift_resolution_; unsigned int sampled_ms_; + unsigned int max_dwells_; long fs_in_; long if_; bool dump_; diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.cc index c1719c956..cc2002bc5 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.cc @@ -64,7 +64,7 @@ GpsL1CaPcpsAcquisitionFineDoppler::GpsL1CaPcpsAcquisitionFineDoppler( dump_ = configuration->property(role + ".dump", false); doppler_max_ = configuration->property(role + ".doppler_max", 5000); doppler_min_ = configuration->property(role + ".doppler_min", -5000); - sampled_ms_ = configuration->property(role + ".sampled_ms", 1); + sampled_ms_ = configuration->property(role + ".coherent_integration_time_ms", 1); max_dwells_= configuration->property(role + ".max_dwells", 1); dump_filename_ = configuration->property(role + ".dump_filename", default_dump_filename); diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.h index 4f6580cb4..0c141c6d2 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.h +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.h @@ -132,7 +132,6 @@ private: size_t item_size_; std::string item_type_; unsigned int vector_length_; - //unsigned int satellite_; unsigned int channel_; float threshold_; int doppler_max_; diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.cc index 4bdf80660..a1500c7d8 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.cc @@ -63,7 +63,7 @@ GpsL1CaPcpsAssistedAcquisition::GpsL1CaPcpsAssistedAcquisition( dump_ = configuration->property(role + ".dump", false); doppler_max_ = configuration->property(role + ".doppler_max", 5000); doppler_min_ = configuration->property(role + ".doppler_min", -5000); - sampled_ms_ = configuration->property(role + ".sampled_ms", 1); + sampled_ms_ = configuration->property(role + ".coherent_integration_time_ms", 1); max_dwells_= configuration->property(role + ".max_dwells", 1); dump_filename_ = configuration->property(role + ".dump_filename", default_dump_filename); diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_multithread_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_multithread_acquisition.cc new file mode 100644 index 000000000..6b6cda002 --- /dev/null +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_multithread_acquisition.cc @@ -0,0 +1,296 @@ +/*! + * \file gps_l1_ca_pcps_multithread_acquisition.cc + * \brief Adapts a multithread PCPS acquisition block to an + * AcquisitionInterface for GPS L1 C/A signals + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "gps_l1_ca_pcps_multithread_acquisition.h" +#include "gps_sdr_signal_processing.h" +#include "GPS_L1_CA.h" +#include "configuration_interface.h" +#include +#include +#include +#include +#include +#include + +using google::LogMessage; + +GpsL1CaPcpsMultithreadAcquisition::GpsL1CaPcpsMultithreadAcquisition( + ConfigurationInterface* configuration, std::string role, + unsigned int in_streams, unsigned int out_streams, + gr::msg_queue::sptr queue) : + role_(role), in_streams_(in_streams), out_streams_(out_streams), queue_(queue) +{ + configuration_ = configuration; + std::string default_item_type = "gr_complex"; + std::string default_dump_filename = "./data/acquisition.dat"; + + DLOG(INFO) << "role " << role; + + item_type_ = configuration_->property(role + ".item_type", + default_item_type); + + fs_in_ = configuration_->property("GNSS-SDR.internal_fs_hz", 2048000); + if_ = configuration_->property(role + ".ifreq", 0); + dump_ = configuration_->property(role + ".dump", false); + shift_resolution_ = configuration_->property(role + ".doppler_max", 15); + sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 1); + + bit_transition_flag_ = configuration_->property("Acquisition.bit_transition_flag", false); + + if (!bit_transition_flag_) + { + max_dwells_ = configuration_->property(role + ".max_dwells", 1); + } + else + { + max_dwells_ = 2; + } + + dump_filename_ = configuration_->property(role + ".dump_filename", + default_dump_filename); + + //--- Find number of samples per spreading code ------------------------- + code_length_ = round(fs_in_ + / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS)); + + vector_length_ = code_length_ * sampled_ms_; + + code_= new gr_complex[vector_length_]; + + if (item_type_.compare("gr_complex") == 0) + { + item_size_ = sizeof(gr_complex); + acquisition_cc_ = pcps_make_multithread_acquisition_cc(sampled_ms_, max_dwells_, + shift_resolution_, if_, fs_in_, code_length_, code_length_, + bit_transition_flag_, queue_, dump_, dump_filename_); + + stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_, vector_length_); + + DLOG(INFO) << "stream_to_vector(" << stream_to_vector_->unique_id() + << ")"; + DLOG(INFO) << "acquisition(" << acquisition_cc_->unique_id() + << ")"; + } + else + { + LOG_AT_LEVEL(WARNING) << item_type_ + << " unknown acquisition item type"; + } +} + + +GpsL1CaPcpsMultithreadAcquisition::~GpsL1CaPcpsMultithreadAcquisition() +{ + delete[] code_; +} + + +void GpsL1CaPcpsMultithreadAcquisition::set_channel(unsigned int channel) +{ + channel_ = channel; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel(channel_); + } +} + + +void GpsL1CaPcpsMultithreadAcquisition::set_threshold(float threshold) +{ + float pfa = configuration_->property(role_ + boost::lexical_cast(channel_) + ".pfa", 0.0); + + if(pfa==0.0) + { + pfa = configuration_->property(role_+".pfa", 0.0); + } + if(pfa==0.0) + { + threshold_ = threshold; + } + else + { + threshold_ = calculate_threshold(pfa); + } + + DLOG(INFO) <<"Channel "<set_threshold(threshold_); + } +} + + +void GpsL1CaPcpsMultithreadAcquisition::set_doppler_max(unsigned int doppler_max) +{ + doppler_max_ = doppler_max; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_max(doppler_max_); + } +} + + +void GpsL1CaPcpsMultithreadAcquisition::set_doppler_step(unsigned int doppler_step) +{ + doppler_step_ = doppler_step; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_step(doppler_step_); + } + +} + + +void GpsL1CaPcpsMultithreadAcquisition::set_channel_queue( + concurrent_queue *channel_internal_queue) +{ + channel_internal_queue_ = channel_internal_queue; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel_queue(channel_internal_queue_); + } +} + + +void GpsL1CaPcpsMultithreadAcquisition::set_gnss_synchro(Gnss_Synchro* gnss_synchro) +{ + gnss_synchro_ = gnss_synchro; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_gnss_synchro(gnss_synchro_); + } +} + + +signed int GpsL1CaPcpsMultithreadAcquisition::mag() +{ + if (item_type_.compare("gr_complex") == 0) + { + return acquisition_cc_->mag(); + } + else + { + return 0; + } +} + + +void GpsL1CaPcpsMultithreadAcquisition::init() +{ + acquisition_cc_->init(); + set_local_code(); +} + + +void GpsL1CaPcpsMultithreadAcquisition::set_local_code() +{ + if (item_type_.compare("gr_complex") == 0) + { + std::complex* code = new std::complex[code_length_]; + + gps_l1_ca_code_gen_complex_sampled(code, gnss_synchro_->PRN, fs_in_, 0); + + for (unsigned int i = 0; i < sampled_ms_; i++) + { + memcpy(&(code_[i*code_length_]), code, + sizeof(gr_complex)*code_length_); + } + + acquisition_cc_->set_local_code(code_); + + delete[] code; + } +} + + +void GpsL1CaPcpsMultithreadAcquisition::reset() +{ + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_active(true); + } +} + + +float GpsL1CaPcpsMultithreadAcquisition::calculate_threshold(float pfa) +{ + //Calculate the threshold + + unsigned int frequency_bins = 0; + for (int doppler = (int)(-doppler_max_); doppler <= (int)doppler_max_; doppler += doppler_step_) + { + frequency_bins++; + } + + DLOG(INFO) <<"Channel "<connect(stream_to_vector_, 0, acquisition_cc_, 0); + } + +} + + +void GpsL1CaPcpsMultithreadAcquisition::disconnect(gr::top_block_sptr top_block) +{ + if (item_type_.compare("gr_complex") == 0) + { + top_block->disconnect(stream_to_vector_, 0, acquisition_cc_, 0); + } +} + + +gr::basic_block_sptr GpsL1CaPcpsMultithreadAcquisition::get_left_block() +{ + return stream_to_vector_; +} + + +gr::basic_block_sptr GpsL1CaPcpsMultithreadAcquisition::get_right_block() +{ + return acquisition_cc_; +} + diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_multithread_acquisition.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_multithread_acquisition.h new file mode 100644 index 000000000..cafc3c693 --- /dev/null +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_multithread_acquisition.h @@ -0,0 +1,162 @@ +/*! + * \file gps_l1_ca_pcps_multithread_acquisition.h + * \brief Adapts a multithread PCPS acquisition block to an + * AcquisitionInterface for GPS L1 C/A signals + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_GPS_L1_CA_PCPS_MULTITHREAD_CQUISITION_H_ +#define GNSS_SDR_GPS_L1_CA_PCPS_MULTITHREAD_CQUISITION_H_ + +#include "gnss_synchro.h" +#include "acquisition_interface.h" +#include "pcps_multithread_acquisition_cc.h" +#include +#include + + +class ConfigurationInterface; + +/*! + * \brief This class adapts a multithread PCPS acquisition block to an + * AcquisitionInterface for GPS L1 C/A signals + */ +class GpsL1CaPcpsMultithreadAcquisition: public AcquisitionInterface +{ +public: + GpsL1CaPcpsMultithreadAcquisition(ConfigurationInterface* configuration, + std::string role, unsigned int in_streams, + unsigned int out_streams, boost::shared_ptr queue); + + virtual ~GpsL1CaPcpsMultithreadAcquisition(); + + std::string role() + { + return role_; + } + + /*! + * \brief Returns "GPS_L1_CA_PCPS_Multithread_Acquisition" + */ + std::string implementation() + { + return "GPS_L1_CA_PCPS_Multithread_Acquisition"; + } + size_t item_size() + { + return item_size_; + } + + void connect(gr::top_block_sptr top_block); + void disconnect(gr::top_block_sptr top_block); + gr::basic_block_sptr get_left_block(); + gr::basic_block_sptr get_right_block(); + + /*! + * \brief Set acquisition/tracking common Gnss_Synchro object pointer + * to efficiently exchange synchronization data between acquisition and + * tracking blocks + */ + void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro); + + /*! + * \brief Set acquisition channel unique ID + */ + void set_channel(unsigned int channel); + + /*! + * \brief Set statistics threshold of PCPS algorithm + */ + void set_threshold(float threshold); + + /*! + * \brief Set maximum Doppler off grid search + */ + void set_doppler_max(unsigned int doppler_max); + + /*! + * \brief Set Doppler steps for the grid search + */ + void set_doppler_step(unsigned int doppler_step); + + /*! + * \brief Set tracking channel internal queue + */ + void set_channel_queue(concurrent_queue *channel_internal_queue); + + /*! + * \brief Initializes acquisition algorithm. + */ + void init(); + + /*! + * \brief Sets local code for GPS L1/CA PCPS acquisition algorithm. + */ + void set_local_code(); + + /*! + * \brief Returns the maximum peak of grid search + */ + signed int mag(); + + /*! + * \brief Restart acquisition algorithm + */ + void reset(); + +private: + ConfigurationInterface* configuration_; + pcps_multithread_acquisition_cc_sptr acquisition_cc_; + gr::blocks::stream_to_vector::sptr stream_to_vector_; + size_t item_size_; + std::string item_type_; + unsigned int vector_length_; + unsigned int code_length_; + bool bit_transition_flag_; + unsigned int channel_; + float threshold_; + unsigned int doppler_max_; + unsigned int doppler_step_; + unsigned int shift_resolution_; + unsigned int sampled_ms_; + unsigned int max_dwells_; + long fs_in_; + long if_; + bool dump_; + std::string dump_filename_; + std::complex * code_; + Gnss_Synchro * gnss_synchro_; + std::string role_; + unsigned int in_streams_; + unsigned int out_streams_; + boost::shared_ptr queue_; + concurrent_queue *channel_internal_queue_; + + float calculate_threshold(float pfa); +}; + +#endif /* GNSS_SDR_GPS_L1_CA_PCPS_MULTITHREAD_CQUISITION_H_ */ diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.cc new file mode 100644 index 000000000..82f0a6473 --- /dev/null +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.cc @@ -0,0 +1,284 @@ +/*! + * \file gps_l1_ca_pcps_tong_acquisition.cc + * \brief Adapts a PCPS Tong acquisition block to an AcquisitionInterface for + * GPS L1 C/A signals + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "gps_l1_ca_pcps_tong_acquisition.h" +#include "gps_sdr_signal_processing.h" +#include "GPS_L1_CA.h" +#include "configuration_interface.h" +#include +#include +#include +#include +#include +#include + +using google::LogMessage; + +GpsL1CaPcpsTongAcquisition::GpsL1CaPcpsTongAcquisition( + ConfigurationInterface* configuration, std::string role, + unsigned int in_streams, unsigned int out_streams, + gr::msg_queue::sptr queue) : + role_(role), in_streams_(in_streams), out_streams_(out_streams), queue_(queue) +{ + configuration_ = configuration; + std::string default_item_type = "gr_complex"; + std::string default_dump_filename = "./data/acquisition.dat"; + + DLOG(INFO) << "role " << role; + + item_type_ = configuration_->property(role + ".item_type", + default_item_type); + + fs_in_ = configuration_->property("GNSS-SDR.internal_fs_hz", 2048000); + if_ = configuration_->property(role + ".ifreq", 0); + dump_ = configuration_->property(role + ".dump", false); + shift_resolution_ = configuration_->property(role + ".doppler_max", 15); + sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 1); + + tong_init_val_ = configuration->property(role + ".tong_init_val", 1); + tong_max_val_ = configuration->property(role + ".tong_max_val", 2); + + dump_filename_ = configuration_->property(role + ".dump_filename", + default_dump_filename); + + //--- Find number of samples per spreading code ------------------------- + code_length_ = round(fs_in_ + / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS)); + + vector_length_ = code_length_ * sampled_ms_; + + code_= new gr_complex[vector_length_]; + + if (item_type_.compare("gr_complex") == 0) + { + item_size_ = sizeof(gr_complex); + acquisition_cc_ = pcps_tong_make_acquisition_cc(sampled_ms_, shift_resolution_, if_, fs_in_, + code_length_, code_length_, tong_init_val_, tong_max_val_, + queue_, dump_, dump_filename_); + + stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_, vector_length_); + + DLOG(INFO) << "stream_to_vector(" << stream_to_vector_->unique_id() + << ")"; + DLOG(INFO) << "acquisition(" << acquisition_cc_->unique_id() + << ")"; + } + else + { + LOG_AT_LEVEL(WARNING) << item_type_ + << " unknown acquisition item type"; + } +} + + +GpsL1CaPcpsTongAcquisition::~GpsL1CaPcpsTongAcquisition() +{ + delete[] code_; +} + + +void GpsL1CaPcpsTongAcquisition::set_channel(unsigned int channel) +{ + channel_ = channel; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel(channel_); + } +} + + +void GpsL1CaPcpsTongAcquisition::set_threshold(float threshold) +{ + float pfa = configuration_->property(role_ + boost::lexical_cast(channel_) + ".pfa", 0.0); + + if(pfa==0.0) + { + pfa = configuration_->property(role_+".pfa", 0.0); + } + if(pfa==0.0) + { + threshold_ = threshold; + } + else + { + threshold_ = calculate_threshold(pfa); + } + + DLOG(INFO) <<"Channel "<set_threshold(threshold_); + } +} + + +void GpsL1CaPcpsTongAcquisition::set_doppler_max(unsigned int doppler_max) +{ + doppler_max_ = doppler_max; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_max(doppler_max_); + } +} + + +void GpsL1CaPcpsTongAcquisition::set_doppler_step(unsigned int doppler_step) +{ + doppler_step_ = doppler_step; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_doppler_step(doppler_step_); + } + +} + + +void GpsL1CaPcpsTongAcquisition::set_channel_queue( + concurrent_queue *channel_internal_queue) +{ + channel_internal_queue_ = channel_internal_queue; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_channel_queue(channel_internal_queue_); + } +} + + +void GpsL1CaPcpsTongAcquisition::set_gnss_synchro(Gnss_Synchro* gnss_synchro) +{ + gnss_synchro_ = gnss_synchro; + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_gnss_synchro(gnss_synchro_); + } +} + + +signed int GpsL1CaPcpsTongAcquisition::mag() +{ + if (item_type_.compare("gr_complex") == 0) + { + return acquisition_cc_->mag(); + } + else + { + return 0; + } +} + + +void GpsL1CaPcpsTongAcquisition::init() +{ + acquisition_cc_->init(); + set_local_code(); +} + +void GpsL1CaPcpsTongAcquisition::set_local_code() +{ + if (item_type_.compare("gr_complex") == 0) + { + std::complex* code = new std::complex[code_length_]; + + gps_l1_ca_code_gen_complex_sampled(code, gnss_synchro_->PRN, fs_in_, 0); + + for (unsigned int i = 0; i < sampled_ms_; i++) + { + memcpy(&(code_[i*code_length_]), code, + sizeof(gr_complex)*code_length_); + } + + acquisition_cc_->set_local_code(code_); + + delete[] code; + } +} + +void GpsL1CaPcpsTongAcquisition::reset() +{ + if (item_type_.compare("gr_complex") == 0) + { + acquisition_cc_->set_active(true); + } +} + +float GpsL1CaPcpsTongAcquisition::calculate_threshold(float pfa) +{ + //Calculate the threshold + + unsigned int frequency_bins = 0; + for (int doppler = (int)(-doppler_max_); doppler <= (int)doppler_max_; doppler += doppler_step_) + { + frequency_bins++; + } + + DLOG(INFO) <<"Channel "<connect(stream_to_vector_, 0, acquisition_cc_, 0); + } + +} + + +void GpsL1CaPcpsTongAcquisition::disconnect(gr::top_block_sptr top_block) +{ + if (item_type_.compare("gr_complex") == 0) + { + top_block->disconnect(stream_to_vector_, 0, acquisition_cc_, 0); + } +} + + +gr::basic_block_sptr GpsL1CaPcpsTongAcquisition::get_left_block() +{ + return stream_to_vector_; +} + + +gr::basic_block_sptr GpsL1CaPcpsTongAcquisition::get_right_block() +{ + return acquisition_cc_; +} + diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.h new file mode 100644 index 000000000..5152e8d1f --- /dev/null +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.h @@ -0,0 +1,165 @@ +/*! + * \file gps_l1_ca_pcps_tong_acquisition.h + * \brief Adapts a PCPS Tong acquisition block to an AcquisitionInterface for + * GPS L1 C/A signals + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_GPS_L1_CA_TONG_ACQUISITION_H_ +#define GNSS_SDR_GPS_L1_CA_TONG_ACQUISITION_H_ + +#include "gnss_synchro.h" +#include "acquisition_interface.h" +#include "pcps_tong_acquisition_cc.h" +#include +#include + + +class ConfigurationInterface; + +/*! + * \brief This class adapts a PCPS Tong acquisition block to an + * AcquisitionInterface for GPS L1 C/A signals + */ +class GpsL1CaPcpsTongAcquisition: public AcquisitionInterface +{ +public: + GpsL1CaPcpsTongAcquisition(ConfigurationInterface* configuration, + std::string role, unsigned int in_streams, + unsigned int out_streams, boost::shared_ptr queue); + + virtual ~GpsL1CaPcpsTongAcquisition(); + + std::string role() + { + return role_; + } + + /*! + * \brief Returns "GPS_L1_CA_PCPS_Tong_Acquisition" + */ + std::string implementation() + { + return "GPS_L1_CA_PCPS_Tong_Acquisition"; + } + size_t item_size() + { + return item_size_; + } + + void connect(gr::top_block_sptr top_block); + void disconnect(gr::top_block_sptr top_block); + gr::basic_block_sptr get_left_block(); + gr::basic_block_sptr get_right_block(); + + /*! + * \brief Set acquisition/tracking common Gnss_Synchro object pointer + * to efficiently exchange synchronization data between acquisition and + * tracking blocks + */ + void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro); + + /*! + * \brief Set acquisition channel unique ID + */ + void set_channel(unsigned int channel); + + /*! + * \brief Set statistics threshold of TONG algorithm + */ + void set_threshold(float threshold); + + /*! bit_transition_flag_ = configuration_->property("Acquisition.bit_transition_flag", false); + + * \brief Set maximum Doppler off grid search + */ + void set_doppler_max(unsigned int doppler_max); + + /*! + * \brief Set Doppler steps for the grid search + */ + void set_doppler_step(unsigned int doppler_step); + + /*! + * \brief Set tracking channel internal queue + */ + void set_channel_queue(concurrent_queue *channel_internal_queue); + + /*! + * \brief Initializes acquisition algorithm. + */ + void init(); + + /*! + * \brief Sets local code for GPS L1/CA TONG acquisition algorithm. + */ + void set_local_code(); + + /*! + * \brief Returns the maximum peak of grid search + */ + signed int mag(); + + /*! + * \brief Restart acquisition algorithm + */// std::cout << "role " << role_ << std::endl; + + void reset(); + +private: + ConfigurationInterface* configuration_; + pcps_tong_acquisition_cc_sptr acquisition_cc_; + gr::blocks::stream_to_vector::sptr stream_to_vector_; + size_t item_size_; + std::string item_type_; + unsigned int vector_length_; + unsigned int code_length_; + bool bit_transition_flag_; + unsigned int channel_; + float threshold_; + unsigned int doppler_max_; + unsigned int doppler_step_; + unsigned int shift_resolution_; + unsigned int sampled_ms_; + unsigned int tong_init_val_; + unsigned int tong_max_val_; + long fs_in_; + long if_; + bool dump_; + std::string dump_filename_; + std::complex * code_; + Gnss_Synchro * gnss_synchro_; + std::string role_; + unsigned int in_streams_; + unsigned int out_streams_; + boost::shared_ptr queue_; + concurrent_queue *channel_internal_queue_; + + float calculate_threshold(float pfa); +}; + +#endif /* GNSS_SDR_GPS_L1_CA_TONG_ACQUISITION_H_ */ diff --git a/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt b/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt index 7149f6327..6ea1114ee 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt @@ -17,9 +17,13 @@ # set(ACQ_GR_BLOCKS_SOURCES - pcps_acquisition_cc.cc + pcps_acquisition_cc.cc + pcps_multithread_acquisition_cc.cc pcps_assisted_acquisition_cc.cc pcps_acquisition_fine_doppler_cc.cc + pcps_tong_acquisition_cc.cc + pcps_cccwsr_acquisition_cc.cc + galileo_pcps_8ms_acquisition_cc.cc ) include_directories( diff --git a/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.cc new file mode 100644 index 000000000..d43abe9ff --- /dev/null +++ b/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.cc @@ -0,0 +1,404 @@ +/*! + * \file galileo_pcps_8ms_acquisition_cc.cc + * \brief This class implements a Parallel Code Phase Search Acquisition for + * Galileo E1 signals with coherent integration time = 8 ms (two codes) + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "galileo_pcps_8ms_acquisition_cc.h" +#include "gnss_signal_processing.h" +#include "control_message_factory.h" +#include +#include +#include +#include +#include + +using google::LogMessage; + +galileo_pcps_8ms_acquisition_cc_sptr galileo_pcps_8ms_make_acquisition_cc( + unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename) +{ + + return galileo_pcps_8ms_acquisition_cc_sptr( + new galileo_pcps_8ms_acquisition_cc(sampled_ms, max_dwells, doppler_max, freq, fs_in, samples_per_ms, + samples_per_code, queue, dump, dump_filename)); +} + + +galileo_pcps_8ms_acquisition_cc::galileo_pcps_8ms_acquisition_cc( + unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename) : + gr::block("galileo_pcps_8ms_acquisition_cc", + gr::io_signature::make(1, 1, sizeof(gr_complex) * sampled_ms * samples_per_ms), + gr::io_signature::make(0, 0, sizeof(gr_complex) * sampled_ms * samples_per_ms)) +{ + d_sample_counter = 0; // SAMPLE COUNTER + d_active = false; + d_state = 0; + d_queue = queue; + d_freq = freq; + d_fs_in = fs_in; + d_samples_per_ms = samples_per_ms; + d_samples_per_code = samples_per_code; + d_sampled_ms = sampled_ms; + d_max_dwells = max_dwells; + d_well_count = 0; + d_doppler_max = doppler_max; + d_fft_size = d_sampled_ms * d_samples_per_ms; + d_mag = 0; + d_input_power = 0.0; + d_num_doppler_bins = 0; + + //todo: do something if posix_memalign fails + if (posix_memalign((void**)&d_fft_code_A, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_fft_code_B, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_magnitude, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + + // Direct FFT + d_fft_if = new gr::fft::fft_complex(d_fft_size, true); + + // Inverse FFT + d_ifft = new gr::fft::fft_complex(d_fft_size, false); + + // For dumping samples into a file + d_dump = dump; + d_dump_filename = dump_filename; +} + + +galileo_pcps_8ms_acquisition_cc::~galileo_pcps_8ms_acquisition_cc() +{ + + for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++) + { + free(d_grid_doppler_wipeoffs[doppler_index]); + } + + + if (d_num_doppler_bins > 0) + { + delete[] d_grid_doppler_wipeoffs; + } + + free(d_fft_code_A); + free(d_fft_code_B); + free(d_magnitude); + + delete d_ifft; + delete d_fft_if; + + if (d_dump) + { + d_dump_file.close(); + } +} + + +void galileo_pcps_8ms_acquisition_cc::set_local_code(std::complex * code) +{ + memcpy(d_fft_if->get_inbuf(), code, sizeof(gr_complex)*d_fft_size); + + d_fft_if->execute(); // We need the FFT of local code + + //Conjugate the local code + if (is_unaligned()) + { + volk_32fc_conjugate_32fc_u(d_fft_code_A,d_fft_if->get_outbuf(),d_fft_size); + } + else + { + volk_32fc_conjugate_32fc_a(d_fft_code_A,d_fft_if->get_outbuf(),d_fft_size); + } + + + volk_32fc_s32fc_multiply_32fc_a(&(d_fft_if->get_inbuf())[d_samples_per_code], + &code[d_samples_per_code], gr_complex(-1,0), + d_samples_per_code); + + d_fft_if->execute(); // We need the FFT of local code + + //Conjugate the local code + if (is_unaligned()) + { + volk_32fc_conjugate_32fc_u(d_fft_code_B,d_fft_if->get_outbuf(),d_fft_size); + } + else + { + volk_32fc_conjugate_32fc_a(d_fft_code_B,d_fft_if->get_outbuf(),d_fft_size); + } +} + + +void galileo_pcps_8ms_acquisition_cc::init() +{ + d_gnss_synchro->Acq_delay_samples = 0.0; + d_gnss_synchro->Acq_doppler_hz = 0.0; + d_gnss_synchro->Acq_samplestamp_samples = 0; + d_mag = 0.0; + d_input_power = 0.0; + + // Create the carrier Doppler wipeoff signals + d_num_doppler_bins = 0;//floor(2*std::abs((int)d_doppler_max)/d_doppler_step); + for (int doppler = (int)(-d_doppler_max); doppler <= (int)d_doppler_max; doppler += d_doppler_step) + { + d_num_doppler_bins++; + } + d_grid_doppler_wipeoffs = new gr_complex*[d_num_doppler_bins]; + for (unsigned int doppler_index=0;doppler_indexAcq_delay_samples = 0.0; + d_gnss_synchro->Acq_doppler_hz = 0.0; + d_gnss_synchro->Acq_samplestamp_samples = 0; + d_well_count = 0; + d_mag = 0.0; + d_input_power = 0.0; + d_test_statistics = 0.0; + + d_state = 1; + } + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + break; + } + + case 1: + { + // initialize acquisition algorithm + int doppler; + unsigned int indext = 0; + unsigned int indext_A = 0; + unsigned int indext_B = 0; + float magt = 0.0; + float magt_A = 0.0; + float magt_B = 0.0; + const gr_complex *in = (const gr_complex *)input_items[0]; //Get the input samples pointer + float fft_normalization_factor = (float)d_fft_size * (float)d_fft_size; + d_input_power = 0.0; + d_mag = 0.0; + + d_sample_counter += d_fft_size; // sample counter + + d_well_count++; + + DLOG(INFO) << "Channel: " << d_channel + << " , doing acquisition of satellite: " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN + << " ,sample stamp: " << d_sample_counter << ", threshold: " + << d_threshold << ", doppler_max: " << d_doppler_max + << ", doppler_step: " << d_doppler_step; + + // 1- Compute the input signal power estimation + volk_32fc_magnitude_squared_32f_a(d_magnitude, in, d_fft_size); + volk_32f_accumulator_s32f_a(&d_input_power, d_magnitude, d_fft_size); + d_input_power /= (float)d_fft_size; + + // 2- Doppler frequency search loop + for (unsigned int doppler_index=0;doppler_indexget_inbuf(), in, + d_grid_doppler_wipeoffs[doppler_index], d_fft_size); + + // 3- Perform the FFT-based convolution (parallel time search) + // Compute the FFT of the carrier wiped--off incoming signal + d_fft_if->execute(); + + // Multiply carrier wiped--off, Fourier transformed incoming signal + // with the local FFT'd code reference using SIMD operations with VOLK library + volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), + d_fft_if->get_outbuf(), d_fft_code_A, d_fft_size); + + // compute the inverse FFT + d_ifft->execute(); + + // Search maximum + volk_32fc_magnitude_squared_32f_a(d_magnitude, d_ifft->get_outbuf(), d_fft_size); + volk_32f_index_max_16u_a(&indext_A, d_magnitude, d_fft_size); + + // Normalize the maximum value to correct the scale factor introduced by FFTW + magt_A = d_magnitude[indext_A] / (fft_normalization_factor * fft_normalization_factor); + + // Multiply carrier wiped--off, Fourier transformed incoming signal + // with the local FFT'd code reference using SIMD operations with VOLK library + volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), + d_fft_if->get_outbuf(), d_fft_code_B, d_fft_size); + + // compute the inverse FFT + d_ifft->execute(); + + // Search maximum + volk_32fc_magnitude_squared_32f_a(d_magnitude, d_ifft->get_outbuf(), d_fft_size); + volk_32f_index_max_16u_a(&indext_B, d_magnitude, d_fft_size); + + // Normalize the maximum value to correct the scale factor introduced by FFTW + magt_B = d_magnitude[indext_B] / (fft_normalization_factor * fft_normalization_factor); + + if (magt_A >= magt_B) + { + magt = magt_A; + indext = indext_A; + } + else + { + magt = magt_B; + indext = indext_B; + } + + // 4- record the maximum peak and the associated synchronization parameters + if (d_mag < magt) + { + d_mag = magt; + d_gnss_synchro->Acq_delay_samples = (double)(indext % d_samples_per_code); + d_gnss_synchro->Acq_doppler_hz = (double)doppler; + d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter; + } + + // Record results to file if required + if (d_dump) + { + std::stringstream filename; + std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write + filename.str(""); + filename << "../data/test_statistics_" << d_gnss_synchro->System + <<"_" << d_gnss_synchro->Signal << "_sat_" + << d_gnss_synchro->PRN << "_doppler_" << doppler << ".dat"; + d_dump_file.open(filename.str().c_str(), std::ios::out | std::ios::binary); + d_dump_file.write((char*)d_ifft->get_outbuf(), n); //write directly |abs(x)|^2 in this Doppler bin? + d_dump_file.close(); + } + } + + // 5- Compute the test statistics and compare to the threshold + //d_test_statistics = 2 * d_fft_size * d_mag / d_input_power; + d_test_statistics = d_mag / d_input_power; + + if (d_test_statistics > d_threshold) + { + d_state = 2; // Positive acquisition + } + else + { + if (d_well_count == d_max_dwells) + { + d_state = 3; // Negative acquisition + } + } + + consume_each(1); + + break; + } + + case 2: + { + // 6.1- Declare positive acquisition using a message queue + DLOG(INFO) << "positive acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + + d_active = false; + d_state = 0; + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + acquisition_message = 1; + d_channel_internal_queue->push(acquisition_message); + + break; + } + + case 3: + { + // 6.2- Declare negative acquisition using a message queue + DLOG(INFO) << "negative acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + + d_active = false; + d_state = 0; + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + acquisition_message = 2; + d_channel_internal_queue->push(acquisition_message); + + break; + } + } + + return 0; +} diff --git a/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.h b/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.h new file mode 100644 index 000000000..8c5b36fe4 --- /dev/null +++ b/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.h @@ -0,0 +1,218 @@ +/*! + * \file galileo_pcps_8ms_acquisition_cc.h + * \brief This class implements a Parallel Code Phase Search Acquisition for + * Galileo E1 signals with coherent integration time = 8 ms (two codes) + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_PCPS_8MS_ACQUISITION_CC_H_ +#define GNSS_SDR_PCPS_8MS_ACQUISITION_CC_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "concurrent_queue.h" +#include "gnss_synchro.h" + +class galileo_pcps_8ms_acquisition_cc; + +typedef boost::shared_ptr galileo_pcps_8ms_acquisition_cc_sptr; + +galileo_pcps_8ms_acquisition_cc_sptr +galileo_pcps_8ms_make_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); + +/*! + * \brief This class implements a Parallel Code Phase Search Acquisition for + * Galileo E1 signals with coherent integration time = 8 ms (two codes) + */ +class galileo_pcps_8ms_acquisition_cc: public gr::block +{ +private: + friend galileo_pcps_8ms_acquisition_cc_sptr + galileo_pcps_8ms_make_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); + + + galileo_pcps_8ms_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); + + void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift, + int doppler_offset); + + + long d_fs_in; + long d_freq; + int d_samples_per_ms; + int d_samples_per_code; + unsigned int d_doppler_resolution; + float d_threshold; + std::string d_satellite_str; + unsigned int d_doppler_max; + unsigned int d_doppler_step; + unsigned int d_sampled_ms; + unsigned int d_max_dwells; + unsigned int d_well_count; + unsigned int d_fft_size; + unsigned long int d_sample_counter; + gr_complex** d_grid_doppler_wipeoffs; + unsigned int d_num_doppler_bins; + gr_complex* d_fft_code_A; + gr_complex* d_fft_code_B; + gr::fft::fft_complex* d_fft_if; + gr::fft::fft_complex* d_ifft; + Gnss_Synchro *d_gnss_synchro; + unsigned int d_code_phase; + float d_doppler_freq; + float d_mag; + float* d_magnitude; + float d_input_power; + float d_test_statistics; + gr::msg_queue::sptr d_queue; + concurrent_queue *d_channel_internal_queue; + std::ofstream d_dump_file; + bool d_active; + int d_state; + bool d_dump; + unsigned int d_channel; + std::string d_dump_filename; + +public: + /*! + * \brief Default destructor. + */ + ~galileo_pcps_8ms_acquisition_cc(); + + /*! + * \brief Set acquisition/tracking common Gnss_Synchro object pointer + * to exchange synchronization data between acquisition and tracking blocks. + * \param p_gnss_synchro Satellite information shared by the processing blocks. + */ + void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) + { + d_gnss_synchro = p_gnss_synchro; + } + + /*! + * \brief Returns the maximum peak of grid search. + */ + unsigned int mag() + { + return d_mag; + } + + /*! + * \brief Initializes acquisition algorithm. + */ + void init(); + + /*! + * \brief Sets local code for PCPS acquisition algorithm. + * \param code - Pointer to the PRN code. + */ + void set_local_code(std::complex * code); + + /*! + * \brief Starts acquisition algorithm, turning from standby mode to + * active mode + * \param active - bool that activates/deactivates the block. + */ + void set_active(bool active) + { + d_active = active; + } + + /*! + * \brief Set acquisition channel unique ID + * \param channel - receiver channel. + */ + void set_channel(unsigned int channel) + { + d_channel = channel; + } + + /*! + * \brief Set statistics threshold of PCPS algorithm. + * \param threshold - Threshold for signal detection (check \ref Navitec2012, + * Algorithm 1, for a definition of this threshold). + */ + void set_threshold(float threshold) + { + d_threshold = threshold; + } + + /*! + * \brief Set maximum Doppler grid search + * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz]. + */ + void set_doppler_max(unsigned int doppler_max) + { + d_doppler_max = doppler_max; + } + + /*! + * \brief Set Doppler steps for the grid search + * \param doppler_step - Frequency bin of the search grid [Hz]. + */ + void set_doppler_step(unsigned int doppler_step) + { + d_doppler_step = doppler_step; + } + + + /*! + * \brief Set tracking channel internal queue. + * \param channel_internal_queue - Channel's internal blocks information queue. + */ + void set_channel_queue(concurrent_queue *channel_internal_queue) + { + d_channel_internal_queue = channel_internal_queue; + } + + /*! + * \brief Parallel Code Phase Search Acquisition signal processing. + */ + int general_work(int noutput_items, gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* GNSS_SDR_PCPS_8MS_ACQUISITION_CC_H_*/ diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_cc.cc index 188ffea51..596e89884 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_cc.cc @@ -44,39 +44,48 @@ using google::LogMessage; pcps_acquisition_cc_sptr pcps_make_acquisition_cc( - unsigned int sampled_ms, unsigned int doppler_max, - long freq, long fs_in, int samples_per_ms, int samples_per_code, - gr::msg_queue::sptr queue, bool dump, std::string dump_filename) + unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename) { return pcps_acquisition_cc_sptr( - new pcps_acquisition_cc(sampled_ms, doppler_max, freq, fs_in, - samples_per_ms, samples_per_code, queue, dump, dump_filename)); + new pcps_acquisition_cc(sampled_ms, max_dwells, doppler_max, freq, fs_in, samples_per_ms, + samples_per_code, bit_transition_flag, queue, dump, dump_filename)); } - pcps_acquisition_cc::pcps_acquisition_cc( - unsigned int sampled_ms, unsigned int doppler_max, - long freq, long fs_in, int samples_per_ms, int samples_per_code, - gr::msg_queue::sptr queue, bool dump, std::string dump_filename) : + unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename) : gr::block("pcps_acquisition_cc", gr::io_signature::make(1, 1, sizeof(gr_complex) * sampled_ms * samples_per_ms), gr::io_signature::make(0, 0, sizeof(gr_complex) * sampled_ms * samples_per_ms)) { d_sample_counter = 0; // SAMPLE COUNTER d_active = false; + d_state = 0; d_queue = queue; d_freq = freq; d_fs_in = fs_in; d_samples_per_ms = samples_per_ms; d_samples_per_code = samples_per_code; d_sampled_ms = sampled_ms; + d_max_dwells = max_dwells; + d_well_count = 0; d_doppler_max = doppler_max; d_fft_size = d_sampled_ms * d_samples_per_ms; d_mag = 0; d_input_power = 0.0; d_num_doppler_bins = 0; + d_bit_transition_flag = bit_transition_flag; //todo: do something if posix_memalign fails if (posix_memalign((void**)&d_fft_codes, 16, d_fft_size * sizeof(gr_complex)) == 0){}; @@ -94,11 +103,9 @@ pcps_acquisition_cc::pcps_acquisition_cc( } - pcps_acquisition_cc::~pcps_acquisition_cc() { - for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++) { free(d_grid_doppler_wipeoffs[doppler_index]); @@ -115,6 +122,7 @@ pcps_acquisition_cc::~pcps_acquisition_cc() delete d_ifft; delete d_fft_if; + if (d_dump) { d_dump_file.close(); @@ -122,7 +130,6 @@ pcps_acquisition_cc::~pcps_acquisition_cc() } - void pcps_acquisition_cc::set_local_code(std::complex * code) { memcpy(d_fft_if->get_inbuf(), code, sizeof(gr_complex)*d_fft_size); @@ -141,7 +148,6 @@ void pcps_acquisition_cc::set_local_code(std::complex * code) } - void pcps_acquisition_cc::init() { d_gnss_synchro->Acq_delay_samples = 0.0; @@ -151,7 +157,11 @@ void pcps_acquisition_cc::init() d_input_power = 0.0; // Create the carrier Doppler wipeoff signals - d_num_doppler_bins=floor(2*std::abs((int)d_doppler_max)/d_doppler_step); + d_num_doppler_bins = 0;//floor(2*std::abs((int)d_doppler_max)/d_doppler_step); + for (int doppler = (int)(-d_doppler_max); doppler <= (int)d_doppler_max; doppler += d_doppler_step) + { + d_num_doppler_bins++; + } d_grid_doppler_wipeoffs = new gr_complex*[d_num_doppler_bins]; for (unsigned int doppler_index=0;doppler_indexAcq_delay_samples = 0.0; + d_gnss_synchro->Acq_doppler_hz = 0.0; + d_gnss_synchro->Acq_samplestamp_samples = 0; + d_well_count = 0; + d_mag = 0.0; + d_input_power = 0.0; + d_test_statistics = 0.0; + + d_state = 1; + } + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + break; } - else + + case 1: { // initialize acquisition algorithm int doppler; unsigned int indext = 0; float magt = 0.0; const gr_complex *in = (const gr_complex *)input_items[0]; //Get the input samples pointer - bool positive_acquisition = false; - int acquisition_message = -1; //0=STOP_CHANNEL 1=ACQ_SUCCEES 2=ACQ_FAIL - //aux vars - unsigned int i; - float fft_normalization_factor; + float fft_normalization_factor = (float)d_fft_size * (float)d_fft_size; + d_input_power = 0.0; + d_mag = 0.0; d_sample_counter += d_fft_size; // sample counter - //restart acquisition variables - d_gnss_synchro->Acq_delay_samples = 0.0; - d_gnss_synchro->Acq_doppler_hz = 0.0; - d_mag = 0.0; - d_input_power = 0.0; + d_well_count++; DLOG(INFO) << "Channel: " << d_channel << " , doing acquisition of satellite: " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN @@ -214,19 +238,22 @@ int pcps_acquisition_cc::general_work(int noutput_items, << ", doppler_step: " << d_doppler_step; // 1- Compute the input signal power estimation - if (is_unaligned()) - { - volk_32fc_magnitude_squared_32f_u(d_magnitude, in, d_fft_size); - for (i = 0; i < d_fft_size; i++) - d_input_power += d_magnitude[i]; - } - else - { - volk_32fc_magnitude_squared_32f_a(d_magnitude, in, d_fft_size); - volk_32f_accumulator_s32f_a(&d_input_power, d_magnitude, d_fft_size); - } + volk_32fc_magnitude_squared_32f_a(d_magnitude, in, d_fft_size); + +// for(int i =0; i < 10 ;i++){ +// DLOG(INFO) << "d_magnitude["<< i <<"] " << d_magnitude[i]; +// } + + volk_32f_accumulator_s32f_a(&d_input_power, d_magnitude, d_fft_size); + +// DLOG(INFO) << "d_input_power before " << d_input_power; + d_input_power /= (float)d_fft_size; +// DLOG(INFO) << "d_fft_size " << d_fft_size; +// DLOG(INFO) << "d_input_power " << d_input_power; + + // 2- Doppler frequency search loop for (unsigned int doppler_index=0;doppler_indexget_inbuf(), in, - d_grid_doppler_wipeoffs[doppler_index], d_fft_size); - } - else - { - volk_32fc_x2_multiply_32fc_a(d_fft_if->get_inbuf(), in, - d_grid_doppler_wipeoffs[doppler_index], d_fft_size); - } + volk_32fc_x2_multiply_32fc_a(d_fft_if->get_inbuf(), in, + d_grid_doppler_wipeoffs[doppler_index], d_fft_size); // 3- Perform the FFT-based convolution (parallel time search) // Compute the FFT of the carrier wiped--off incoming signal @@ -251,43 +270,15 @@ int pcps_acquisition_cc::general_work(int noutput_items, // Multiply carrier wiped--off, Fourier transformed incoming signal // with the local FFT'd code reference using SIMD operations with VOLK library - if (is_unaligned()) - { - volk_32fc_x2_multiply_32fc_u(d_ifft->get_inbuf(), - d_fft_if->get_outbuf(), d_fft_codes, d_fft_size); - } - else - { - volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), - d_fft_if->get_outbuf(), d_fft_codes, d_fft_size); - } + volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), + d_fft_if->get_outbuf(), d_fft_codes, d_fft_size); // compute the inverse FFT d_ifft->execute(); // Search maximum - indext = 0; - magt = 0.0; - - fft_normalization_factor = (float)d_fft_size * (float)d_fft_size; - - if (is_unaligned()) - { - volk_32fc_magnitude_squared_32f_u(d_magnitude, d_ifft->get_outbuf(), d_fft_size); - for (i = 0; i < d_fft_size; i++) - { - if(d_magnitude[i] > magt) - { - magt = d_magnitude[i]; - indext = i; - } - } - } - else - { - volk_32fc_magnitude_squared_32f_a(d_magnitude, d_ifft->get_outbuf(), d_fft_size); - volk_32f_index_max_16u_a(&indext, d_magnitude, d_fft_size); - } + volk_32fc_magnitude_squared_32f_a(d_magnitude, d_ifft->get_outbuf(), d_fft_size); + volk_32f_index_max_16u_a(&indext, d_magnitude, d_fft_size); // Normalize the maximum value to correct the scale factor introduced by FFTW magt = d_magnitude[indext] / (fft_normalization_factor * fft_normalization_factor); @@ -296,8 +287,17 @@ int pcps_acquisition_cc::general_work(int noutput_items, if (d_mag < magt) { d_mag = magt; - d_gnss_synchro->Acq_delay_samples = (double)(indext % d_samples_per_code); - d_gnss_synchro->Acq_doppler_hz = (double)doppler; + + if (d_test_statistics < (magt / d_input_power) || !d_bit_transition_flag) + { + d_gnss_synchro->Acq_delay_samples = (double)(indext % d_samples_per_code); + d_gnss_synchro->Acq_doppler_hz = (double)doppler; + d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter; + + // 5- Compute the test statistics and compare to the threshold + //d_test_statistics = 2 * d_fft_size * d_mag / d_input_power; + d_test_statistics = d_mag / d_input_power; + } } // Record results to file if required @@ -315,51 +315,90 @@ int pcps_acquisition_cc::general_work(int noutput_items, } } - // 5- Compute the test statistics and compare to the threshold - //d_test_statistics = 2 * d_fft_size * d_mag / d_input_power; - d_test_statistics = d_mag / d_input_power; - - // 6- Declare positive or negative acquisition using a message queue - if (d_test_statistics > d_threshold) + if (!d_bit_transition_flag) { - positive_acquisition = true; - d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter; - DLOG(INFO) << "positive acquisition"; - DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; - DLOG(INFO) << "sample_stamp " << d_sample_counter; - DLOG(INFO) << "test statistics value " << d_test_statistics; - DLOG(INFO) << "test statistics threshold " << d_threshold; - DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; - DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; - DLOG(INFO) << "magnitude " << d_mag; - DLOG(INFO) << "input signal power " << d_input_power; + if (d_test_statistics > d_threshold) + { + d_state = 2; // Positive acquisition + } + else + { + if (d_well_count == d_max_dwells) + { + d_state = 3; // Negative acquisition + } + } } else { - DLOG(INFO) << "negative acquisition"; - DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; - DLOG(INFO) << "sample_stamp " << d_sample_counter; - DLOG(INFO) << "test statistics value " << d_test_statistics; - DLOG(INFO) << "test statistics threshold " << d_threshold; - DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; - DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; - DLOG(INFO) << "magnitude " << d_mag; - DLOG(INFO) << "input signal power " << d_input_power; + if (d_well_count == d_max_dwells) + { + if (d_test_statistics > d_threshold) + { + d_state = 2; // Positive acquisition + } + else + { + d_state = 3; // Negative acquisition + } + } } + consume_each(1); + + break; + } + + case 2: + { + // 6.1- Declare positive acquisition using a message queue + DLOG(INFO) << "positive acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + d_active = false; + d_state = 0; - if (positive_acquisition) - { - acquisition_message = 1; - } - else - { - acquisition_message = 2; - } + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + acquisition_message = 1; d_channel_internal_queue->push(acquisition_message); - consume_each(1); + + break; } + + case 3: + { + // 6.2- Declare negative acquisition using a message queue + DLOG(INFO) << "negative acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + + d_active = false; + d_state = 0; + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + acquisition_message = 2; + d_channel_internal_queue->push(acquisition_message); + + break; + } + } + return 0; } diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_cc.h b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_cc.h index 0dc3aed09..2d8a2a87d 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_cc.h +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_cc.h @@ -66,9 +66,12 @@ class pcps_acquisition_cc; typedef boost::shared_ptr pcps_acquisition_cc_sptr; pcps_acquisition_cc_sptr -pcps_make_acquisition_cc(unsigned int sampled_ms, unsigned int doppler_max, - long freq, long fs_in, int samples_per_ms, int samples_per_code, - gr::msg_queue::sptr queue, bool dump, std::string dump_filename); +pcps_make_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); /*! * \brief This class implements a Parallel Code Phase Search Acquisition. @@ -80,13 +83,20 @@ class pcps_acquisition_cc: public gr::block { private: friend pcps_acquisition_cc_sptr - pcps_make_acquisition_cc(unsigned int sampled_ms, unsigned int doppler_max, - long freq, long fs_in, int samples_per_ms, int samples_per_code, - gr::msg_queue::sptr queue, bool dump, std::string dump_filename); + pcps_make_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); - pcps_acquisition_cc(unsigned int sampled_ms, unsigned int doppler_max, - long freq, long fs_in, int samples_per_ms, int samples_per_code, - gr::msg_queue::sptr queue, bool dump, std::string dump_filename); + + pcps_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift, int doppler_offset); @@ -98,10 +108,12 @@ private: int d_samples_per_code; unsigned int d_doppler_resolution; float d_threshold; - std::string d_satellite_str; + std::string d_satellite_str; unsigned int d_doppler_max; unsigned int d_doppler_step; unsigned int d_sampled_ms; + unsigned int d_max_dwells; + unsigned int d_well_count; unsigned int d_fft_size; unsigned long int d_sample_counter; gr_complex** d_grid_doppler_wipeoffs; @@ -109,17 +121,19 @@ private: gr_complex* d_fft_codes; gr::fft::fft_complex* d_fft_if; gr::fft::fft_complex* d_ifft; - Gnss_Synchro *d_gnss_synchro; + Gnss_Synchro *d_gnss_synchro; unsigned int d_code_phase; float d_doppler_freq; float d_mag; float* d_magnitude; float d_input_power; float d_test_statistics; + bool d_bit_transition_flag; gr::msg_queue::sptr d_queue; concurrent_queue *d_channel_internal_queue; std::ofstream d_dump_file; bool d_active; + int d_state; bool d_dump; unsigned int d_channel; std::string d_dump_filename; diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.cc new file mode 100644 index 000000000..524c4ae02 --- /dev/null +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.cc @@ -0,0 +1,420 @@ +/*! + * \file pcps_cccwsr_acquisition_cc.cc + * \brief This class implements a Parallel Code Phase Search acquisition + * with Coherent Channel Combining With Sign Recovery scheme. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * D.Borio, C.O'Driscoll, G.Lachapelle, "Coherent, Noncoherent and + * Differentially Coherent Combining Techniques for Acquisition of + * New Composite GNSS Signals", IEEE Transactions On Aerospace and + * Electronic Systems vol. 45 no. 3, July 2009, section IV + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "pcps_cccwsr_acquisition_cc.h" +#include "gnss_signal_processing.h" +#include "control_message_factory.h" +#include +#include +#include +#include +#include +#include + +using google::LogMessage; + +pcps_cccwsr_acquisition_cc_sptr pcps_cccwsr_make_acquisition_cc( + unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename) + +{ + + return pcps_cccwsr_acquisition_cc_sptr( + new pcps_cccwsr_acquisition_cc(sampled_ms, max_dwells, doppler_max, freq, fs_in, + samples_per_ms, samples_per_code, queue, dump, dump_filename)); +} + + +pcps_cccwsr_acquisition_cc::pcps_cccwsr_acquisition_cc( + unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename) : + gr::block("pcps_cccwsr_acquisition_cc", + gr::io_signature::make(1, 1, sizeof(gr_complex) * sampled_ms * samples_per_ms), + gr::io_signature::make(0, 0, sizeof(gr_complex) * sampled_ms * samples_per_ms)) +{ + d_sample_counter = 0; // SAMPLE COUNTER + d_active = false; + d_state = 0; + d_queue = queue; + d_freq = freq; + d_fs_in = fs_in; + d_samples_per_ms = samples_per_ms; + d_samples_per_code = samples_per_code; + d_sampled_ms = sampled_ms; + d_max_dwells = max_dwells; + d_well_count = 0; + d_doppler_max = doppler_max; + d_fft_size = d_sampled_ms * d_samples_per_ms; + d_mag = 0; + d_input_power = 0.0; + d_num_doppler_bins = 0; + + //todo: do something if posix_memalign fails + if (posix_memalign((void**)&d_fft_code_data, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_fft_code_pilot, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_data_correlation, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_pilot_correlation, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_correlation_plus, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_correlation_minus, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_magnitude, 16, d_fft_size * sizeof(float)) == 0){}; + + // Direct FFT + d_fft_if = new gr::fft::fft_complex(d_fft_size, true); + + // Inverse FFT + d_ifft = new gr::fft::fft_complex(d_fft_size, false); + + // For dumping samples into a file + d_dump = dump; + d_dump_filename = dump_filename; +} + + +pcps_cccwsr_acquisition_cc::~pcps_cccwsr_acquisition_cc() +{ + + for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++) + { + free(d_grid_doppler_wipeoffs[doppler_index]); + } + + + if (d_num_doppler_bins > 0) + { + delete[] d_grid_doppler_wipeoffs; + } + + free(d_fft_code_data); + free(d_fft_code_pilot); + free(d_data_correlation); + free(d_pilot_correlation); + free(d_correlation_plus); + free(d_correlation_minus); + free(d_magnitude); + + delete d_ifft; + delete d_fft_if; + + if (d_dump) + { + d_dump_file.close(); + } +} + + +void pcps_cccwsr_acquisition_cc::set_local_code(std::complex * code_data, + std::complex * code_pilot) +{ + memcpy(d_fft_if->get_inbuf(), code_data, sizeof(gr_complex)*d_fft_size); + + d_fft_if->execute(); // We need the FFT of local code + + //Conjugate the local code + if (is_unaligned()) + { + volk_32fc_conjugate_32fc_u(d_fft_code_data,d_fft_if->get_outbuf(),d_fft_size); + } + else + { + volk_32fc_conjugate_32fc_a(d_fft_code_data,d_fft_if->get_outbuf(),d_fft_size); + } + + memcpy(d_fft_if->get_inbuf(), code_pilot, sizeof(gr_complex)*d_fft_size); + + d_fft_if->execute(); // We need the FFT of local code + + //Conjugate the local code, + if (is_unaligned()) + { + volk_32fc_conjugate_32fc_u(d_fft_code_pilot,d_fft_if->get_outbuf(),d_fft_size); + } + else + { + volk_32fc_conjugate_32fc_a(d_fft_code_pilot,d_fft_if->get_outbuf(),d_fft_size); + } +} + + +void pcps_cccwsr_acquisition_cc::init() +{ + d_gnss_synchro->Acq_delay_samples = 0.0; + d_gnss_synchro->Acq_doppler_hz = 0.0; + d_gnss_synchro->Acq_samplestamp_samples = 0; + d_mag = 0.0; + d_input_power = 0.0; + + // Create the carrier Doppler wipeoff signals + d_num_doppler_bins = 0;//floor(2*std::abs((int)d_doppler_max)/d_doppler_step); + for (int doppler = (int)(-d_doppler_max); doppler <= (int)d_doppler_max; doppler += d_doppler_step) + { + d_num_doppler_bins++; + } + d_grid_doppler_wipeoffs = new gr_complex*[d_num_doppler_bins]; + for (unsigned int doppler_index=0;doppler_indexAcq_delay_samples = 0.0; + d_gnss_synchro->Acq_doppler_hz = 0.0; + d_gnss_synchro->Acq_samplestamp_samples = 0; + d_well_count = 0; + d_mag = 0.0; + d_input_power = 0.0; + d_test_statistics = 0.0; + + d_state = 1; + } + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + break; + } + case 1: + { + // initialize acquisition algorithm + int doppler; + unsigned int indext = 0; + unsigned int indext_plus = 0; + unsigned int indext_minus = 0; + float magt = 0.0; + float magt_plus = 0.0; + float magt_minus = 0.0; + const gr_complex *in = (const gr_complex *)input_items[0]; //Get the input samples pointer + float fft_normalization_factor = (float)d_fft_size * (float)d_fft_size; + + d_sample_counter += d_fft_size; // sample counter + + d_well_count++; + + DLOG(INFO) << "Channel: " << d_channel + << " , doing acquisition of satellite: " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN + << " ,sample stamp: " << d_sample_counter << ", threshold: " + << d_threshold << ", doppler_max: " << d_doppler_max + << ", doppler_step: " << d_doppler_step; + + // 1- Compute the input signal power estimation + volk_32fc_magnitude_squared_32f_a(d_magnitude, in, d_fft_size); + volk_32f_accumulator_s32f_a(&d_input_power, d_magnitude, d_fft_size); + d_input_power /= (float)d_fft_size; + + // 2- Doppler frequency search loop + for (unsigned int doppler_index=0;doppler_indexget_inbuf(), in, + d_grid_doppler_wipeoffs[doppler_index], d_fft_size); + + // 3- Perform the FFT-based convolution (parallel time search) + // Compute the FFT of the carrier wiped--off incoming signal + d_fft_if->execute(); + + // Multiply carrier wiped--off, Fourier transformed incoming signal + // with the local FFT'd code reference {data+j*pilot} using SIMD operations with VOLK library + volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), + d_fft_if->get_outbuf(), d_fft_code_data, d_fft_size); + + // compute the inverse FFT + d_ifft->execute(); + + memcpy(d_data_correlation, d_ifft->get_outbuf(), sizeof(gr_complex)*d_fft_size); + + + volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), + d_fft_if->get_outbuf(), d_fft_code_pilot, d_fft_size); + + d_ifft->execute(); + + memcpy(d_pilot_correlation, d_ifft->get_outbuf(), sizeof(gr_complex)*d_fft_size); + + for (unsigned int i = 0; i < d_fft_size; i++) + { + d_correlation_plus[i] = std::complex( + d_data_correlation[i].real() - d_pilot_correlation[i].imag(), + d_data_correlation[i].imag() + d_pilot_correlation[i].real()); + + d_correlation_minus[i] = std::complex( + d_data_correlation[i].real() + d_pilot_correlation[i].imag(), + d_data_correlation[i].imag() - d_pilot_correlation[i].real()); + } + + volk_32fc_magnitude_squared_32f_a(d_magnitude, d_correlation_plus, d_fft_size); + volk_32f_index_max_16u_a(&indext_plus, d_magnitude, d_fft_size); + magt_plus = d_magnitude[indext_plus] / (fft_normalization_factor * fft_normalization_factor); + + volk_32fc_magnitude_squared_32f_a(d_magnitude, d_correlation_minus, d_fft_size); + volk_32f_index_max_16u_a(&indext_minus, d_magnitude, d_fft_size); + magt_minus = d_magnitude[indext_minus] / (fft_normalization_factor * fft_normalization_factor); + + if (magt_plus >= magt_minus) + { + magt = magt_plus; + indext = indext_plus; + } + else + { + magt = magt_minus; + indext = indext_minus; + } + + // 4- record the maximum peak and the associated synchronization parameters + if (d_mag < magt) + { + d_mag = magt; + d_gnss_synchro->Acq_delay_samples = (double)(indext % d_samples_per_code); + d_gnss_synchro->Acq_doppler_hz = (double)doppler; + d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter; + } + + // Record results to file if required + if (d_dump) + { + std::stringstream filename; + std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write + filename.str(""); + filename << "../data/test_statistics_" << d_gnss_synchro->System + <<"_" << d_gnss_synchro->Signal << "_sat_" + << d_gnss_synchro->PRN << "_doppler_" << doppler << ".dat"; + d_dump_file.open(filename.str().c_str(), std::ios::out | std::ios::binary); + d_dump_file.write((char*)d_ifft->get_outbuf(), n); //write directly |abs(x)|^2 in this Doppler bin? + d_dump_file.close(); + } + } + + // 5- Compute the test statistics and compare to the threshold + //d_test_statistics = 2 * d_fft_size * d_mag / d_input_power; + d_test_statistics = d_mag / d_input_power; + + // 6- Declare positive or negative acquisition using a message queue + if (d_test_statistics > d_threshold) + { + d_state = 2; // Positive acquisition + } + else + { + if (d_well_count == d_max_dwells) + { + d_state = 3; // Negative acquisition + } + } + + break; + } + + case 2: + { + // 6.1- Declare positive acquisition using a message queue + DLOG(INFO) << "positive acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + + d_active = false; + d_state = 0; + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + acquisition_message = 1; + d_channel_internal_queue->push(acquisition_message); + + break; + } + + case 3: + { + // 6.2- Declare negative acquisition using a message queue + DLOG(INFO) << "negative acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + + d_active = false; + d_state = 0; + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + acquisition_message = 2; + d_channel_internal_queue->push(acquisition_message); + + break; + } + } + + return 0; +} diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.h b/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.h new file mode 100644 index 000000000..8cc769ea6 --- /dev/null +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.h @@ -0,0 +1,230 @@ +/*! + * \file pcps_cccwsr_acquisition_cc.h + * \brief This class implements a Parallel Code Phase Search acquisition + * with Coherent Channel Combining With Sign Recovery scheme. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * D.Borio, C.O'Driscoll, G.Lachapelle, "Coherent, Noncoherent and + * Differentially Coherent Combining Techniques for Acquisition of + * New Composite GNSS Signals", IEEE Transactions On Aerospace and + * Electronic Systems vol. 45 no. 3, July 2009, section IV + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_PCPS_CCCWSR_ACQUISITION_CC_H_ +#define GNSS_SDR_PCPS_CCCWSR_ACQUISITION_CC_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "concurrent_queue.h" +#include "gnss_synchro.h" +#include + +class pcps_cccwsr_acquisition_cc; + +typedef boost::shared_ptr pcps_cccwsr_acquisition_cc_sptr; + +pcps_cccwsr_acquisition_cc_sptr +pcps_cccwsr_make_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); + +/*! + * \brief This class implements a Parallel Code Phase Search Acquisition with + * Coherent Channel Combining With Sign Recovery scheme. + */ +class pcps_cccwsr_acquisition_cc: public gr::block +{ +private: + friend pcps_cccwsr_acquisition_cc_sptr + pcps_cccwsr_make_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); + + + pcps_cccwsr_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); + + void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift, + int doppler_offset); + + + long d_fs_in; + long d_freq; + int d_samples_per_ms; + int d_samples_per_code; + unsigned int d_doppler_resolution; + float d_threshold; + std::string d_satellite_str; + unsigned int d_doppler_max; + unsigned int d_doppler_step; + unsigned int d_sampled_ms; + unsigned int d_max_dwells; + unsigned int d_well_count; + unsigned int d_fft_size; + unsigned long int d_sample_counter; + gr_complex** d_grid_doppler_wipeoffs; + unsigned int d_num_doppler_bins; + gr_complex* d_fft_code_data; + gr_complex* d_fft_code_pilot; + gr::fft::fft_complex* d_fft_if; + gr::fft::fft_complex* d_ifft; + Gnss_Synchro *d_gnss_synchro; + unsigned int d_code_phase; + float d_doppler_freq; + float d_mag; + float* d_magnitude; + gr_complex* d_data_correlation; + gr_complex* d_pilot_correlation; + gr_complex* d_correlation_plus; + gr_complex* d_correlation_minus; + float d_input_power; + float d_test_statistics; + gr::msg_queue::sptr d_queue; + concurrent_queue *d_channel_internal_queue; + std::ofstream d_dump_file; + bool d_active; + int d_state; + bool d_dump; + unsigned int d_channel; + std::string d_dump_filename; + +public: + /*! + * \brief Default destructor. + */ + ~pcps_cccwsr_acquisition_cc(); + + /*! + * \brief Set acquisition/tracking common Gnss_Synchro object pointer + * to exchange synchronization data between acquisition and tracking blocks. + * \param p_gnss_synchro Satellite information shared by the processing blocks. + */ + void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) + { + d_gnss_synchro = p_gnss_synchro; + } + + /*! + * \brief Returns the maximum peak of grid search. + */ + unsigned int mag() + { + return d_mag; + } + + /*! + * \brief Initializes acquisition algorithm. + */ + void init(); + + /*! + * \brief Sets local code for CCCWSR acquisition algorithm. + * \param data_code - Pointer to the data PRN code. + * \param pilot_code - Pointer to the pilot PRN code. + */ + void set_local_code(std::complex * code_data, std::complex * code_pilot); + + /*! + * \brief Starts acquisition algorithm, turning from standby mode to + * active mode + * \param active - bool that activates/deactivates the block. + */ + void set_active(bool active) + { + d_active = active; + } + + /*! + * \brief Set acquisition channel unique ID + * \param channel - receiver channel. + */ + void set_channel(unsigned int channel) + { + d_channel = channel; + } + + /*! + * \brief Set statistics threshold of CCCWSR algorithm. + * \param threshold - Threshold for signal detection (check \ref Navitec2012, + * Algorithm 1, for a definition of this threshold). + */ + void set_threshold(float threshold) + { + d_threshold = threshold; + } + + /*! + * \brief Set maximum Doppler grid search + * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz]. + */ + void set_doppler_max(unsigned int doppler_max) + { + d_doppler_max = doppler_max; + } + + /*! + * \brief Set Doppler steps for the grid search + * \param doppler_step - Frequency bin of the search grid [Hz]. + */ + void set_doppler_step(unsigned int doppler_step) + { + d_doppler_step = doppler_step; + } + + + /*! + * \brief Set tracking channel internal queue. + * \param channel_internal_queue - Channel's internal blocks information queue. + */ + void set_channel_queue(concurrent_queue *channel_internal_queue) + { + d_channel_internal_queue = channel_internal_queue; + } + + /*! + * \brief Coherent Channel Combining With Sign Recovery Acquisition signal processing. + */ + int general_work(int noutput_items, gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +}; + +#endif /* GNSS_SDR_PCPS_CCCWSR_ACQUISITION_CC_H_*/ diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.cc new file mode 100644 index 000000000..79f746b55 --- /dev/null +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.cc @@ -0,0 +1,401 @@ +/*! + * \file pcps_multithread_acquisition_cc.cc + * \brief This class implements a Parallel Code Phase Search Acquisition + * \authors
    + *
  • Javier Arribas, 2011. jarribas(at)cttc.es + *
  • Luis Esteve, 2012. luis(at)epsilon-formacion.com + *
  • Marc Molina, 2013. marc.molina.pena@gmail.com + *
+ * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "pcps_multithread_acquisition_cc.h" +#include "gnss_signal_processing.h" +#include "control_message_factory.h" +#include +#include +#include +#include +#include + +using google::LogMessage; + +pcps_multithread_acquisition_cc_sptr pcps_make_multithread_acquisition_cc( + unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename) +{ + + return pcps_multithread_acquisition_cc_sptr( + new pcps_multithread_acquisition_cc(sampled_ms, max_dwells, doppler_max, freq, fs_in, samples_per_ms, + samples_per_code, bit_transition_flag, queue, dump, dump_filename)); +} + + +pcps_multithread_acquisition_cc::pcps_multithread_acquisition_cc( + unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename) : + gr::block("pcps_multithread_acquisition_cc", + gr::io_signature::make(1, 1, sizeof(gr_complex) * sampled_ms * samples_per_ms), + gr::io_signature::make(0, 0, sizeof(gr_complex) * sampled_ms * samples_per_ms)) +{ + d_sample_counter = 0; // SAMPLE COUNTER + d_active = false; + d_state = 0; + d_queue = queue; + d_freq = freq; + d_fs_in = fs_in; + d_samples_per_ms = samples_per_ms; + d_samples_per_code = samples_per_code; + d_sampled_ms = sampled_ms; + d_max_dwells = max_dwells; + d_well_count = 0; + d_doppler_max = doppler_max; + d_fft_size = d_sampled_ms * d_samples_per_ms; + d_mag = 0; + d_input_power = 0.0; + d_num_doppler_bins = 0; + d_bit_transition_flag = bit_transition_flag; + + //todo: do something if posix_memalign fails + if (posix_memalign((void**)&d_fft_codes, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_magnitude, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + + // Direct FFT + d_fft_if = new gr::fft::fft_complex(d_fft_size, true); + + // Inverse FFT + d_ifft = new gr::fft::fft_complex(d_fft_size, false); + + // For dumping samples into a file + d_dump = dump; + d_dump_filename = dump_filename; +} + + +pcps_multithread_acquisition_cc::~pcps_multithread_acquisition_cc() +{ + + for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++) + { + free(d_grid_doppler_wipeoffs[doppler_index]); + } + + + if (d_num_doppler_bins > 0) + { + delete[] d_grid_doppler_wipeoffs; + } + + free(d_fft_codes); + free(d_magnitude); + + delete d_ifft; + delete d_fft_if; + + if (d_dump) + { + d_dump_file.close(); + } +} + + +void pcps_multithread_acquisition_cc::set_local_code(std::complex * code) +{ + memcpy(d_fft_if->get_inbuf(), code, sizeof(gr_complex)*d_fft_size); + + d_fft_if->execute(); // We need the FFT of local code + + //Conjugate the local code + if (is_unaligned()) + { + volk_32fc_conjugate_32fc_u(d_fft_codes,d_fft_if->get_outbuf(),d_fft_size); + } + else + { + volk_32fc_conjugate_32fc_a(d_fft_codes,d_fft_if->get_outbuf(),d_fft_size); + } +} + +void pcps_multithread_acquisition_cc::perform_acquisition(const gr_complex* in, unsigned int samplestamp) +{ + // initialize acquisition algorithm + int doppler; + unsigned int indext = 0; + float magt = 0.0; + float fft_normalization_factor = (float)d_fft_size * (float)d_fft_size; + d_input_power = 0.0; + d_mag = 0.0; + + d_well_count++; + + DLOG(INFO) << "Channel: " << d_channel + << " , doing acquisition of satellite: " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN + << " ,sample stamp: " << d_sample_counter << ", threshold: " + << d_threshold << ", doppler_max: " << d_doppler_max + << ", doppler_step: " << d_doppler_step; + + // 1- Compute the input signal power estimation + volk_32fc_magnitude_squared_32f_a(d_magnitude, in, d_fft_size); + volk_32f_accumulator_s32f_a(&d_input_power, d_magnitude, d_fft_size); + d_input_power /= (float)d_fft_size; + + // 2- Doppler frequency search loop + for (unsigned int doppler_index=0;doppler_indexget_inbuf(), in, + d_grid_doppler_wipeoffs[doppler_index], d_fft_size); + + // 3- Perform the FFT-based convolution (parallel time search) + // Compute the FFT of the carrier wiped--off incoming signal + d_fft_if->execute(); + + // Multiply carrier wiped--off, Fourier transformed incoming signal + // with the local FFT'd code reference using SIMD operations with VOLK library + volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), + d_fft_if->get_outbuf(), d_fft_codes, d_fft_size); + + // compute the inverse FFT + d_ifft->execute(); + + // Search maximum + volk_32fc_magnitude_squared_32f_a(d_magnitude, d_ifft->get_outbuf(), d_fft_size); + volk_32f_index_max_16u_a(&indext, d_magnitude, d_fft_size); + + // Normalize the maximum value to correct the scale factor introduced by FFTW + magt = d_magnitude[indext] / (fft_normalization_factor * fft_normalization_factor); + + // 4- record the maximum peak and the associated synchronization parameters + if (d_mag < magt) + { + d_mag = magt; + + if (d_test_statistics < (magt / d_input_power) || !d_bit_transition_flag) + { + d_gnss_synchro->Acq_delay_samples = (double)(indext % d_samples_per_code); + d_gnss_synchro->Acq_doppler_hz = (double)doppler; + d_gnss_synchro->Acq_samplestamp_samples = samplestamp; + + // 5- Compute the test statistics and compare to the threshold + //d_test_statistics = 2 * d_fft_size * d_mag / d_input_power; + d_test_statistics = d_mag / d_input_power; + } + } + + // Record results to file if required + if (d_dump) + { + std::stringstream filename; + std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write + filename.str(""); + filename << "../data/test_statistics_" << d_gnss_synchro->System + <<"_" << d_gnss_synchro->Signal << "_sat_" + << d_gnss_synchro->PRN << "_doppler_" << doppler << ".dat"; + d_dump_file.open(filename.str().c_str(), std::ios::out | std::ios::binary); + d_dump_file.write((char*)d_ifft->get_outbuf(), n); //write directly |abs(x)|^2 in this Doppler bin? + d_dump_file.close(); + } + } + + if (!d_bit_transition_flag) + { + if (d_test_statistics > d_threshold) + { + d_state = 3; // Positive acquisition + } + else + { + if (d_well_count == d_max_dwells) + { + d_state = 4; // Negative acquisition + } + else + { + d_state = 1; // Process next block + } + } + } + else + { + if (d_well_count == d_max_dwells) + { + if (d_test_statistics > d_threshold) + { + d_state = 3; // Positive acquisition + } + else + { + d_state = 4; // Negative acquisition + } + } + else + { + d_state = 1; // Process next block + } + } +} + + +void pcps_multithread_acquisition_cc::init() +{ + d_gnss_synchro->Acq_delay_samples = 0.0; + d_gnss_synchro->Acq_doppler_hz = 0.0; + d_gnss_synchro->Acq_samplestamp_samples = 0; + d_mag = 0.0; + d_input_power = 0.0; + + // Create the carrier Doppler wipeoff signals + d_num_doppler_bins = 0;//floor(2*std::abs((int)d_doppler_max)/d_doppler_step); + for (int doppler = (int)(-d_doppler_max); doppler <= (int)d_doppler_max; doppler += d_doppler_step) + { + d_num_doppler_bins++; + } + d_grid_doppler_wipeoffs = new gr_complex*[d_num_doppler_bins]; + for (unsigned int doppler_index=0;doppler_indexAcq_delay_samples = 0.0; + d_gnss_synchro->Acq_doppler_hz = 0.0; + d_gnss_synchro->Acq_samplestamp_samples = 0; + d_well_count = 0; + d_mag = 0.0; + d_input_power = 0.0; + d_test_statistics = 0.0; + + d_state = 1; + } + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + break; + } + + case 1: + { + const gr_complex *in = (const gr_complex *)input_items[0]; //Get the input samples pointer + d_sample_counter += d_fft_size; // sample counter + boost::thread(&pcps_multithread_acquisition_cc::perform_acquisition, this, in, d_sample_counter); + d_state = 2; + consume_each(1); + + break; + } + + case 2: + { + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + break; + } + case 3: + { + + // Declare positive acquisition using a message queue + DLOG(INFO) << "positive acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + + d_active = false; + d_state = 0; + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + acquisition_message = 1; + d_channel_internal_queue->push(acquisition_message); + + break; + } + + case 4: + { + // Declare negative acquisition using a message queue + DLOG(INFO) << "negative acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + + d_active = false; + d_state = 0; + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + acquisition_message = 2; + d_channel_internal_queue->push(acquisition_message); + + break; + } + } + + return 0; +} diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.h b/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.h new file mode 100644 index 000000000..d9a5ba8be --- /dev/null +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_multithread_acquisition_cc.h @@ -0,0 +1,243 @@ +/*! + * \file pcps_multithread_acquisition_cc.h + * \brief This class implements a Parallel Code Phase Search Acquisition + * + * Acquisition strategy (Kay Borre book + CFAR threshold). + *
    + *
  1. Compute the input signal power estimation + *
  2. Doppler serial search loop + *
  3. Perform the FFT-based circular convolution (parallel time search) + *
  4. Record the maximum peak and the associated synchronization parameters + *
  5. Compute the test statistics and compare to the threshold + *
  6. Declare positive or negative acquisition using a message queue + *
+ * + * Kay Borre book: K.Borre, D.M.Akos, N.Bertelsen, P.Rinder, and S.H.Jensen, + * "A Software-Defined GPS and Galileo Receiver. A Single-Frequency + * Approach", Birkha user, 2007. pp 81-84 + * + * \authors
    + *
  • Javier Arribas, 2011. jarribas(at)cttc.es + *
  • Luis Esteve, 2012. luis(at)epsilon-formacion.com + *
  • Marc Molina, 2013. marc.molina.pena@gmail.com + *
+ * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_PCPS_MULTITHREAD_ACQUISITION_CC_H_ +#define GNSS_SDR_PCPS_MULTITHREAD_ACQUISITION_CC_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "concurrent_queue.h" +#include "gnss_synchro.h" + +class pcps_multithread_acquisition_cc; + +typedef boost::shared_ptr pcps_multithread_acquisition_cc_sptr; + +pcps_multithread_acquisition_cc_sptr +pcps_make_multithread_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); + +/*! + * \brief This class implements a Parallel Code Phase Search Acquisition. + * + * Check \ref Navitec2012 "An Open Source Galileo E1 Software Receiver", + * Algorithm 1, for a pseudocode description of this implementation. + */ +class pcps_multithread_acquisition_cc: public gr::block +{ +private: + friend pcps_multithread_acquisition_cc_sptr + pcps_make_multithread_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); + + + pcps_multithread_acquisition_cc(unsigned int sampled_ms, unsigned int max_dwells, + unsigned int doppler_max, long freq, long fs_in, + int samples_per_ms, int samples_per_code, + bool bit_transition_flag, + gr::msg_queue::sptr queue, bool dump, + std::string dump_filename); + + void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift, + int doppler_offset); + + + long d_fs_in; + long d_freq; + int d_samples_per_ms; + int d_samples_per_code; + unsigned int d_doppler_resolution; + float d_threshold; + std::string d_satellite_str; + unsigned int d_doppler_max; + unsigned int d_doppler_step; + unsigned int d_sampled_ms; + unsigned int d_max_dwells; + unsigned int d_well_count; + unsigned int d_fft_size; + unsigned long int d_sample_counter; + gr_complex** d_grid_doppler_wipeoffs; + unsigned int d_num_doppler_bins; + gr_complex* d_fft_codes; + gr::fft::fft_complex* d_fft_if; + gr::fft::fft_complex* d_ifft; + Gnss_Synchro *d_gnss_synchro; + unsigned int d_code_phase; + float d_doppler_freq; + float d_mag; + float* d_magnitude; + float d_input_power; + float d_test_statistics; + bool d_bit_transition_flag; + gr::msg_queue::sptr d_queue; + concurrent_queue *d_channel_internal_queue; + std::ofstream d_dump_file; + bool d_active; + int d_state; + bool d_dump; + unsigned int d_channel; + std::string d_dump_filename; + +public: + /*! + * \brief Default destructor. + */ + ~pcps_multithread_acquisition_cc(); + + /*! + * \brief Set acquisition/tracking common Gnss_Synchro object pointer + * to exchange synchronization data between acquisition and tracking blocks. + * \param p_gnss_synchro Satellite information shared by the processing blocks. + */ + void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) + { + d_gnss_synchro = p_gnss_synchro; + } + + /*! + * \brief Returns the maximum peak of grid search. + */ + unsigned int mag() + { + return d_mag; + } + + /*! + * \brief Initializes acquisition algorithm. + */ + void init(); + + /*! + * \brief Sets local code for PCPS acquisition algorithm. + * \param code - Pointer to the PRN code. + */ + void set_local_code(std::complex * code); + + /*! + * \brief Starts acquisition algorithm, turning from standby mode to + * active mode + * \param active - bool that activates/deactivates the block. + */ + void set_active(bool active) + { + d_active = active; + } + + /*! + * \brief Set acquisition channel unique ID + * \param channel - receiver channel. + */ + void set_channel(unsigned int channel) + { + d_channel = channel; + } + + /*! + * \brief Set statistics threshold of PCPS algorithm. + * \param threshold - Threshold for signal detection (check \ref Navitec2012, + * Algorithm 1, for a definition of this threshold). + */ + void set_threshold(float threshold) + { + d_threshold = threshold; + } + + /*! + * \brief Set maximum Doppler grid search + * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz]. + */ + void set_doppler_max(unsigned int doppler_max) + { + d_doppler_max = doppler_max; + } + + /*! + * \brief Set Doppler steps for the grid search + * \param doppler_step - Frequency bin of the search grid [Hz]. + */ + void set_doppler_step(unsigned int doppler_step) + { + d_doppler_step = doppler_step; + } + + + /*! + * \brief Set tracking channel internal queue. + * \param channel_internal_queue - Channel's internal blocks information queue. + */ + void set_channel_queue(concurrent_queue *channel_internal_queue) + { + d_channel_internal_queue = channel_internal_queue; + } + + /*! + * \brief Parallel Code Phase Search Acquisition signal processing. + */ + int general_work(int noutput_items, gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void perform_acquisition(const gr_complex* in, const unsigned int samplestamp); +}; + +#endif /* GNSS_SDR_PCPS_MULTITHREAD_ACQUISITION_CC_H_*/ diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.cc new file mode 100644 index 000000000..5adc1aaec --- /dev/null +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.cc @@ -0,0 +1,408 @@ +/*! + * \file pcps_tong_acquisition_cc.h + * \brief This class implements a Parallel Code Phase Search Acquisition with + * Tong algorithm. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * Acquisition strategy (Kaplan book + CFAR threshold). + *
    + *
  1. Compute the input signal power estimation. + *
  2. Doppler serial search loop. + *
  3. Perform the FFT-based circular convolution (parallel time search). + *
  4. Compute the tests statistics for all the cells. + *
  5. Accumulate the grid of tests statistics with the previous grids. + *
  6. Record the maximum peak and the associated synchronization parameters. + *
  7. Compare the maximum averaged test statistics with a threshold. + *
  8. If the test statistics exceeds the threshold, increment the Tong counter. + *
  9. Otherwise, decrement the Tong counter. + *
  10. If the Tong counter is equal to a given maximum value, declare positive + *
  11. acquisition. If the Tong counter is equa to zero, declare negative + *
  12. acquisition. Otherwise, process the next block. + *
+ * + * Kaplan book: D.Kaplan, J.Hegarty, "Understanding GPS. Principles + * and Applications", Artech House, 2006, pp 223-227 + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "pcps_tong_acquisition_cc.h" +#include "gnss_signal_processing.h" +#include "control_message_factory.h" +#include +#include +#include +#include +#include + +using google::LogMessage; + +pcps_tong_acquisition_cc_sptr pcps_tong_make_acquisition_cc( + unsigned int sampled_ms, unsigned int doppler_max, + long freq, long fs_in, int samples_per_ms, + int samples_per_code, unsigned int tong_init_val, + unsigned int tong_max_val, gr::msg_queue::sptr queue, + bool dump, std::string dump_filename) +{ + return pcps_tong_acquisition_cc_sptr( + new pcps_tong_acquisition_cc(sampled_ms, doppler_max, freq, fs_in, samples_per_ms, samples_per_code, + tong_init_val, tong_max_val, queue, dump, dump_filename)); +} + + +pcps_tong_acquisition_cc::pcps_tong_acquisition_cc( + unsigned int sampled_ms, unsigned int doppler_max, + long freq, long fs_in, int samples_per_ms, + int samples_per_code, unsigned int tong_init_val, + unsigned int tong_max_val, gr::msg_queue::sptr queue, + bool dump, std::string dump_filename) : + gr::block("pcps_tong_acquisition_cc", + gr::io_signature::make(1, 1, sizeof(gr_complex) * sampled_ms * samples_per_ms), + gr::io_signature::make(0, 0, sizeof(gr_complex) * sampled_ms * samples_per_ms)) +{ + d_sample_counter = 0; // SAMPLE COUNTER + d_active = false; + d_state = 0; + d_queue = queue; + d_freq = freq; + d_fs_in = fs_in; + d_samples_per_ms = samples_per_ms; + d_samples_per_code = samples_per_code; + d_sampled_ms = sampled_ms; + d_well_count = 0; + d_tong_max_val = tong_max_val; + d_tong_init_val = tong_init_val; + d_tong_count = d_tong_init_val; + d_doppler_max = doppler_max; + d_fft_size = d_sampled_ms * d_samples_per_ms; + d_mag = 0; + d_input_power = 0.0; + d_num_doppler_bins = 0; + + //todo: do something if posix_memalign fails + if (posix_memalign((void**)&d_fft_codes, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + if (posix_memalign((void**)&d_magnitude, 16, d_fft_size * sizeof(gr_complex)) == 0){}; + + // Direct FFT + d_fft_if = new gr::fft::fft_complex(d_fft_size, true); + + // Inverse FFT + d_ifft = new gr::fft::fft_complex(d_fft_size, false); + + // For dumping samples into a file + d_dump = dump; + d_dump_filename = dump_filename; +} + + +pcps_tong_acquisition_cc::~pcps_tong_acquisition_cc() +{ + + for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++) + { + free(d_grid_doppler_wipeoffs[doppler_index]); + free(d_grid_data[doppler_index]); + } + + + if (d_num_doppler_bins > 0) + { + delete[] d_grid_doppler_wipeoffs; + delete[] d_grid_data; + } + + free(d_fft_codes); + free(d_magnitude); + + delete d_ifft; + delete d_fft_if; + + if (d_dump) + { + d_dump_file.close(); + } +} + + +void pcps_tong_acquisition_cc::set_local_code(std::complex * code) +{ + memcpy(d_fft_if->get_inbuf(), code, sizeof(gr_complex)*d_fft_size); + + d_fft_if->execute(); // We need the FFT of local code + + //Conjugate the local code + if (is_unaligned()) + { + volk_32fc_conjugate_32fc_u(d_fft_codes,d_fft_if->get_outbuf(),d_fft_size); + } + else + { + volk_32fc_conjugate_32fc_a(d_fft_codes,d_fft_if->get_outbuf(),d_fft_size); + } +} + + +void pcps_tong_acquisition_cc::init() +{ + d_gnss_synchro->Acq_delay_samples = 0.0; + d_gnss_synchro->Acq_doppler_hz = 0.0; + d_gnss_synchro->Acq_samplestamp_samples = 0; + d_mag = 0.0; + d_input_power = 0.0; + + // Create the carrier Doppler wipeoff signals + d_num_doppler_bins = 0;//floor(2*std::abs((int)d_doppler_max)/d_doppler_step); + for (int doppler = (int)(-d_doppler_max); doppler <= (int)d_doppler_max; doppler += d_doppler_step) + { + d_num_doppler_bins++; + } + d_grid_doppler_wipeoffs = new gr_complex*[d_num_doppler_bins]; + d_grid_data = new float*[d_num_doppler_bins]; + for (unsigned int doppler_index=0;doppler_indexAcq_delay_samples = 0.0; + d_gnss_synchro->Acq_doppler_hz = 0.0; + d_gnss_synchro->Acq_samplestamp_samples = 0; + d_well_count = 0; + d_tong_count = d_tong_init_val; + d_mag = 0.0; + d_input_power = 0.0; + d_test_statistics = 0.0; + + for (unsigned int doppler_index=0;doppler_indexSystem << " "<< d_gnss_synchro->PRN + << " ,sample stamp: " << d_sample_counter << ", threshold: " + << d_threshold << ", doppler_max: " << d_doppler_max + << ", doppler_step: " << d_doppler_step; + + // 1- Compute the input signal power estimation + volk_32fc_magnitude_squared_32f_a(d_magnitude, in, d_fft_size); + volk_32f_accumulator_s32f_a(&d_input_power, d_magnitude, d_fft_size); + d_input_power /= (float)d_fft_size; + + // 2- Doppler frequency search loop + for (unsigned int doppler_index=0;doppler_indexget_inbuf(), in, + d_grid_doppler_wipeoffs[doppler_index], d_fft_size); + + // 3- Perform the FFT-based convolution (parallel time search) + // Compute the FFT of the carrier wiped--off incoming signal + d_fft_if->execute(); + + // Multiply carrier wiped--off, Fourier transformed incoming signal + // with the local FFT'd code reference using SIMD operations with VOLK library + volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), + d_fft_if->get_outbuf(), d_fft_codes, d_fft_size); + + // compute the inverse FFT + d_ifft->execute(); + + // Search maximum + volk_32fc_magnitude_squared_32f_a(d_magnitude, d_ifft->get_outbuf(), d_fft_size); + + volk_32f_s32f_multiply_32f_a(d_magnitude, d_magnitude, + 1/(fft_normalization_factor*fft_normalization_factor*d_input_power), + d_fft_size); + + volk_32f_x2_add_32f_a(d_grid_data[doppler_index], d_magnitude, d_grid_data[doppler_index], d_fft_size); + + volk_32f_index_max_16u_a(&indext, d_grid_data[doppler_index], d_fft_size); + + // Normalize the maximum value to correct the scale factor introduced by FFTW + magt = d_grid_data[doppler_index][indext]; + + // 4- record the maximum peak and the associated synchronization parameters + if (d_mag < magt) + { + d_mag = magt; + d_gnss_synchro->Acq_delay_samples = (double)(indext % d_samples_per_code); + d_gnss_synchro->Acq_doppler_hz = (double)doppler; + d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter; + } + + // Record results to file if required + if (d_dump) + { + std::stringstream filename; + std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write + filename.str(""); + filename << "../data/test_statistics_" << d_gnss_synchro->System + <<"_" << d_gnss_synchro->Signal << "_sat_" + << d_gnss_synchro->PRN << "_doppler_" << doppler << ".dat"; + d_dump_file.open(filename.str().c_str(), std::ios::out | std::ios::binary); + d_dump_file.write((char*)d_ifft->get_outbuf(), n); //write directly |abs(x)|^2 in this Doppler bin? + d_dump_file.close(); + } + } + + // 5- Compute the test statistics and compare to the threshold + //d_test_statistics = 2 * d_fft_size * d_mag / d_input_power; + d_test_statistics = d_mag; + + if (d_test_statistics > d_threshold*d_well_count) + { + d_tong_count++; + if (d_tong_count == d_tong_max_val) + { + d_state = 2; // Positive acquisition + } + } + else + { + d_tong_count--; + if (d_tong_count == 0) + { + d_state = 3; // Negative acquisition + } + } + + consume_each(1); + + break; + } + + case 2: + { + // 6.1- Declare positive acquisition using a message queue + DLOG(INFO) << "positive acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + + d_active = false; + d_state = 0; + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + acquisition_message = 1; + d_channel_internal_queue->push(acquisition_message); + + break; + } + + case 3: + { + // 6.2- Declare negative acquisition using a message queue + DLOG(INFO) << "negative acquisition"; + DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN; + DLOG(INFO) << "sample_stamp " << d_sample_counter; + DLOG(INFO) << "test statistics value " << d_test_statistics; + DLOG(INFO) << "test statistics threshold " << d_threshold; + DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples; + DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz; + DLOG(INFO) << "magnitude " << d_mag; + DLOG(INFO) << "input signal power " << d_input_power; + + d_active = false; + d_state = 0; + + d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + consume_each(ninput_items[0]); + + acquisition_message = 2; + d_channel_internal_queue->push(acquisition_message); + + break; + } + } + + return 0; +} diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.h b/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.h new file mode 100644 index 000000000..50a4b43ba --- /dev/null +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.h @@ -0,0 +1,239 @@ +/*! + * \file pcps_tong_acquisition_cc.h + * \brief This class implements a Parallel Code Phase Search Acquisition with + * Tong algorithm. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * Acquisition strategy (Kaplan book + CFAR threshold). + *
    + *
  1. Compute the input signal power estimation. + *
  2. Doppler serial search loop. + *
  3. Perform the FFT-based circular convolution (parallel time search). + *
  4. Compute the tests statistics for all the cells. + *
  5. Accumulate the grid of tests statistics with the previous grids. + *
  6. Record the maximum peak and the associated synchronization parameters. + *
  7. Compare the maximum averaged test statistics with a threshold. + *
  8. If the test statistics exceeds the threshold, increment the Tong counter. + *
  9. Otherwise, decrement the Tong counter. + *
  10. If the Tong counter is equal to a given maximum value, declare positive + *
  11. acquisition. If the Tong counter is equa to zero, declare negative + *
  12. acquisition. Otherwise, process the next block. + *
+ * + * Kaplan book: D.Kaplan, J.Hegarty, "Understanding GPS. Principles + * and Applications", Artech House, 2006, pp 223-227 + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_PCPS_TONG_acquisition_cc_H_ +#define GNSS_SDR_PCPS_TONG_acquisition_cc_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "concurrent_queue.h" +#include "gnss_synchro.h" + +class pcps_tong_acquisition_cc; + +typedef boost::shared_ptr pcps_tong_acquisition_cc_sptr; + +pcps_tong_acquisition_cc_sptr +pcps_tong_make_acquisition_cc(unsigned int sampled_ms, unsigned int doppler_max, + long freq, long fs_in, int samples_per_ms, + int samples_per_code, unsigned int tong_init_val, + unsigned int tong_max_val, gr::msg_queue::sptr queue, + bool dump, std::string dump_filename); + +/*! + * \brief This class implements a Parallel Code Phase Search Acquisition with + * Tong algorithm. + */ +class pcps_tong_acquisition_cc: public gr::block +{ +private: + friend pcps_tong_acquisition_cc_sptr + pcps_tong_make_acquisition_cc(unsigned int sampled_ms, unsigned int doppler_max, + long freq, long fs_in, int samples_per_ms, + int samples_per_code, unsigned int tong_init_val, + unsigned int tong_max_val, gr::msg_queue::sptr queue, + bool dump, std::string dump_filename); + + + pcps_tong_acquisition_cc(unsigned int sampled_ms, unsigned int doppler_max, + long freq, long fs_in, int samples_per_ms, + int samples_per_code, unsigned int tong_init_val, + unsigned int tong_max_val, gr::msg_queue::sptr queue, + bool dump, std::string dump_filename); + + void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift, + int doppler_offset); + + + long d_fs_in; + long d_freq; + int d_samples_per_ms; + int d_samples_per_code; + unsigned int d_doppler_resolution; + float d_threshold; + std::string d_satellite_str; + unsigned int d_doppler_max; + unsigned int d_doppler_step; + unsigned int d_sampled_ms; + unsigned int d_well_count; + unsigned int d_tong_count; + unsigned int d_tong_init_val; + unsigned int d_tong_max_val; + unsigned int d_fft_size; + unsigned long int d_sample_counter; + gr_complex** d_grid_doppler_wipeoffs; + unsigned int d_num_doppler_bins; + gr_complex* d_fft_codes; + float** d_grid_data; + gr::fft::fft_complex* d_fft_if; + gr::fft::fft_complex* d_ifft; + Gnss_Synchro *d_gnss_synchro; + unsigned int d_code_phase; + float d_doppler_freq; + float d_mag; + float* d_magnitude; + float d_input_power; + float d_test_statistics; + gr::msg_queue::sptr d_queue; + concurrent_queue *d_channel_internal_queue; + std::ofstream d_dump_file; + bool d_active; + int d_state; + bool d_dump; + unsigned int d_channel; + std::string d_dump_filename; + +public: + /*! + * \brief Default destructor. + */ + ~pcps_tong_acquisition_cc(); + + /*! + * \brief Set acquisition/tracking common Gnss_Synchro object pointer + * to exchange synchronization data between acquisition and tracking blocks. + * \param p_gnss_synchro Satellite information shared by the processing blocks. + */ + void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) + { + d_gnss_synchro = p_gnss_synchro; + } + + /*! + * \brief Returns the maximum peak of grid search. + */ + unsigned int mag() + { + return d_mag; + } + + /*! + * \brief Initializes acquisition algorithm. + */ + void init(); + + /*! + * \brief Sets local code for TONG acquisition algorithm. + * \param code - Pointer to the PRN code. + */ + void set_local_code(std::complex * code); + + /*! + * \brief Starts acquisition algorithm, turning from standby mode to + * active mode + * \param active - bool that activates/deactivates the block. + */ + void set_active(bool active) + { + d_active = active; + } + + /*! + * \brief Set acquisition channel unique ID + * \param channel - receiver channel. + */ + void set_channel(unsigned int channel) + { + d_channel = channel; + } + + /*! + * \brief Set statistics threshold of TONG algorithm. + * \param threshold - Threshold for signal detection (check \ref Navitec2012, + * Algorithm 1, for a definition of this threshold). + */ + void set_threshold(float threshold) + { + d_threshold = threshold; + } + + /*! + * \brief Set maximum Doppler grid search + * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz]. + */ + void set_doppler_max(unsigned int doppler_max) + { + d_doppler_max = doppler_max; + } + + /*! + * \brief Set Doppler steps for the grid search + * \param doppler_step - Frequency bin of the search grid [Hz]. + */ + void set_doppler_step(unsigned int doppler_step) + { + d_doppler_step = doppler_step; + } + + + /*! + * \brief Set tracking channel internal queue. + * \param channel_internal_queue - Channel's internal blocks information queue. + */ + void set_channel_queue(concurrent_queue *channel_internal_queue) + { + d_channel_internal_queue = channel_internal_queue; + } + + /*! + * \brief Parallel Code Phase Search Acquisition signal processing. + */ + int general_work(int noutput_items, gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* GNSS_SDR_PCPS_TONG_acquisition_cc_H_ */ diff --git a/src/algorithms/libs/gps_sdr_signal_processing.h b/src/algorithms/libs/gps_sdr_signal_processing.h index 3434f1312..10d63c5d5 100644 --- a/src/algorithms/libs/gps_sdr_signal_processing.h +++ b/src/algorithms/libs/gps_sdr_signal_processing.h @@ -40,6 +40,9 @@ //!Generates complex GPS L1 C/A code for the desired SV ID and code shift, and sampled to specific sampling frequency void gps_l1_ca_code_gen_complex(std::complex* _dest, signed int _prn, unsigned int _chip_shift); +//! Generates N complex GPS L1 C/A codes for the desired SV ID and code shift +void gps_l1_ca_code_gen_complex_sampled(std::complex* _dest, unsigned int _prn, signed int _fs, unsigned int _chip_shift, unsigned int _ncodes); + //! Generates complex GPS L1 C/A code for the desired SV ID and code shift void gps_l1_ca_code_gen_complex_sampled(std::complex* _dest, unsigned int _prn, signed int _fs, unsigned int _chip_shift); diff --git a/src/algorithms/signal_generator/adapters/signal_generator.cc b/src/algorithms/signal_generator/adapters/signal_generator.cc index c2cb9c922..7f571aa62 100644 --- a/src/algorithms/signal_generator/adapters/signal_generator.cc +++ b/src/algorithms/signal_generator/adapters/signal_generator.cc @@ -1,6 +1,6 @@ /*! * \file signal_generator.cc - * \brief Signal generator. + * \brief Adapter of a class that generates synthesized GNSS signal. * \author Marc Molina, 2013. marc.molina.pena@gmail.com * * diff --git a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc index d31ce6b47..1e8d94c12 100644 --- a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc +++ b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc @@ -1,5 +1,5 @@ /*! - * \file signal_generator_c.h + * \file signal_generator_c.cc * \brief GNU Radio source block that generates synthesized GNSS signal. * \author Marc Molina, 2013. marc.molina.pena@gmail.com * @@ -27,9 +27,9 @@ * * ------------------------------------------------------------------------- */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +//#ifdef HAVE_CONFIG_H +//#include "config.h" +//#endif #include "signal_generator_c.h" #include @@ -73,7 +73,7 @@ signal_generator_c::signal_generator_c (std::vector system, const s fs_in_(fs_in), num_sats_(PRN.size()), vector_length_(vector_length), - BW_BB_(BW_BB*(float)fs_in/2) + BW_BB_(BW_BB*(float)fs_in/2.0) { init(); generate_codes(); @@ -122,14 +122,14 @@ void signal_generator_c::init() // for (unsigned int i = 0; i < num_sats_; i++) // { // std::cout << "Sat " << i << ": " << std::endl; -// std::cout << "System " << system_[i] << ": " << std::endl; +// std::cout << " System " << system_[i] << ": " << std::endl; // std::cout << " PRN: " << PRN_[i] << std::endl; // std::cout << " CN0: " << CN0_dB_[i] << std::endl; // std::cout << " Doppler: " << doppler_Hz_[i] << std::endl; // std::cout << " Delay: " << delay_chips_[i] << std::endl; -// std::cout << "Samples per code = " << samples_per_code_[i] << std::endl; -// std::cout << "codes per vector = " << num_of_codes_per_vector_[i] << std::endl; -// std::cout << "data_bit_duration = " << data_bit_duration_ms_[i] << std::endl; +// std::cout << " Samples per code = " << samples_per_code_[i] << std::endl; +// std::cout << " codes per vector = " << num_of_codes_per_vector_[i] << std::endl; +// std::cout << " data_bit_duration = " << data_bit_duration_ms_[i] << std::endl; // } } @@ -152,9 +152,12 @@ void signal_generator_c::generate_codes() (int)GPS_L1_CA_CODE_LENGTH_CHIPS-delay_chips_[sat]); // Obtain the desired CN0 assuming that Pn = 1. - for (unsigned int i = 0; i < samples_per_code_[sat]; i++) + if (noise_flag_) { - code[i] *= sqrt(pow(10,CN0_dB_[sat]/10)/BW_BB_); + for (unsigned int i = 0; i < samples_per_code_[sat]; i++) + { + code[i] *= sqrt(pow(10,CN0_dB_[sat]/10)/BW_BB_); + } } // Concatenate "num_of_codes_per_vector_" codes @@ -175,9 +178,12 @@ void signal_generator_c::generate_codes() (int)Galileo_E1_B_CODE_LENGTH_CHIPS-delay_chips_[sat]); // Obtain the desired CN0 assuming that Pn = 1. - for (unsigned int i = 0; i < samples_per_code_[sat]; i++) + if (noise_flag_) { - code[i] *= sqrt(pow(10,CN0_dB_[sat]/10)/BW_BB_/2); + for (unsigned int i = 0; i < samples_per_code_[sat]; i++) + { + code[i] *= sqrt(pow(10,CN0_dB_[sat]/10)/BW_BB_/2); + } } // Concatenate "num_of_codes_per_vector_" codes @@ -197,9 +203,12 @@ void signal_generator_c::generate_codes() (int)Galileo_E1_B_CODE_LENGTH_CHIPS-delay_chips_[sat], true); // Obtain the desired CN0 assuming that Pn = 1. - for (unsigned int i = 0; i < vector_length_; i++) + if (noise_flag_) { - sampled_code_pilot_[sat][i] *= sqrt(pow(10,CN0_dB_[sat]/10)/BW_BB_/2); + for (unsigned int i = 0; i < vector_length_; i++) + { + sampled_code_pilot_[sat][i] *= sqrt(pow(10,CN0_dB_[sat]/10)/BW_BB_/2); + } } } } @@ -257,21 +266,20 @@ signal_generator_c::general_work (int noutput_items, for (i = 0; i < num_of_codes_per_vector_[sat]; i++) { - gr_complex prev_data_bit = current_data_bits_[sat]; + for (k = 0; k < delay_samples; k++) + { + out[out_idx] += sampled_code_data_[sat][out_idx] + * current_data_bits_[sat] + * complex_phase_[out_idx]; + out_idx++; + } + if (ms_counter_[sat] == 0 && data_flag_) { // New random data bit current_data_bits_[sat] = gr_complex((rand()%2) == 0 ? 1 : -1, 0); } - for (k = 0; k < delay_samples; k++) - { - out[out_idx] += sampled_code_data_[sat][out_idx] - * prev_data_bit - * complex_phase_[out_idx]; - out_idx++; - } - for (k = delay_samples; k < samples_per_code_[sat]; k++) { out[out_idx] += sampled_code_data_[sat][out_idx] @@ -292,21 +300,20 @@ signal_generator_c::general_work (int noutput_items, for (i = 0; i < num_of_codes_per_vector_[sat]; i++) { - gr_complex prev_data_bit = current_data_bits_[sat]; - if (ms_counter_[sat] == 0 && data_flag_) - { - // New random data bit - current_data_bits_[sat] = gr_complex((rand()%2) == 0 ? -1 : 1, 0); - } - for (k = 0; k < delay_samples; k++) { - out[out_idx] += (sampled_code_data_[sat][out_idx] * prev_data_bit + out[out_idx] += (sampled_code_data_[sat][out_idx] * current_data_bits_[sat] - sampled_code_pilot_[sat][out_idx]) * complex_phase_[out_idx]; out_idx++; } + if (ms_counter_[sat] == 0 && data_flag_) + { + // New random data bit + current_data_bits_[sat] = gr_complex((rand()%2) == 0 ? 1 : -1, 0); + } + for (k = delay_samples; k < samples_per_code_[sat]; k++) { out[out_idx] += (sampled_code_data_[sat][out_idx] * current_data_bits_[sat] diff --git a/src/algorithms/signal_source/CMakeLists.txt b/src/algorithms/signal_source/CMakeLists.txt index ebeb32dc4..1c3ce6ae9 100644 --- a/src/algorithms/signal_source/CMakeLists.txt +++ b/src/algorithms/signal_source/CMakeLists.txt @@ -17,4 +17,4 @@ # add_subdirectory(adapters) -#add_subdirectory(gnuradio_blocks) \ No newline at end of file +#add_subdirectory(gnuradio_blocks) diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index 80d3ea220..af3fb455e 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -54,9 +54,13 @@ #include "fir_filter.h" #include "freq_xlating_fir_filter.h" #include "gps_l1_ca_pcps_acquisition.h" +#include "gps_l1_ca_pcps_tong_acquisition.h" #include "gps_l1_ca_pcps_assisted_acquisition.h" #include "gps_l1_ca_pcps_acquisition_fine_doppler.h" #include "galileo_e1_pcps_ambiguous_acquisition.h" +#include "galileo_e1_pcps_8ms_ambiguous_acquisition.h" +#include "galileo_e1_pcps_tong_ambiguous_acquisition.h" +#include "galileo_e1_pcps_cccwsr_ambiguous_acquisition.h" #include "gps_l1_ca_dll_pll_tracking.h" #include "gps_l1_ca_dll_pll_optim_tracking.h" #include "gps_l1_ca_dll_fll_pll_tracking.h" @@ -332,9 +336,14 @@ GNSSBlockInterface* GNSSBlockFactory::GetBlock( block = new GpsL1CaPcpsAssistedAcquisition(configuration, role, in_streams, out_streams, queue); } - else if (implementation.compare("Galileo_E1_PCPS_Ambiguous_Acquisition") == 0) + else if (implementation.compare("GPS_L1_CA_PCPS_Tong_Acquisition") == 0) { - block = new GalileoE1PcpsAmbiguousAcquisition(configuration, role, in_streams, + block = new GpsL1CaPcpsTongAcquisition(configuration, role, in_streams, + out_streams, queue); + } + else if (implementation.compare("GPS_L1_CA_PCPS_Multithread_Acquisition") == 0) + { + block = new GpsL1CaPcpsAcquisition(configuration, role, in_streams, out_streams, queue); } else if (implementation.compare("GPS_L1_CA_PCPS_Acquisition_Fine_Doppler") == 0) @@ -342,6 +351,26 @@ GNSSBlockInterface* GNSSBlockFactory::GetBlock( block = new GpsL1CaPcpsAcquisitionFineDoppler(configuration, role, in_streams, out_streams, queue); } + else if (implementation.compare("Galileo_E1_PCPS_Ambiguous_Acquisition") == 0) + { + block = new GalileoE1PcpsAmbiguousAcquisition(configuration, role, in_streams, + out_streams, queue); + } + else if (implementation.compare("Galileo_E1_PCPS_8ms_Ambiguous_Acquisition") == 0) + { + block = new GalileoE1Pcps8msAmbiguousAcquisition(configuration, role, in_streams, + out_streams, queue); + } + else if (implementation.compare("Galileo_E1_PCPS_Tong_Ambiguous_Acquisition") == 0) + { + block = new GalileoE1PcpsTongAmbiguousAcquisition(configuration, role, in_streams, + out_streams, queue); + } + else if (implementation.compare("Galileo_E1_PCPS_CCCWSR_Ambiguous_Acquisition") == 0) + { + block = new GalileoE1PcpsCccwsrAmbiguousAcquisition(configuration, role, in_streams, + out_streams, queue); + } // TRACKING BLOCKS ------------------------------------------------------------- else if (implementation.compare("GPS_L1_CA_DLL_PLL_Tracking") == 0) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index bdf6c3dea..8dbb1cc4c 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -80,6 +80,8 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/algorithms/tracking/adapters ${CMAKE_SOURCE_DIR}/src/algorithms/tracking/gnuradio_blocks ${CMAKE_SOURCE_DIR}/src/algorithms/signal_source/adapters + ${CMAKE_SOURCE_DIR}/src/algorithms/signal_generator/adapters + ${CMAKE_SOURCE_DIR}/src/algorithms/signal_generator/gnuradio_blocks ${CMAKE_SOURCE_DIR}/src/algorithms/input_filter/adapters ${CMAKE_SOURCE_DIR}/src/algorithms/acquisition/adapters ${CMAKE_SOURCE_DIR}/src/algorithms/acquisition/gnuradio_blocks @@ -97,7 +99,7 @@ find_library( /usr/local/lib64 /usr/lib /usr/lib64 -) +) add_executable(run_tests ${CMAKE_CURRENT_SOURCE_DIR}/test_main.cc) @@ -118,20 +120,27 @@ add_executable(control_thread_test EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/control_thread/control_message_factory_test.cc ) target_link_libraries(control_thread_test ${Boost_LIBRARIES} ${GFLAGS_LIBS} ${GLOG_LIBRARIES} ${GTEST_LIBRARIES} gnss_sp_libs gnss_rx) -add_test(control_thread_test control_thread_test) +add_test(control_thread_test control_thread_test) add_executable(gnss_block_test EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/single_test_main.cc ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/file_signal_source_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/fir_filter_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/gps_l1_ca_pcps_acquisition_test.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/gps_l1_ca_pcps_acquisition_gsoc2013_test.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/gps_l1_ca_pcps_multithread_acquisition_gsoc2013_test.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/gps_l1_ca_pcps_tong_acquisition_gsoc2013_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/galileo_e1_pcps_ambiguous_acquisition_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc_test.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc2013_test.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/galileo_e1_pcps_8ms_ambiguous_acquisition_gsoc2013_test.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/galileo_e1_pcps_cccwsr_ambiguous_acquisition_gsoc2013_test.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/galileo_e1_pcps_tong_ambiguous_acquisition_gsoc2013_test.cc #${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/galileo_e1_dll_pll_veml_tracking_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/file_output_filter_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/gnss_block/gnss_block_factory_test.cc ) target_link_libraries(gnss_block_test ${Boost_LIBRARIES} ${GFLAGS_LIBS} ${GLOG_LIBRARIES} ${GTEST_LIBRARIES} gnss_sp_libs gnss_rx) -add_test(gnss_block_test gnss_block_test) +add_test(gnss_block_test gnss_block_test) diff --git a/src/tests/gnss_block/galileo_e1_pcps_8ms_ambiguous_acquisition_gsoc2013_test.cc b/src/tests/gnss_block/galileo_e1_pcps_8ms_ambiguous_acquisition_gsoc2013_test.cc new file mode 100644 index 000000000..718a4239f --- /dev/null +++ b/src/tests/gnss_block/galileo_e1_pcps_8ms_ambiguous_acquisition_gsoc2013_test.cc @@ -0,0 +1,577 @@ +/*! + * \file galileo_e1_pcps_8ms_ambiguous_acquisition_gsoc2013_test.cc + * \brief This class implements an acquisition test for + * GalileoE1Pcps8msAmbiguousAcquisition class. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gnss_block_interface.h" +#include "in_memory_configuration.h" +#include "gnss_synchro.h" +#include "galileo_e1_pcps_8ms_ambiguous_acquisition.h" +#include "signal_generator.h" +//#include "signal_generator.cc" +#include "signal_generator_c.h" +//#include "signal_generator_c.cc" +#include "fir_filter.h" +#include "gen_signal_source.h" +#include "boost/shared_ptr.hpp" +#include "gnss_sdr_valve.h" + + + +class GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test: public ::testing::Test +{ +protected: + GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test() + { + queue = gr::msg_queue::make(0); + top_block = gr::make_top_block("Acquisition test"); + item_size = sizeof(gr_complex); + stop = false; + message = 0; + } + + ~GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test() + { + } + + void init(); + void config_1(); + void config_2(); + void start_queue(); + void wait_message(); + void process_message(); + void stop_queue(); + + gr::msg_queue::sptr queue; + gr::top_block_sptr top_block; + GalileoE1Pcps8msAmbiguousAcquisition *acquisition; + InMemoryConfiguration* config; + Gnss_Synchro gnss_synchro; + size_t item_size; + concurrent_queue channel_internal_queue; + bool stop; + int message; + boost::thread ch_thread; + + unsigned int integration_time_ms; + unsigned int fs_in; + + double expected_delay_chips; + double expected_doppler_hz; + float max_doppler_error_hz; + float max_delay_error_chips; + + unsigned int num_of_realizations; + unsigned int realization_counter; + unsigned int detection_counter; + unsigned int correct_estimation_counter; + unsigned int acquired_samples; + unsigned int mean_acq_time_us; + + double mse_doppler; + double mse_delay; + + double Pd; + double Pfa_p; + double Pfa_a; +}; + +void GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test::init() +{ + message = 0; + realization_counter = 0; + detection_counter = 0; + correct_estimation_counter = 0; + acquired_samples = 0; + mse_doppler = 0; + mse_delay = 0; + mean_acq_time_us = 0; + Pd = 0; + Pfa_p = 0; + Pfa_a = 0; +} + +void GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test::config_1() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'E'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 8; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 1; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "1"); + + config->set_property("SignalSource.system_0", "E"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", + std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", + std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.noise_flag", "false"); + config->set_property("SignalSource.data_flag", "false"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_8ms_Ambiguous_Acquisition"); + config->set_property("Acquisition.threshold", "0.2"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test::config_2() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'E'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 8; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 100; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "4"); + + config->set_property("SignalSource.system_0", "E"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", + std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", + std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.system_1", "E"); + config->set_property("SignalSource.PRN_1", "15"); + config->set_property("SignalSource.CN0_dB_1", "44"); + config->set_property("SignalSource.doppler_Hz_1", "1000"); + config->set_property("SignalSource.delay_chips_1", "100"); + + config->set_property("SignalSource.system_2", "G"); + config->set_property("SignalSource.PRN_2", "10"); + config->set_property("SignalSource.CN0_dB_2", "44"); + config->set_property("SignalSource.doppler_Hz_2", "2000"); + config->set_property("SignalSource.delay_chips_2", "200"); + + config->set_property("SignalSource.system_3", "G"); + config->set_property("SignalSource.PRN_3", "20"); + config->set_property("SignalSource.CN0_dB_3", "44"); + config->set_property("SignalSource.doppler_Hz_3", "3000"); + config->set_property("SignalSource.delay_chips_3", "300"); + + config->set_property("SignalSource.noise_flag", "true"); + config->set_property("SignalSource.data_flag", "true"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_8ms_Ambiguous_Acquisition"); + config->set_property("Acquisition.pfa", "1e-1"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test::start_queue() +{ + stop = false; + ch_thread = boost::thread(&GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test::wait_message, this); +} + +void GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test::wait_message() +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + while (!stop) + { + acquisition->reset(); + + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + + channel_internal_queue.wait_and_pop(message); + + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + + mean_acq_time_us += (end-begin); + + process_message(); + } +} + +void GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test::process_message() +{ + if (message == 1) + { + detection_counter++; + + // The term -5 is here to correct the additional delay introduced by the FIR filter + double delay_error_chips = abs((double)expected_delay_chips - (double)(gnss_synchro.Acq_delay_samples-5)*1023.0/((double)fs_in*1e-3)); + double doppler_error_hz = abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); + + mse_delay += std::pow(delay_error_chips, 2); + mse_doppler += std::pow(doppler_error_hz, 2); + + if ((delay_error_chips < max_delay_error_chips) && (doppler_error_hz < max_doppler_error_hz)) + { + correct_estimation_counter++; + } + } + + realization_counter++; + + std::cout << "Progress: " << round((float)realization_counter/num_of_realizations*100) << "% \r" << std::flush; + + if (realization_counter == num_of_realizations) + { + mse_delay /= num_of_realizations; + mse_doppler /= num_of_realizations; + + Pd = (double)correct_estimation_counter / (double)num_of_realizations; + Pfa_a = (double)detection_counter / (double)num_of_realizations; + Pfa_p = (double)(detection_counter-correct_estimation_counter) / (double)num_of_realizations; + + mean_acq_time_us /= num_of_realizations; + + stop_queue(); + top_block->stop(); + + std::cout << std::endl; + } +} + +void GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test::stop_queue() +{ + stop = true; +} + +TEST_F(GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test, Instantiate) +{ + config_1(); + acquisition = new GalileoE1Pcps8msAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + delete acquisition; + delete config; +} + +TEST_F(GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test, ConnectAndRun) +{ + int nsamples = floor(fs_in*integration_time_ms*1e-3); + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + config_1(); + + acquisition = new GalileoE1Pcps8msAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + boost::shared_ptr source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0)); + boost::shared_ptr valve = gnss_sdr_make_valve(sizeof(gr_complex), nsamples, queue); + top_block->connect(source, 0, valve, 0); + top_block->connect(valve, 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + }) << "Failure running he top_block."<< std::endl; + + std::cout << "Processed " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; + + delete acquisition; + delete config; +} + +TEST_F(GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test, ValidationOfResults) +{ + config_1(); + + acquisition = new GalileoE1Pcps8msAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + // i = 0 --> sallite in acquisition is visible + // i = 1 --> satellite in acquisition is not visible + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; + if (message == 1) + { + EXPECT_EQ(1, correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; + } + + } + else if (i == 1) + { + EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; + } + } + + delete acquisition; + delete config; +} + +TEST_F(GalileoE1Pcps8msAmbiguousAcquisitionGSoC2013Test, ValidationOfResultsProbabilities) +{ + config_2(); + + acquisition = new GalileoE1Pcps8msAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + std::cout << "Probability of false alarm (target) = " << 0.1 << std::endl; + + // i = 0 --> sallite in acquisition is visible (prob of detection and prob of detection with wrong estimation) + // i = 1 --> satellite in acquisition is not visible (prob of false detection) + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + std::cout << "Probability of detection = " << Pd << std::endl; + std::cout << "Probability of false alarm (satellite present) = " << Pfa_p << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + else if (i == 1) + { + std::cout << "Probability of false alarm (satellite absent) = " << Pfa_a << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + } + + delete acquisition; + delete config; +} diff --git a/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc2013_test.cc b/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc2013_test.cc new file mode 100644 index 000000000..913a491fd --- /dev/null +++ b/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc2013_test.cc @@ -0,0 +1,581 @@ +/*! + * \file galileo_e1_pcps_ambiguous_acquisition_gsoc2013_test.cc + * \brief This class implements an acquisition test for + * GalileoE1PcpsAmbiguousAcquisition class. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gnss_block_interface.h" +#include "in_memory_configuration.h" +#include "gnss_synchro.h" +#include "galileo_e1_pcps_ambiguous_acquisition.h" +#include "signal_generator.h" +//#include "signal_generator.cc" +#include "signal_generator_c.h" +//#include "signal_generator_c.cc" +#include "fir_filter.h" +#include "gen_signal_source.h" +#include "boost/shared_ptr.hpp" +#include "gnss_sdr_valve.h" + + + +class GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test: public ::testing::Test +{ +protected: + GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test() + { + queue = gr::msg_queue::make(0); + top_block = gr::make_top_block("Acquisition test"); + item_size = sizeof(gr_complex); + stop = false; + message = 0; + } + + ~GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test() + { + } + + void init(); + void config_1(); + void config_2(); + void start_queue(); + void wait_message(); + void process_message(); + void stop_queue(); + + gr::msg_queue::sptr queue; + gr::top_block_sptr top_block; + GalileoE1PcpsAmbiguousAcquisition *acquisition; + InMemoryConfiguration* config; + Gnss_Synchro gnss_synchro; + size_t item_size; + concurrent_queue channel_internal_queue; + bool stop; + int message; + boost::thread ch_thread; + + unsigned int integration_time_ms; + unsigned int fs_in; + + double expected_delay_chips; + double expected_doppler_hz; + float max_doppler_error_hz; + float max_delay_error_chips; + + unsigned int num_of_realizations; + unsigned int realization_counter; + unsigned int detection_counter; + unsigned int correct_estimation_counter; + unsigned int acquired_samples; + unsigned int mean_acq_time_us; + + double mse_doppler; + double mse_delay; + + double Pd; + double Pfa_p; + double Pfa_a; +}; + + +void GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test::init() +{ + message = 0; + realization_counter = 0; + detection_counter = 0; + correct_estimation_counter = 0; + acquired_samples = 0; + mse_doppler = 0; + mse_delay = 0; + mean_acq_time_us = 0; + Pd = 0; + Pfa_p = 0; + Pfa_a = 0; +} + +void GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test::config_1() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'E'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 4; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 1; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "1"); + + config->set_property("SignalSource.system_0", "E"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", + std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", + std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.noise_flag", "false"); + config->set_property("SignalSource.data_flag", "false"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.bit_transition_flag","false"); + config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_Ambiguous_Acquisition"); + config->set_property("Acquisition.threshold", "0.3"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test::config_2() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'E'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 4; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 100; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "4"); + + config->set_property("SignalSource.system_0", "E"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", + std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", + std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.system_1", "E"); + config->set_property("SignalSource.PRN_1", "15"); + config->set_property("SignalSource.CN0_dB_1", "44"); + config->set_property("SignalSource.doppler_Hz_1", "1000"); + config->set_property("SignalSource.delay_chips_1", "100"); + + config->set_property("SignalSource.system_2", "G"); + config->set_property("SignalSource.PRN_2", "10"); + config->set_property("SignalSource.CN0_dB_2", "44"); + config->set_property("SignalSource.doppler_Hz_2", "2000"); + config->set_property("SignalSource.delay_chips_2", "200"); + + config->set_property("SignalSource.system_3", "G"); + config->set_property("SignalSource.PRN_3", "20"); + config->set_property("SignalSource.CN0_dB_3", "44"); + config->set_property("SignalSource.doppler_Hz_3", "3000"); + config->set_property("SignalSource.delay_chips_3", "300"); + + config->set_property("SignalSource.noise_flag", "true"); + config->set_property("SignalSource.data_flag", "true"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.bit_transition_flag","false"); + config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_Ambiguous_Acquisition"); + config->set_property("Acquisition.pfa", "1e-1"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test::start_queue() +{ + stop = false; + ch_thread = boost::thread(&GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test::wait_message, this); +} + +void GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test::wait_message() +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + while (!stop) + { + acquisition->reset(); + + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + + channel_internal_queue.wait_and_pop(message); + + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + + mean_acq_time_us += (end-begin); + + process_message(); + } +} + +void GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test::process_message() +{ + if (message == 1) + { + detection_counter++; + + // The term -5 is here to correct the additional delay introduced by the FIR filter + double delay_error_chips = abs((double)expected_delay_chips - (double)(gnss_synchro.Acq_delay_samples-5)*1023.0/((double)fs_in*1e-3)); + double doppler_error_hz = abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); + + mse_delay += std::pow(delay_error_chips, 2); + mse_doppler += std::pow(doppler_error_hz, 2); + + if ((delay_error_chips < max_delay_error_chips) && (doppler_error_hz < max_doppler_error_hz)) + { + correct_estimation_counter++; + } + } + + realization_counter++; + + std::cout << "Progress: " << round((float)realization_counter/num_of_realizations*100) << "% \r" << std::flush; + + if (realization_counter == num_of_realizations) + { + mse_delay /= num_of_realizations; + mse_doppler /= num_of_realizations; + + Pd = (double)correct_estimation_counter / (double)num_of_realizations; + Pfa_a = (double)detection_counter / (double)num_of_realizations; + Pfa_p = (double)(detection_counter-correct_estimation_counter) / (double)num_of_realizations; + + mean_acq_time_us /= num_of_realizations; + + stop_queue(); + top_block->stop(); + + std::cout << std::endl; + } +} + +void GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test::stop_queue() +{ + stop = true; +} + +TEST_F(GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test, Instantiate) +{ + config_1(); + acquisition = new GalileoE1PcpsAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + delete acquisition; + delete config; +} + +TEST_F(GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test, ConnectAndRun) +{ + int nsamples = floor(fs_in*integration_time_ms*1e-3); + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + config_1(); + + acquisition = new GalileoE1PcpsAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + boost::shared_ptr source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0)); + boost::shared_ptr valve = gnss_sdr_make_valve(sizeof(gr_complex), nsamples, queue); + top_block->connect(source, 0, valve, 0); + top_block->connect(valve, 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + }) << "Failure running he top_block."<< std::endl; + + std::cout << "Processed " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; + + delete acquisition; + delete config; +} + +TEST_F(GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test, ValidationOfResults) +{ + config_1(); + + acquisition = new GalileoE1PcpsAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + // i = 0 --> sallite in acquisition is visible + // i = 1 --> satellite in acquisition is not visible + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; + if (message == 1) + { + EXPECT_EQ(1, correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; + } + } + else if (i == 1) + { + EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; + } + } + + delete acquisition; + delete config; +} + +TEST_F(GalileoE1PcpsAmbiguousAcquisitionGSoC2013Test, ValidationOfResultsProbabilities) +{ + config_2(); + + acquisition = new GalileoE1PcpsAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + std::cout << "Probability of false alarm (target) = " << 0.1 << std::endl; + + // i = 0 --> sallite in acquisition is visible (prob of detection and prob of detection with wrong estimation) + // i = 1 --> satellite in acquisition is not visible (prob of false detection) + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + std::cout << "Probability of detection = " << Pd << std::endl; + std::cout << "Probability of false alarm (satellite present) = " << Pfa_p << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + else if (i == 1) + { + std::cout << "Probability of false alarm (satellite absent) = " << Pfa_a << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + } + + delete acquisition; + delete config; +} diff --git a/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc_test.cc b/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc_test.cc index 2b2456413..beff35c37 100644 --- a/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc_test.cc +++ b/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc_test.cc @@ -111,7 +111,7 @@ void GalileoE1PcpsAmbiguousAcquisitionGSoCTest::init() config->set_property("GNSS-SDR.internal_fs_hz", "4000000"); config->set_property("Acquisition.item_type", "gr_complex"); config->set_property("Acquisition.if", "0"); - config->set_property("Acquisition.sampled_ms", "4"); + config->set_property("Acquisition.coherent_integration_time_ms", "4"); config->set_property("Acquisition.dump", "false"); config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_Ambiguous_Acquisition"); config->set_property("Acquisition.threshold", "50"); diff --git a/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_test.cc b/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_test.cc index a6da62e8e..a0665e5ae 100644 --- a/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_test.cc +++ b/src/tests/gnss_block/galileo_e1_pcps_ambiguous_acquisition_test.cc @@ -98,7 +98,7 @@ void GalileoE1PcpsAmbiguousAcquisitionTest::init() config->set_property("GNSS-SDR.internal_fs_hz", "4000000"); config->set_property("Acquisition.item_type", "gr_complex"); config->set_property("Acquisition.if", "0"); - config->set_property("Acquisition.sampled_ms", "4"); + config->set_property("Acquisition.coherent_integration_time_ms", "4"); config->set_property("Acquisition.dump", "false"); config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_Ambiguous_Acquisition"); config->set_property("Acquisition.threshold", "0.005"); diff --git a/src/tests/gnss_block/galileo_e1_pcps_cccwsr_ambiguous_acquisition_gsoc2013_test.cc b/src/tests/gnss_block/galileo_e1_pcps_cccwsr_ambiguous_acquisition_gsoc2013_test.cc new file mode 100644 index 000000000..d33c6e2aa --- /dev/null +++ b/src/tests/gnss_block/galileo_e1_pcps_cccwsr_ambiguous_acquisition_gsoc2013_test.cc @@ -0,0 +1,579 @@ +/*! + * \file galileo_e1_pcps_cccwsr_ambiguous_acquisition_gsoc2013_test.cc + * \brief This class implements an acquisition test for + * GalileoE1PcpsCccwsrAmbiguousAcquisition class. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gnss_block_interface.h" +#include "in_memory_configuration.h" +#include "gnss_synchro.h" +#include "galileo_e1_pcps_cccwsr_ambiguous_acquisition.h" +#include "signal_generator.h" +//#include "signal_generator.cc" +#include "signal_generator_c.h" +//#include "signal_generator_c.cc" +#include "fir_filter.h" +#include "gen_signal_source.h" +#include "boost/shared_ptr.hpp" +#include "gnss_sdr_valve.h" + + + +class GalileoE1PcpsCccwsrAmbiguousAcquisitionTest: public ::testing::Test +{ +protected: + GalileoE1PcpsCccwsrAmbiguousAcquisitionTest() + { + queue = gr::msg_queue::make(0); + top_block = gr::make_top_block("Acquisition test"); + item_size = sizeof(gr_complex); + stop = false; + message = 0; + } + + ~GalileoE1PcpsCccwsrAmbiguousAcquisitionTest() + { + } + + void init(); + void config_1(); + void config_2(); + void start_queue(); + void wait_message(); + void process_message(); + void stop_queue(); + + gr::msg_queue::sptr queue; + gr::top_block_sptr top_block; + GalileoE1PcpsCccwsrAmbiguousAcquisition *acquisition; + InMemoryConfiguration* config; + Gnss_Synchro gnss_synchro; + size_t item_size; + concurrent_queue channel_internal_queue; + bool stop; + int message; + boost::thread ch_thread; + + unsigned int integration_time_ms; + unsigned int fs_in; + + double expected_delay_chips; + double expected_doppler_hz; + float max_doppler_error_hz; + float max_delay_error_chips; + + unsigned int num_of_realizations; + unsigned int realization_counter; + unsigned int detection_counter; + unsigned int correct_estimation_counter; + unsigned int acquired_samples; + unsigned int mean_acq_time_us; + + double mse_doppler; + double mse_delay; + + double Pd; + double Pfa_p; + double Pfa_a; +}; + +void GalileoE1PcpsCccwsrAmbiguousAcquisitionTest::init() +{ + message = 0; + realization_counter = 0; + detection_counter = 0; + correct_estimation_counter = 0; + acquired_samples = 0; + mse_doppler = 0; + mse_delay = 0; + mean_acq_time_us = 0; + Pd = 0; + Pfa_p = 0; + Pfa_a = 0; +} + +void GalileoE1PcpsCccwsrAmbiguousAcquisitionTest::config_1() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'E'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 4; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 1; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "1"); + + config->set_property("SignalSource.system_0", "E"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", + std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", + std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.noise_flag", "false"); + config->set_property("SignalSource.data_flag", "false"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_CCCWSR_Ambiguous_Acquisition"); + config->set_property("Acquisition.threshold", "0.7"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GalileoE1PcpsCccwsrAmbiguousAcquisitionTest::config_2() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'E'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 4; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 100; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "4"); + + config->set_property("SignalSource.system_0", "E"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", + std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", + std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.system_1", "E"); + config->set_property("SignalSource.PRN_1", "15"); + config->set_property("SignalSource.CN0_dB_1", "44"); + config->set_property("SignalSource.doppler_Hz_1", "1000"); + config->set_property("SignalSource.delay_chips_1", "100"); + + config->set_property("SignalSource.system_2", "G"); + config->set_property("SignalSource.PRN_2", "10"); + config->set_property("SignalSource.CN0_dB_2", "44"); + config->set_property("SignalSource.doppler_Hz_2", "2000"); + config->set_property("SignalSource.delay_chips_2", "200"); + + config->set_property("SignalSource.system_3", "G"); + config->set_property("SignalSource.PRN_3", "20"); + config->set_property("SignalSource.CN0_dB_3", "44"); + config->set_property("SignalSource.doppler_Hz_3", "3000"); + config->set_property("SignalSource.delay_chips_3", "300"); + + config->set_property("SignalSource.noise_flag", "true"); + config->set_property("SignalSource.data_flag", "true"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_CCCWSR_Ambiguous_Acquisition"); + config->set_property("Acquisition.threshold", "0.0025"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GalileoE1PcpsCccwsrAmbiguousAcquisitionTest::start_queue() +{ + stop = false; + ch_thread = boost::thread(&GalileoE1PcpsCccwsrAmbiguousAcquisitionTest::wait_message, this); +} + + +void GalileoE1PcpsCccwsrAmbiguousAcquisitionTest::wait_message() +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + while (!stop) + { + acquisition->reset(); + + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + + channel_internal_queue.wait_and_pop(message); + + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + + mean_acq_time_us += (end-begin); + + process_message(); + } +} + +void GalileoE1PcpsCccwsrAmbiguousAcquisitionTest::process_message() +{ + if (message == 1) + { + detection_counter++; + + // The term -5 is here to correct the additional delay introduced by the FIR filter + double delay_error_chips = abs((double)expected_delay_chips - (double)(gnss_synchro.Acq_delay_samples-5)*1023.0/((double)fs_in*1e-3)); + double doppler_error_hz = abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); + + mse_delay += std::pow(delay_error_chips, 2); + mse_doppler += std::pow(doppler_error_hz, 2); + + if ((delay_error_chips < max_delay_error_chips) && (doppler_error_hz < max_doppler_error_hz)) + { + correct_estimation_counter++; + } + } + + realization_counter++; + + std::cout << "Progress: " << round((float)realization_counter/num_of_realizations*100) << "% \r" << std::flush; + + if (realization_counter == num_of_realizations) + { + mse_delay /= num_of_realizations; + mse_doppler /= num_of_realizations; + + Pd = (double)correct_estimation_counter / (double)num_of_realizations; + Pfa_a = (double)detection_counter / (double)num_of_realizations; + Pfa_p = (double)(detection_counter-correct_estimation_counter) / (double)num_of_realizations; + + mean_acq_time_us /= num_of_realizations; + + stop_queue(); + top_block->stop(); + + std::cout << std::endl; + } +} + +void GalileoE1PcpsCccwsrAmbiguousAcquisitionTest::stop_queue() +{ + stop = true; +} + +TEST_F(GalileoE1PcpsCccwsrAmbiguousAcquisitionTest, Instantiate) +{ + config_1(); + acquisition = new GalileoE1PcpsCccwsrAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + delete acquisition; + delete config; +} + +TEST_F(GalileoE1PcpsCccwsrAmbiguousAcquisitionTest, ConnectAndRun) +{ + int nsamples = floor(fs_in*integration_time_ms*1e-3); + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + config_1(); + + acquisition = new GalileoE1PcpsCccwsrAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + boost::shared_ptr source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0)); + boost::shared_ptr valve = gnss_sdr_make_valve(sizeof(gr_complex), nsamples, queue); + top_block->connect(source, 0, valve, 0); + top_block->connect(valve, 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + }) << "Failure running he top_block."<< std::endl; + + std::cout << "Processed " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; + + delete acquisition; + delete config; +} + +TEST_F(GalileoE1PcpsCccwsrAmbiguousAcquisitionTest, ValidationOfResults) +{ + config_1(); + + acquisition = new GalileoE1PcpsCccwsrAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + // i = 0 --> sallite in acquisition is visible + // i = 1 --> satellite in acquisition is not visible + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; + if (message == 1) + { + EXPECT_EQ(1, correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; + } + } + else if (i == 1) + { + EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; + } + } + + delete acquisition; + delete config; +} + +TEST_F(GalileoE1PcpsCccwsrAmbiguousAcquisitionTest, ValidationOfResultsProbabilities) +{ + config_2(); + + acquisition = new GalileoE1PcpsCccwsrAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + std::cout << "Probability of false alarm (target) = " << 0.0065 << std::endl; + + // i = 0 --> sallite in acquisition is visible (prob of detection and prob of detection with wrong estimation) + // i = 1 --> satellite in acquisition is not visible (prob of false detection) + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + std::cout << "Probability of detection = " << Pd << std::endl; + std::cout << "Probability of false alarm (satellite present) = " << Pfa_p << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + else if (i == 1) + { + std::cout << "Probability of false alarm (satellite absent) = " << Pfa_a << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + } + + delete acquisition; + delete config; +} diff --git a/src/tests/gnss_block/galileo_e1_pcps_tong_ambiguous_acquisition_gsoc2013_test.cc b/src/tests/gnss_block/galileo_e1_pcps_tong_ambiguous_acquisition_gsoc2013_test.cc new file mode 100644 index 000000000..d36820eaa --- /dev/null +++ b/src/tests/gnss_block/galileo_e1_pcps_tong_ambiguous_acquisition_gsoc2013_test.cc @@ -0,0 +1,579 @@ +/*! + * \file galileo_e1_pcps_tong_ambiguous_acquisition_gsoc2013_test.cc + * \brief This class implements an acquisition test for + * GalileoE1PcpsTongAmbiguousAcquisition class. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com * + * + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gnss_block_interface.h" +#include "in_memory_configuration.h" +#include "configuration_interface.h" +#include "gnss_synchro.h" +#include "galileo_e1_pcps_tong_ambiguous_acquisition.h" +#include "signal_generator.h" +//#include "signal_generator.cc" +#include "signal_generator_c.h" +//#include "signal_generator_c.cc" +#include "fir_filter.h" +#include "gen_signal_source.h" +#include "gnss_sdr_valve.h" +#include "boost/shared_ptr.hpp" + + +class GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test: public ::testing::Test +{ +protected: + GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test() + { + queue = gr::msg_queue::make(0); + top_block = gr::make_top_block("Acquisition test"); + item_size = sizeof(gr_complex); + stop = false; + message = 0; + } + + ~GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test() + { + } + + void init(); + void config_1(); + void config_2(); + void start_queue(); + void wait_message(); + void process_message(); + void stop_queue(); + + gr::msg_queue::sptr queue; + gr::top_block_sptr top_block; + GalileoE1PcpsTongAmbiguousAcquisition *acquisition; + InMemoryConfiguration* config; + Gnss_Synchro gnss_synchro; + size_t item_size; + concurrent_queue channel_internal_queue; + bool stop; + int message; + boost::thread ch_thread; + + unsigned int integration_time_ms; + unsigned int fs_in; + + double expected_delay_chips; + double expected_doppler_hz; + float max_doppler_error_hz; + float max_delay_error_chips; + + unsigned int num_of_realizations; + unsigned int realization_counter; + unsigned int detection_counter; + unsigned int correct_estimation_counter; + unsigned int acquired_samples; + unsigned int mean_acq_time_us; + + double mse_doppler; + double mse_delay; + + double Pd; + double Pfa_p; + double Pfa_a; +}; + +void GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test::init() +{ + message = 0; + realization_counter = 0; + detection_counter = 0; + correct_estimation_counter = 0; + acquired_samples = 0; + mse_doppler = 0; + mse_delay = 0; + mean_acq_time_us = 0; + Pd = 0; + Pfa_p = 0; + Pfa_a = 0; +} + +void GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test::config_1() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'E'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 4; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 1; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "1"); + + config->set_property("SignalSource.system_0", "E"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", + std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", + std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.noise_flag", "false"); + config->set_property("SignalSource.data_flag", "false"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.tong_init_val", "5"); + config->set_property("Acquisition.tong_max_val", "10"); + config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_Tong_Ambiguous_Acquisition"); + config->set_property("Acquisition.threshold", "0.3"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test::config_2() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'E'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 4; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 100; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "4"); + + config->set_property("SignalSource.system_0", "E"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", + std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", + std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.system_1", "E"); + config->set_property("SignalSource.PRN_1", "15"); + config->set_property("SignalSource.CN0_dB_1", "44"); + config->set_property("SignalSource.doppler_Hz_1", "1000"); + config->set_property("SignalSource.delay_chips_1", "100"); + + config->set_property("SignalSource.system_2", "G"); + config->set_property("SignalSource.PRN_2", "10"); + config->set_property("SignalSource.CN0_dB_2", "44"); + config->set_property("SignalSource.doppler_Hz_2", "2000"); + config->set_property("SignalSource.delay_chips_2", "200"); + + config->set_property("SignalSource.system_3", "G"); + config->set_property("SignalSource.PRN_3", "20"); + config->set_property("SignalSource.CN0_dB_3", "44"); + config->set_property("SignalSource.doppler_Hz_3", "3000"); + config->set_property("SignalSource.delay_chips_3", "300"); + + config->set_property("SignalSource.noise_flag", "true"); + config->set_property("SignalSource.data_flag", "true"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.tong_init_val", "5"); + config->set_property("Acquisition.tong_max_val", "10"); + config->set_property("Acquisition.implementation", "Galileo_E1_PCPS_Tong_Ambiguous_Acquisition"); + config->set_property("Acquisition.threshold", "0.0005"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test::start_queue() +{ + stop = false; + ch_thread = boost::thread(&GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test::wait_message, this); +} + +void GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test::wait_message() +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + while (!stop) + { + acquisition->reset(); + + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + + channel_internal_queue.wait_and_pop(message); + + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + + mean_acq_time_us += (end-begin); + + process_message(); + } +} + +void GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test::process_message() +{ + if (message == 1) + { + detection_counter++; + + // The term -5 is here to correct the additional delay introduced by the FIR filter + double delay_error_chips = abs((double)expected_delay_chips - (double)(gnss_synchro.Acq_delay_samples-5)*1023.0/((double)fs_in*1e-3)); + double doppler_error_hz = abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); + + mse_delay += std::pow(delay_error_chips, 2); + mse_doppler += std::pow(doppler_error_hz, 2); + + if ((delay_error_chips < max_delay_error_chips) && (doppler_error_hz < max_doppler_error_hz)) + { + correct_estimation_counter++; + } + } + + realization_counter++; + + std::cout << "Progress: " << round((float)realization_counter/num_of_realizations*100) << "% \r" << std::flush; + + if (realization_counter == num_of_realizations) + { + mse_delay /= num_of_realizations; + mse_doppler /= num_of_realizations; + + Pd = (double)correct_estimation_counter / (double)num_of_realizations; + Pfa_a = (double)detection_counter / (double)num_of_realizations; + Pfa_p = (double)(detection_counter-correct_estimation_counter) / (double)num_of_realizations; + + mean_acq_time_us /= num_of_realizations; + + stop_queue(); + top_block->stop(); + + std::cout << std::endl; + } +} + +void GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test::stop_queue() +{ + stop = true; +} + +TEST_F(GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test, Instantiate) +{ + config_1(); + acquisition = new GalileoE1PcpsTongAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + delete acquisition; + delete config; +} + +TEST_F(GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test, ConnectAndRun) +{ + int nsamples = floor(fs_in*integration_time_ms*1e-3); + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + config_1(); + acquisition = new GalileoE1PcpsTongAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + boost::shared_ptr source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0)); + boost::shared_ptr valve = gnss_sdr_make_valve(sizeof(gr_complex), nsamples, queue); + top_block->connect(source, 0, valve, 0); + top_block->connect(valve, 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + }) << "Failure running the top_block."<< std::endl; + + std::cout << "Processed " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; + + delete acquisition; + delete config; +} + +TEST_F(GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test, ValidationOfResults) +{ + config_1(); + + acquisition = new GalileoE1PcpsTongAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + // i = 0 --> sallite in acquisition is visible + // i = 1 --> satellite in acquisition is not visible + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; + if (message == 1) + { + EXPECT_EQ(1, correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; + } + } + else if (i == 1) + { + EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; + } + } + + delete acquisition; + delete config; +} + +TEST_F(GalileoE1PcpsTongAmbiguousAcquisitionGSoC2013Test, ValidationOfResultsProbabilities) +{ + config_2(); + + acquisition = new GalileoE1PcpsTongAmbiguousAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + std::cout << "Probability of false alarm (target) = " << 0.0 << std::endl; + + // i = 0 --> sallite in acquisition is visible (prob of detection and prob of detection with wrong estimation) + // i = 1 --> satellite in acquisition is not visible (prob of false detection) + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + std::cout << "Probability of detection = " << Pd << std::endl; + std::cout << "Probability of false alarm (satellite present) = " << Pfa_p << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + else if (i == 1) + { + std::cout << "Probability of false alarm (satellite absent) = " << Pfa_a << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + } + + delete acquisition; + delete config; +} diff --git a/src/tests/gnss_block/gps_l1_ca_pcps_acquisition_gsoc2013_test.cc b/src/tests/gnss_block/gps_l1_ca_pcps_acquisition_gsoc2013_test.cc new file mode 100644 index 000000000..86cc544a2 --- /dev/null +++ b/src/tests/gnss_block/gps_l1_ca_pcps_acquisition_gsoc2013_test.cc @@ -0,0 +1,577 @@ +/*! + * \file gps_l1_ca_pcps_acquisition_gsoc2013_test.cc + * \brief This class implements an acquisition test for + * GpsL1CaPcpsAcquisition class. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gnss_block_interface.h" +#include "in_memory_configuration.h" +#include "configuration_interface.h" +#include "gnss_synchro.h" +#include "gps_l1_ca_pcps_acquisition.h" +#include "signal_generator.h" +#include "signal_generator.cc" +#include "signal_generator_c.h" +#include "signal_generator_c.cc" +#include "fir_filter.h" +#include "gen_signal_source.h" +#include "gnss_sdr_valve.h" +#include "boost/shared_ptr.hpp" +#include "pass_through.h" + + +class GpsL1CaPcpsAcquisitionGSoC2013Test: public ::testing::Test +{ +protected: + GpsL1CaPcpsAcquisitionGSoC2013Test() + { + queue = gr::msg_queue::make(0); + top_block = gr::make_top_block("Acquisition test"); + item_size = sizeof(gr_complex); + stop = false; + message = 0; + } + + ~GpsL1CaPcpsAcquisitionGSoC2013Test() + { + } + + void init(); + void config_1(); + void config_2(); + void start_queue(); + void wait_message(); + void process_message(); + void stop_queue(); + + gr::msg_queue::sptr queue; + gr::top_block_sptr top_block; + GpsL1CaPcpsAcquisition *acquisition; + InMemoryConfiguration* config; + Gnss_Synchro gnss_synchro; + size_t item_size; + concurrent_queue channel_internal_queue; + bool stop; + int message; + boost::thread ch_thread; + + unsigned int integration_time_ms; + unsigned int fs_in; + + double expected_delay_chips; + double expected_doppler_hz; + float max_doppler_error_hz; + float max_delay_error_chips; + + unsigned int num_of_realizations; + unsigned int realization_counter; + unsigned int detection_counter; + unsigned int correct_estimation_counter; + unsigned int acquired_samples; + unsigned int mean_acq_time_us; + + double mse_doppler; + double mse_delay; + + double Pd; + double Pfa_p; + double Pfa_a; +}; + +void GpsL1CaPcpsAcquisitionGSoC2013Test::init() +{ + message = 0; + realization_counter = 0; + detection_counter = 0; + correct_estimation_counter = 0; + acquired_samples = 0; + mse_doppler = 0; + mse_delay = 0; + mean_acq_time_us = 0; + Pd = 0; + Pfa_p = 0; + Pfa_a = 0; +} + +void GpsL1CaPcpsAcquisitionGSoC2013Test::config_1() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'G'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 1; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 1; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "1"); + + config->set_property("SignalSource.system_0", "G"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.noise_flag", "false"); + config->set_property("SignalSource.data_flag", "false"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Acquisition"); + config->set_property("Acquisition.threshold", "0.8"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.bit_transition_flag", "false"); + config->set_property("Acquisition.dump", "false"); +} + +void GpsL1CaPcpsAcquisitionGSoC2013Test::config_2() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'G'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 1; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 100; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "4"); + + config->set_property("SignalSource.system_0", "G"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.system_1", "G"); + config->set_property("SignalSource.PRN_1", "15"); + config->set_property("SignalSource.CN0_dB_1", "44"); + config->set_property("SignalSource.doppler_Hz_1", "1000"); + config->set_property("SignalSource.delay_chips_1", "100"); + + config->set_property("SignalSource.system_2", "E"); + config->set_property("SignalSource.PRN_2", "21"); + config->set_property("SignalSource.CN0_dB_2", "44"); + config->set_property("SignalSource.doppler_Hz_2", "2000"); + config->set_property("SignalSource.delay_chips_2", "200"); + + config->set_property("SignalSource.system_3", "E"); + config->set_property("SignalSource.PRN_3", "22"); + config->set_property("SignalSource.CN0_dB_3", "44"); + config->set_property("SignalSource.doppler_Hz_3", "3000"); + config->set_property("SignalSource.delay_chips_3", "300"); + + config->set_property("SignalSource.noise_flag", "true"); + config->set_property("SignalSource.data_flag", "true"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Acquisition"); + config->set_property("Acquisition.pfa", "1e-1"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.bit_transition_flag", "false"); + config->set_property("Acquisition.dump", "false"); +} + +void GpsL1CaPcpsAcquisitionGSoC2013Test::start_queue() +{ + stop = false; + ch_thread = boost::thread(&GpsL1CaPcpsAcquisitionGSoC2013Test::wait_message, this); +} + +void GpsL1CaPcpsAcquisitionGSoC2013Test::wait_message() +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + while (!stop) + { + acquisition->reset(); + + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + + channel_internal_queue.wait_and_pop(message); + + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + + mean_acq_time_us += (end-begin); + + process_message(); + } +} + +void GpsL1CaPcpsAcquisitionGSoC2013Test::process_message() +{ + if (message == 1) + { + detection_counter++; + + // The term -5 is here to correct the additional delay introduced by the FIR filter + double delay_error_chips = abs((double)expected_delay_chips - (double)(gnss_synchro.Acq_delay_samples-5)*1023.0/((double)fs_in*1e-3)); + double doppler_error_hz = abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); + + mse_delay += std::pow(delay_error_chips, 2); + mse_doppler += std::pow(doppler_error_hz, 2); + + if ((delay_error_chips < max_delay_error_chips) && (doppler_error_hz < max_doppler_error_hz)) + { + correct_estimation_counter++; + } + } + + realization_counter++; + + std::cout << "Progress: " << round((float)realization_counter/num_of_realizations*100) << "% \r" << std::flush; + + if (realization_counter == num_of_realizations) + { + mse_delay /= num_of_realizations; + mse_doppler /= num_of_realizations; + + Pd = (double)correct_estimation_counter / (double)num_of_realizations; + Pfa_a = (double)detection_counter / (double)num_of_realizations; + Pfa_p = (double)(detection_counter-correct_estimation_counter) / (double)num_of_realizations; + + mean_acq_time_us /= num_of_realizations; + + stop_queue(); + top_block->stop(); + + std::cout << std::endl; + } +} + +void GpsL1CaPcpsAcquisitionGSoC2013Test::stop_queue() +{ + stop = true; +} + +TEST_F(GpsL1CaPcpsAcquisitionGSoC2013Test, Instantiate) +{ + config_1(); + acquisition = new GpsL1CaPcpsAcquisition(config, "Acquisition", 1, 1, queue); + delete acquisition; + delete config; +} + +TEST_F(GpsL1CaPcpsAcquisitionGSoC2013Test, ConnectAndRun) +{ + int nsamples = floor(fs_in*integration_time_ms*1e-3); + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + config_1(); + acquisition = new GpsL1CaPcpsAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + boost::shared_ptr source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0)); + boost::shared_ptr valve = gnss_sdr_make_valve(sizeof(gr_complex), nsamples, queue); + top_block->connect(source, 0, valve, 0); + top_block->connect(valve, 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + }) << "Failure running the top_block."<< std::endl; + + std::cout << "Processed " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; + + delete acquisition; + delete config; +} + +TEST_F(GpsL1CaPcpsAcquisitionGSoC2013Test, ValidationOfResults) +{ + config_1(); + + acquisition = new GpsL1CaPcpsAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + // i = 0 --> sallite in acquisition is visible + // i = 1 --> satellite in acquisition is not visible + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; + if (message == 1) + { + EXPECT_EQ(1, correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; + } + + } + else if (i == 1) + { + EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; + } + } + + delete acquisition; + delete config; +} + +TEST_F(GpsL1CaPcpsAcquisitionGSoC2013Test, ValidationOfResultsProbabilities) +{ + config_2(); + + acquisition = new GpsL1CaPcpsAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + std::cout << "Probability of false alarm (target) = " << 0.1 << std::endl; + + // i = 0 --> sallite in acquisition is visible (prob of detection and prob of detection with wrong estimation) + // i = 1 --> satellite in acquisition is not visible (prob of false detection) + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + std::cout << "Probability of detection = " << Pd << std::endl; + std::cout << "Probability of false alarm (satellite present) = " << Pfa_p << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + else if (i == 1) + { + std::cout << "Probability of false alarm (satellite absent) = " << Pfa_a << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + } + + delete acquisition; + delete config; +} diff --git a/src/tests/gnss_block/gps_l1_ca_pcps_acquisition_test.cc b/src/tests/gnss_block/gps_l1_ca_pcps_acquisition_test.cc index 03b86d85c..6ef618af2 100644 --- a/src/tests/gnss_block/gps_l1_ca_pcps_acquisition_test.cc +++ b/src/tests/gnss_block/gps_l1_ca_pcps_acquisition_test.cc @@ -98,7 +98,7 @@ void GpsL1CaPcpsAcquisitionTest::init() config->set_property("GNSS-SDR.internal_fs_hz", "4000000"); config->set_property("Acquisition.item_type", "gr_complex"); config->set_property("Acquisition.if", "0"); - config->set_property("Acquisition.sampled_ms", "1"); + config->set_property("Acquisition.coherent_integration_time_ms", "1"); config->set_property("Acquisition.dump", "false"); config->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Acquisition"); config->set_property("Acquisition.threshold", "0.005"); @@ -219,6 +219,7 @@ TEST_F(GpsL1CaPcpsAcquisitionTest, ValidationOfResults) }) << "Failure connecting the blocks of acquisition test."<< std::endl; start_queue(); + acquisition->init(); acquisition->reset(); diff --git a/src/tests/gnss_block/gps_l1_ca_pcps_multithread_acquisition_gsoc2013_test.cc b/src/tests/gnss_block/gps_l1_ca_pcps_multithread_acquisition_gsoc2013_test.cc new file mode 100644 index 000000000..7c0c3cde8 --- /dev/null +++ b/src/tests/gnss_block/gps_l1_ca_pcps_multithread_acquisition_gsoc2013_test.cc @@ -0,0 +1,576 @@ +/*! + * \file gps_l1_ca_pcps_acquisition_gsoc2013_test.cc + * \brief This class implements an acquisition test for + * GpsL1CaPcpsMultithreadAcquisition class. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gnss_block_interface.h" +#include "in_memory_configuration.h" +#include "configuration_interface.h" +#include "gnss_synchro.h" +#include "gps_l1_ca_pcps_multithread_acquisition.h" +#include "signal_generator.h" +//#include "signal_generator.cc" +#include "signal_generator_c.h" +//#include "signal_generator_c.cc" +#include "fir_filter.h" +#include "gen_signal_source.h" +#include "gnss_sdr_valve.h" +#include "boost/shared_ptr.hpp" + + +class GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test: public ::testing::Test +{ +protected: + GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test() + { + queue = gr::msg_queue::make(0); + top_block = gr::make_top_block("Acquisition test"); + item_size = sizeof(gr_complex); + stop = false; + message = 0; + } + + ~GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test() + { + } + + void init(); + void config_1(); + void config_2(); + void start_queue(); + void wait_message(); + void process_message(); + void stop_queue(); + + gr::msg_queue::sptr queue; + gr::top_block_sptr top_block; + GpsL1CaPcpsMultithreadAcquisition *acquisition; + InMemoryConfiguration* config; + Gnss_Synchro gnss_synchro; + size_t item_size; + concurrent_queue channel_internal_queue; + bool stop; + int message; + boost::thread ch_thread; + + unsigned int integration_time_ms; + unsigned int fs_in; + + double expected_delay_chips; + double expected_doppler_hz; + float max_doppler_error_hz; + float max_delay_error_chips; + + unsigned int num_of_realizations; + unsigned int realization_counter; + unsigned int detection_counter; + unsigned int correct_estimation_counter; + unsigned int acquired_samples; + unsigned int mean_acq_time_us; + + double mse_doppler; + double mse_delay; + + double Pd; + double Pfa_p; + double Pfa_a; +}; + +void GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test::init() +{ + message = 0; + realization_counter = 0; + detection_counter = 0; + correct_estimation_counter = 0; + acquired_samples = 0; + mse_doppler = 0; + mse_delay = 0; + mean_acq_time_us = 0; + Pd = 0; + Pfa_p = 0; + Pfa_a = 0; +} + +void GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test::config_1() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'G'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 1; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 1; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "1"); + + config->set_property("SignalSource.system_0", "G"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.noise_flag", "false"); + config->set_property("SignalSource.data_flag", "false"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Multithread_Acquisition"); + config->set_property("Acquisition.threshold", "0.8"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.bit_transition_flag", "false"); + config->set_property("Acquisition.dump", "false"); +} + +void GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test::config_2() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'G'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 4; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 100; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "4"); + + config->set_property("SignalSource.system_0", "G"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.system_1", "G"); + config->set_property("SignalSource.PRN_1", "15"); + config->set_property("SignalSource.CN0_dB_1", "44"); + config->set_property("SignalSource.doppler_Hz_1", "1000"); + config->set_property("SignalSource.delay_chips_1", "100"); + + config->set_property("SignalSource.system_2", "E"); + config->set_property("SignalSource.PRN_2", "21"); + config->set_property("SignalSource.CN0_dB_2", "44"); + config->set_property("SignalSource.doppler_Hz_2", "2000"); + config->set_property("SignalSource.delay_chips_2", "200"); + + config->set_property("SignalSource.system_3", "E"); + config->set_property("SignalSource.PRN_3", "22"); + config->set_property("SignalSource.CN0_dB_3", "44"); + config->set_property("SignalSource.doppler_Hz_3", "3000"); + config->set_property("SignalSource.delay_chips_3", "300"); + + config->set_property("SignalSource.noise_flag", "true"); + config->set_property("SignalSource.data_flag", "true"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.max_dwells", "1"); + config->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Multithread_Acquisition"); + config->set_property("Acquisition.pfa", "1e-1"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.bit_transition_flag", "true"); + config->set_property("Acquisition.dump", "false"); +} + +void GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test::start_queue() +{ + stop = false; + ch_thread = boost::thread(&GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test::wait_message, this); +} + +void GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test::wait_message() +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + while (!stop) + { + acquisition->reset(); + + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + + channel_internal_queue.wait_and_pop(message); + + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + + mean_acq_time_us += (end-begin); + + process_message(); + } +} + +void GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test::process_message() +{ + if (message == 1) + { + detection_counter++; + + // The term -5 is here to correct the additional delay introduced by the FIR filter + double delay_error_chips = abs((double)expected_delay_chips - (double)(gnss_synchro.Acq_delay_samples-5)*1023.0/((double)fs_in*1e-3)); + double doppler_error_hz = abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); + + mse_delay += std::pow(delay_error_chips, 2); + mse_doppler += std::pow(doppler_error_hz, 2); + + if ((delay_error_chips < max_delay_error_chips) && (doppler_error_hz < max_doppler_error_hz)) + { + correct_estimation_counter++; + } + } + + realization_counter++; + + std::cout << "Progress: " << round((float)realization_counter/num_of_realizations*100) << "% \r" << std::flush; + + if (realization_counter == num_of_realizations) + { + mse_delay /= num_of_realizations; + mse_doppler /= num_of_realizations; + + Pd = (double)correct_estimation_counter / (double)num_of_realizations; + Pfa_a = (double)detection_counter / (double)num_of_realizations; + Pfa_p = (double)(detection_counter-correct_estimation_counter) / (double)num_of_realizations; + + mean_acq_time_us /= num_of_realizations; + + stop_queue(); + top_block->stop(); + + std::cout << std::endl; + } +} + +void GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test::stop_queue() +{ + stop = true; +} + +TEST_F(GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test, Instantiate) +{ + config_1(); + acquisition = new GpsL1CaPcpsMultithreadAcquisition(config, "Acquisition", 1, 1, queue); + delete acquisition; + delete config; +} + +TEST_F(GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test, ConnectAndRun) +{ + int nsamples = floor(fs_in*integration_time_ms*1e-3); + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + config_1(); + acquisition = new GpsL1CaPcpsMultithreadAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + boost::shared_ptr source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0)); + boost::shared_ptr valve = gnss_sdr_make_valve(sizeof(gr_complex), nsamples, queue); + top_block->connect(source, 0, valve, 0); + top_block->connect(valve, 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + }) << "Failure running the top_block."<< std::endl; + + std::cout << "Processed " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; + + delete acquisition; + delete config; +} + +TEST_F(GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test, ValidationOfResults) +{ + config_1(); + + acquisition = new GpsL1CaPcpsMultithreadAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + // i = 0 --> sallite in acquisition is visible + // i = 1 --> satellite in acquisition is not visible + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; + if (message == 1) + { + EXPECT_EQ(1, correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; + } + + } + else if (i == 1) + { + EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; + } + } + + delete acquisition; + delete config; +} + +TEST_F(GpsL1CaPcpsMultithreadAcquisitionGSoC2013Test, ValidationOfResultsProbabilities) +{ + config_2(); + + acquisition = new GpsL1CaPcpsMultithreadAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + std::cout << "Probability of false alarm (target) = " << 0.1 << std::endl; + + // i = 0 --> sallite in acquisition is visible (prob of detection and prob of detection with wrong estimation) + // i = 1 --> satellite in acquisition is not visible (prob of false detection) + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + std::cout << "Probability of detection = " << Pd << std::endl; + std::cout << "Probability of false alarm (satellite present) = " << Pfa_p << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + else if (i == 1) + { + std::cout << "Probability of false alarm (satellite absent) = " << Pfa_a << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + } + + delete acquisition; + delete config; +} diff --git a/src/tests/gnss_block/gps_l1_ca_pcps_tong_acquisition_gsoc2013_test.cc b/src/tests/gnss_block/gps_l1_ca_pcps_tong_acquisition_gsoc2013_test.cc new file mode 100644 index 000000000..5995d1648 --- /dev/null +++ b/src/tests/gnss_block/gps_l1_ca_pcps_tong_acquisition_gsoc2013_test.cc @@ -0,0 +1,575 @@ +/*! + * \file gps_l1_ca_pcps_tong_acquisition_gsoc2013_test.cc + * \brief This class implements an acquisition test for + * GpsL1CaPcpsTongAcquisition class. + * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com + * + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gnss_block_interface.h" +#include "in_memory_configuration.h" +#include "configuration_interface.h" +#include "gnss_synchro.h" +#include "gps_l1_ca_pcps_tong_acquisition.h" +#include "signal_generator.h" +//#include "signal_generator.cc" +#include "signal_generator_c.h" +//#include "signal_generator_c.cc" +#include "fir_filter.h" +#include "gen_signal_source.h" +#include "gnss_sdr_valve.h" +#include "boost/shared_ptr.hpp" + + +class GpsL1CaPcpsTongAcquisitionGSoC2013Test: public ::testing::Test +{ +protected: + GpsL1CaPcpsTongAcquisitionGSoC2013Test() + { + queue = gr::msg_queue::make(0); + top_block = gr::make_top_block("Acquisition test"); + item_size = sizeof(gr_complex); + stop = false; + message = 0; + } + + ~GpsL1CaPcpsTongAcquisitionGSoC2013Test() + { + } + + void init(); + void config_1(); + void config_2(); + void start_queue(); + void wait_message(); + void process_message(); + void stop_queue(); + + gr::msg_queue::sptr queue; + gr::top_block_sptr top_block; + GpsL1CaPcpsTongAcquisition *acquisition; + InMemoryConfiguration* config; + Gnss_Synchro gnss_synchro; + size_t item_size; + concurrent_queue channel_internal_queue; + bool stop; + int message; + boost::thread ch_thread; + + unsigned int integration_time_ms; + unsigned int fs_in; + + double expected_delay_chips; + double expected_doppler_hz; + float max_doppler_error_hz; + float max_delay_error_chips; + + unsigned int num_of_realizations; + unsigned int realization_counter; + unsigned int detection_counter; + unsigned int correct_estimation_counter; + unsigned int acquired_samples; + unsigned int mean_acq_time_us; + + double mse_doppler; + double mse_delay; + + double Pd; + double Pfa_p; + double Pfa_a; +}; + +void GpsL1CaPcpsTongAcquisitionGSoC2013Test::init() +{ + message = 0; + realization_counter = 0; + detection_counter = 0; + correct_estimation_counter = 0; + acquired_samples = 0; + mse_doppler = 0; + mse_delay = 0; + mean_acq_time_us = 0; + Pd = 0; + Pfa_p = 0; + Pfa_a = 0; +} + +void GpsL1CaPcpsTongAcquisitionGSoC2013Test::config_1() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'G'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 1; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 1; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "1"); + + config->set_property("SignalSource.system_0", "G"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.noise_flag", "false"); + config->set_property("SignalSource.data_flag", "false"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Tong_Acquisition"); + config->set_property("Acquisition.threshold", "0.8"); + config->set_property("Acquisition.tong_init_val", "5"); + config->set_property("Acquisition.tong_max_val", "10"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GpsL1CaPcpsTongAcquisitionGSoC2013Test::config_2() +{ + gnss_synchro.Channel_ID = 0; + gnss_synchro.System = 'G'; + std::string signal = "1C"; + signal.copy(gnss_synchro.Signal,2,0); + + integration_time_ms = 1; + fs_in = 4e6; + + expected_delay_chips = 600; + expected_doppler_hz = 750; + max_doppler_error_hz = 2/(3*integration_time_ms*1e-3); + max_delay_error_chips = 0.50; + + num_of_realizations = 100; + + config = new InMemoryConfiguration(); + + config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.fs_hz", std::to_string(fs_in)); + + config->set_property("SignalSource.item_type", "gr_complex"); + + config->set_property("SignalSource.num_satellites", "4"); + + config->set_property("SignalSource.system_0", "G"); + config->set_property("SignalSource.PRN_0", "10"); + config->set_property("SignalSource.CN0_dB_0", "44"); + config->set_property("SignalSource.doppler_Hz_0", std::to_string(expected_doppler_hz)); + config->set_property("SignalSource.delay_chips_0", std::to_string(expected_delay_chips)); + + config->set_property("SignalSource.system_1", "G"); + config->set_property("SignalSource.PRN_1", "15"); + config->set_property("SignalSource.CN0_dB_1", "44"); + config->set_property("SignalSource.doppler_Hz_1", "1000"); + config->set_property("SignalSource.delay_chips_1", "100"); + + config->set_property("SignalSource.system_2", "E"); + config->set_property("SignalSource.PRN_2", "10"); + config->set_property("SignalSource.CN0_dB_2", "44"); + config->set_property("SignalSource.doppler_Hz_2", "2000"); + config->set_property("SignalSource.delay_chips_2", "200"); + + config->set_property("SignalSource.system_3", "E"); + config->set_property("SignalSource.PRN_3", "20"); + config->set_property("SignalSource.CN0_dB_3", "44"); + config->set_property("SignalSource.doppler_Hz_3", "3000"); + config->set_property("SignalSource.delay_chips_3", "300"); + + config->set_property("SignalSource.noise_flag", "true"); + config->set_property("SignalSource.data_flag", "true"); + config->set_property("SignalSource.BW_BB", "0.97"); + + config->set_property("InputFilter.implementation", "Fir_Filter"); + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "11"); + config->set_property("InputFilter.number_of_bands", "2"); + config->set_property("InputFilter.band1_begin", "0.0"); + config->set_property("InputFilter.band1_end", "0.97"); + config->set_property("InputFilter.band2_begin", "0.98"); + config->set_property("InputFilter.band2_end", "1.0"); + config->set_property("InputFilter.ampl1_begin", "1.0"); + config->set_property("InputFilter.ampl1_end", "1.0"); + config->set_property("InputFilter.ampl2_begin", "0.0"); + config->set_property("InputFilter.ampl2_end", "0.0"); + config->set_property("InputFilter.band1_error", "1.0"); + config->set_property("InputFilter.band2_error", "1.0"); + config->set_property("InputFilter.filter_type", "bandpass"); + config->set_property("InputFilter.grid_density", "16"); + + config->set_property("Acquisition.item_type", "gr_complex"); + config->set_property("Acquisition.if", "0"); + config->set_property("Acquisition.coherent_integration_time_ms", + std::to_string(integration_time_ms)); + config->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Tong_Acquisition"); + config->set_property("Acquisition.threshold", "0.002"); + config->set_property("Acquisition.tong_init_val", "5"); + config->set_property("Acquisition.tong_max_val", "10"); + config->set_property("Acquisition.doppler_max", "10000"); + config->set_property("Acquisition.doppler_step", "250"); + config->set_property("Acquisition.dump", "false"); +} + +void GpsL1CaPcpsTongAcquisitionGSoC2013Test::start_queue() +{ + stop = false; + ch_thread = boost::thread(&GpsL1CaPcpsTongAcquisitionGSoC2013Test::wait_message, this); +} + +void GpsL1CaPcpsTongAcquisitionGSoC2013Test::wait_message() +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + while (!stop) + { + acquisition->reset(); + + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + + channel_internal_queue.wait_and_pop(message); + + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + + mean_acq_time_us += (end-begin); + + process_message(); + } +} + +void GpsL1CaPcpsTongAcquisitionGSoC2013Test::process_message() +{ + if (message == 1) + { + detection_counter++; + + // The term -5 is here to correct the additional delay introduced by the FIR filter + double delay_error_chips = abs((double)expected_delay_chips - (double)(gnss_synchro.Acq_delay_samples-5)*1023.0/((double)fs_in*1e-3)); + double doppler_error_hz = abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); + + mse_delay += std::pow(delay_error_chips, 2); + mse_doppler += std::pow(doppler_error_hz, 2); + + if ((delay_error_chips < max_delay_error_chips) && (doppler_error_hz < max_doppler_error_hz)) + { + correct_estimation_counter++; + } + } + + realization_counter++; + + std::cout << "Progress: " << round((float)realization_counter/num_of_realizations*100) << "% \r" << std::flush; + + if (realization_counter == num_of_realizations) + { + mse_delay /= num_of_realizations; + mse_doppler /= num_of_realizations; + + Pd = (double)correct_estimation_counter / (double)num_of_realizations; + Pfa_a = (double)detection_counter / (double)num_of_realizations; + Pfa_p = (double)(detection_counter-correct_estimation_counter) / (double)num_of_realizations; + + mean_acq_time_us /= num_of_realizations; + + stop_queue(); + top_block->stop(); + + std::cout << std::endl; + } +} + +void GpsL1CaPcpsTongAcquisitionGSoC2013Test::stop_queue() +{ + stop = true; +} + +TEST_F(GpsL1CaPcpsTongAcquisitionGSoC2013Test, Instantiate) +{ + config_1(); + acquisition = new GpsL1CaPcpsTongAcquisition(config, "Acquisition", 1, 1, queue); + delete acquisition; + delete config; +} + +TEST_F(GpsL1CaPcpsTongAcquisitionGSoC2013Test, ConnectAndRun) +{ + int nsamples = floor(fs_in*integration_time_ms*1e-3); + struct timeval tv; + long long int begin = 0; + long long int end = 0; + + config_1(); + acquisition = new GpsL1CaPcpsTongAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + boost::shared_ptr source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0)); + boost::shared_ptr valve = gnss_sdr_make_valve(sizeof(gr_complex), nsamples, queue); + top_block->connect(source, 0, valve, 0); + top_block->connect(valve, 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1e6 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1e6 + tv.tv_usec; + }) << "Failure running the top_block."<< std::endl; + + std::cout << "Processed " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; + delete acquisition; + delete config; +} + +TEST_F(GpsL1CaPcpsTongAcquisitionGSoC2013Test, ValidationOfResults) +{ + config_1(); + + acquisition = new GpsL1CaPcpsTongAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + // i = 0 --> sallite in acquisition is visible + // i = 1 --> satellite in acquisition is not visible + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; + if (message == 1) + { + EXPECT_EQ(1, correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; + } + + } + else if (i == 1) + { + EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; + } + } + + delete acquisition; + delete config; +} + +TEST_F(GpsL1CaPcpsTongAcquisitionGSoC2013Test, ValidationOfResultsProbabilities) +{ + config_2(); + + acquisition = new GpsL1CaPcpsTongAcquisition(config, "Acquisition", 1, 1, queue); + + ASSERT_NO_THROW( { + acquisition->set_channel(1); + }) << "Failure setting channel."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_gnss_synchro(&gnss_synchro); + }) << "Failure setting gnss_synchro."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_channel_queue(&channel_internal_queue); + }) << "Failure setting channel_internal_queue."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_max(config->property("Acquisition.doppler_max", 10000)); + }) << "Failure setting doppler_max."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_doppler_step(config->property("Acquisition.doppler_step", 500)); + }) << "Failure setting doppler_step."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->set_threshold(config->property("Acquisition.threshold", 0.0)); + }) << "Failure setting threshold."<< std::endl; + + ASSERT_NO_THROW( { + acquisition->connect(top_block); + }) << "Failure connecting acquisition to the top_block."<< std::endl; + + acquisition->init(); + + ASSERT_NO_THROW( { + boost::shared_ptr signal_source; + SignalGenerator* signal_generator = new SignalGenerator(config, "SignalSource", 0, 1, queue); + FirFilter* filter = new FirFilter(config, "InputFilter", 1, 1, queue); + signal_source.reset(new GenSignalSource(config, signal_generator, filter, "SignalSource", queue)); + signal_source->connect(top_block); + top_block->connect(signal_source->get_right_block(), 0, acquisition->get_left_block(), 0); + }) << "Failure connecting the blocks of acquisition test." << std::endl; + + std::cout << "Probability of false alarm (target) = " << 0.0 << std::endl; + + // i = 0 --> sallite in acquisition is visible (prob of detection and prob of detection with wrong estimation) + // i = 1 --> satellite in acquisition is not visible (prob of false detection) + for (unsigned int i = 0; i < 2; i++) + { + init(); + + if (i == 0) + { + gnss_synchro.PRN = 10; // This satellite is visible + } + else if (i == 1) + { + gnss_synchro.PRN = 20; // This satellite is not visible + } + + acquisition->set_local_code(); + + start_queue(); + + EXPECT_NO_THROW( { + top_block->run(); // Start threads and wait + }) << "Failure running he top_block."<< std::endl; + + if (i == 0) + { + std::cout << "Probability of detection = " << Pd << std::endl; + std::cout << "Probability of false alarm (satellite present) = " << Pfa_p << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + else if (i == 1) + { + std::cout << "Probability of false alarm (satellite absent) = " << Pfa_a << std::endl; +// std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } + } + + delete acquisition; + delete config; +} diff --git a/src/tests/test_main.cc b/src/tests/test_main.cc index 83da16e1c..d702592ab 100644 --- a/src/tests/test_main.cc +++ b/src/tests/test_main.cc @@ -69,10 +69,20 @@ #include "gnss_block/file_output_filter_test.cc" #include "gnss_block/file_signal_source_test.cc" #include "gnss_block/fir_filter_test.cc" -#include "gnss_block/gps_l1_ca_pcps_acquisition_test.cc" -#include "gnss_block/galileo_e1_pcps_ambiguous_acquisition_test.cc" -//#include "gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc_test.cc"// + +//#include "gnss_block/gps_l1_ca_pcps_acquisition_test.cc" +#include "gnss_block/gps_l1_ca_pcps_acquisition_gsoc2013_test.cc" +#include "gnss_block/gps_l1_ca_pcps_multithread_acquisition_gsoc2013_test.cc" +#include "gnss_block/gps_l1_ca_pcps_tong_acquisition_gsoc2013_test.cc" +//#include "gnss_block/galileo_e1_pcps_ambiguous_acquisition_test.cc" +//#include "gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc_test.cc" +#include "gnss_block/galileo_e1_pcps_ambiguous_acquisition_gsoc2013_test.cc" +#include "gnss_block/galileo_e1_pcps_8ms_ambiguous_acquisition_gsoc2013_test.cc" +#include "gnss_block/galileo_e1_pcps_tong_ambiguous_acquisition_gsoc2013_test.cc" +#include "gnss_block/galileo_e1_pcps_cccwsr_ambiguous_acquisition_gsoc2013_test.cc" + #include "gnss_block/galileo_e1_dll_pll_veml_tracking_test.cc" + #include "gnss_block/gnss_block_factory_test.cc" #include "gnuradio_block/gnss_sdr_valve_test.cc" #include "gnuradio_block/direct_resampler_conditioner_cc_test.cc"