From 73a7f9b10966fc8ac5369cff5f3ebc3bf611dac6 Mon Sep 17 00:00:00 2001 From: dominformant <26122827+dominformant@users.noreply.github.com> Date: Thu, 9 Sep 2021 15:16:09 +0200 Subject: [PATCH] Use code generation from `GNSSSignals.jl` (#29) * Use `GNSSSignals.jl` for code calculation * Increase minimum Julia version to 1.6 Co-authored-by: Soeren Schoenbrod --- .github/workflows/ci.yml | 2 +- Project.toml | 6 +++--- src/code_replica.jl | 31 +++++++++++++------------------ test/code_replica.jl | 12 ++++++------ test/tracking_loop.jl | 8 ++++---- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9435267..c0c5763 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: version: - - '1.4' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'. + - '1.6' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'. - '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia. - 'nightly' os: diff --git a/Project.toml b/Project.toml index a0b97e4..8a49674 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Tracking" uuid = "10b2438b-ffd4-5096-aa58-44041d5c8f3b" authors = ["Soeren Zorn "] -version = "0.14.6" +version = "0.14.7" [deps] DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" @@ -15,13 +15,13 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] DocStringExtensions = "0.6, 0.7, 0.8" -GNSSSignals = "0.15" +GNSSSignals = "0.15.3" LoopVectorization = "0.8, 0.9, 0.10, 0.11, 0.12" StaticArrays = "0.9, 0.10, 0.11, 0.12, 1.0" StructArrays = "0.4" TrackingLoopFilters = "0.1" Unitful = "0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 1.0" -julia = "1.4" +julia = "1.6" [extras] Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/src/code_replica.jl b/src/code_replica.jl index c5cacea..4df2e0a 100644 --- a/src/code_replica.jl +++ b/src/code_replica.jl @@ -1,13 +1,13 @@ """ $(SIGNATURES) -Generate a code replica for a signal from satellite system `S`. The +Generate a code replica for a signal from satellite system `S`. The replica contains `num_samples` prompt samples as well as an additional number of early and late samples specified by `correlator_sample_shifts`. The codefrequency is specified by `code_frequency`, while the sampling -rate is given by `sampling_frequency`. The phase of the first prompt +rate is given by `sampling_frequency`. The phase of the first prompt sample is given by `start_code_phase`. The generated signal is returned -in the array `code_replica` with the first generated sample written to +in the array `code_replica` with the first generated sample written to index start_sample. """ function gen_code_replica!( @@ -23,20 +23,15 @@ function gen_code_replica!( ) most_early_sample_shift = correlator_sample_shifts[end] most_late_sample_shift = correlator_sample_shifts[1] - num_early_late_samples = most_early_sample_shift - most_late_sample_shift - fixed_point = sizeof(Int) * 8 - 1 - min_bits_for_code_length(system) - total_code_length = get_code_length(system) * get_secondary_code_length(system) - fixed_point_total_code_length = total_code_length * 1 << fixed_point - modded_start_code_phase = mod(start_code_phase, total_code_length) - fixed_point_start_code_phase = floor(Int, modded_start_code_phase * 1 << fixed_point) - delta = floor(Int, code_frequency * 1 << fixed_point / sampling_frequency) - fixed_point_code_phase = fixed_point_start_code_phase + (most_late_sample_shift - 1) * delta - @inbounds for i = start_sample:num_samples + num_early_late_samples + start_sample - 1 - fixed_point_code_phase += delta - fixed_point_code_phase -= (fixed_point_code_phase >= fixed_point_total_code_length) * fixed_point_total_code_length - code_index = fixed_point_code_phase >> fixed_point - code_replica[i] = get_code_unsafe(system, code_index, prn) - end + total_samples = num_samples + most_early_sample_shift - most_late_sample_shift + gen_code!( + view(code_replica, start_sample:start_sample+total_samples-1), + system, + prn, + sampling_frequency, + code_frequency, + start_code_phase + most_late_sample_shift * code_frequency/sampling_frequency + ) code_replica end @@ -56,7 +51,7 @@ function update_code_phase( secondary_code_or_bit_length = get_data_frequency(system) == 0Hz ? get_secondary_code_length(system) : Int(get_code_frequency(system) / (get_data_frequency(system) * get_code_length(system))) - + code_length = get_code_length(system) * (secondary_code_or_bit_found ? secondary_code_or_bit_length : 1) mod(code_frequency * num_samples / sampling_frequency + start_code_phase, code_length) diff --git a/test/code_replica.jl b/test/code_replica.jl index ad28280..eadbca7 100644 --- a/test/code_replica.jl +++ b/test/code_replica.jl @@ -5,8 +5,8 @@ Tracking.gen_code_replica!( code, gpsl1, - 1023e3, - 2.5e6, + 1023e3Hz, + 2.5e6Hz, 2.0, 11, 2480, @@ -22,8 +22,8 @@ Tracking.gen_code_replica!( code, gpsl1, - 1023e3, - 2.5e6, + 1023e3Hz, + 2.5e6Hz, 2.0, 11, 6480, @@ -40,8 +40,8 @@ Tracking.gen_code_replica!( code, gpsl1, - 1023e3 * 3, - 7.5e6, + 1023e3Hz * 3, + 7.5e6Hz, 2.0, 11, 2480, diff --git a/test/tracking_loop.jl b/test/tracking_loop.jl index bb35298..5ebb7b9 100644 --- a/test/tracking_loop.jl +++ b/test/tracking_loop.jl @@ -150,8 +150,8 @@ end gpsl1 = GPSL1() carrier_doppler = 200Hz start_code_phase = 100 - code_frequency = carrier_doppler / 1540 + 1023kHz - sampling_frequency = 4MHz + code_frequency = carrier_doppler / 1540 + 1023e3Hz + sampling_frequency = 4e6Hz prn = 1 range = 0:3999 start_carrier_phase = π / 2 @@ -237,8 +237,8 @@ end gpsl1 = GPSL1() carrier_doppler = 200Hz start_code_phase = 100 - code_frequency = carrier_doppler / 1540 + 1023kHz - sampling_frequency = 4MHz + code_frequency = carrier_doppler / 1540 + 1023e3Hz + sampling_frequency = 4e6Hz prn = 1 range = 0:3999 start_carrier_phase = π / 2