Skip to content

Commit

Permalink
Restructure: Allow to track multiple satellites (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsoerenm committed May 19, 2023
1 parent d8b132e commit 2c5daa0
Show file tree
Hide file tree
Showing 50 changed files with 3,014 additions and 2,608 deletions.
8 changes: 8 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Configuration file for JuliaFormatter.jl
# For more information, see: https://domluna.github.io/JuliaFormatter.jl/stable/config/

margin = 92
remove_extra_newlines = true
separate_kwargs_with_semicolon = true
format_docstrings = true
format_markdown = true
13 changes: 7 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
name = "Tracking"
uuid = "10b2438b-ffd4-5096-aa58-44041d5c8f3b"
authors = ["Soeren Schoenbrod <soeren.schoenbrod@nav.rwth-aachen.de>",
"Michael Niestroj <michael.niestroj@nav.rwth-aachen.de>"]
authors = ["Soeren Schoenbrod <soeren.schoenbrod@nav.rwth-aachen.de>", "Michael Niestroj <michael.niestroj@nav.rwth-aachen.de>"]
version = "0.15.2"

[deps]
Acquisition = "d4bbf60b-102b-5ffb-8f97-a7ea5817e69f"
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
GNSSSignals = "52c80523-2a4e-5c38-8979-05588f836870"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
TrackingLoopFilters = "0814aff9-93cb-554c-9fff-9bf1cfdb5efa"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
Acquisition = "0.1.0"
CUDA = "3.5"
Acquisition = "0.1.1"
CUDA = "4.0"
DocStringExtensions = "0.6, 0.7, 0.8, 0.9"
GNSSSignals = "0.16"
GNSSSignals = "0.17"
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, 0.6.5"
TrackingLoopFilters = "0.1"
Unitful = "0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 1.0"
julia = "1.6"
julia = "1.6"
106 changes: 70 additions & 36 deletions src/Tracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,46 @@ module Tracking
using Unitful: upreferred, Hz, dBHz, ms
import Base.zero, Base.length, Base.resize!, LinearAlgebra.dot

export get_early, get_prompt, get_late
export get_early_index,get_prompt_index, get_late_index
export get_correlator
export get_accumulator, get_accumulators
export get_num_accumulators
export get_carrier_doppler, get_carrier_phase
export get_code_doppler, get_code_phase
export get_correlator_sample_shifts
export get_early_late_sample_spacing
export get_early_late_index_shift
export get_secondary_code_or_bit_found
export get_correlator_carrier_phase, get_correlator_carrier_frequency
export get_state
export get_system
export get_cn0
export track
export get_bits
export get_num_bits
export get_filtered_prompt
export get_post_corr_filter

export TrackingState
export NumAnts
export NumAccumulators
export MomentsCN0Estimator
export AbstractCN0Estimator
export EarlyPromptLateCorrelator
#export VeryEarlyPromptLateCorrelator
export SecondaryCodeOrBitDetector
export GainControlledSignal
export AbstractPostCorrFilter
export get_early, get_prompt, get_late,
get_prn,
get_code_phase,
get_code_doppler,
get_carrier_phase,
get_carrier_doppler,
get_integrated_samples,
get_correlator,
get_last_fully_integrated_correlator,
get_last_fully_integrated_filtered_prompt,
get_sample_of_last_fully_integrated_correlator,
get_secondary_code_or_bit_detector,
get_prompts_buffer,
get_bit_buffer,
get_bits,
get_accumulators,
get_early_late_sample_spacing,
track,
NumAnts,
NumAccumulators,
MomentsCN0Estimator,
AbstractCN0Estimator,
EarlyPromptLateCorrelator,
VeryEarlyPromptLateCorrelator,
SecondaryCodeOrBitDetector,
GainControlledSignal,
AbstractPostCorrFilter,
SatState,
SystemSatsState,
CPUDownconvertAndCorrelator,
GPUDownconvertAndCorrelator,
ConventionalPLLAndDLL,
ConventionalPLLsAndDLLs,
DefaultPostCorrFilter,
TrackState,
add_sats!,
remove_sats!,
get_sat_states,
get_sat_state,
get_system

struct NumAnts{x}
end
Expand All @@ -54,20 +63,45 @@ module Tracking

NumAccumulators(x) = NumAccumulators{x}()

include("post_corr_filter.jl")
TupleLike{T <: Tuple} = Union{T, NamedTuple{<:Any, T}}

struct DopplersAndFilteredPrompt
carrier_doppler::typeof(1.0Hz)
code_doppler::typeof(1.0Hz)
filtered_prompt::ComplexF64
end

"""
$(SIGNATURES)
Get the number of samples in the signal.
"""
@inline function get_num_samples(signal)
length(signal)
end

@inline function get_num_samples(signal::AbstractMatrix)
size(signal, 1)
end

include("code_replica.jl")
include("carrier_replica.jl")
include("downconvert.jl")
include("cn0_estimation.jl")
include("discriminators.jl")
include("bit_buffer.jl")
include("correlator.jl")
include("discriminators.jl")
include("post_corr_filter.jl")
include("secondary_code_or_bit_detector.jl")
include("tracking_state.jl")
include("tracking_results.jl")
include("tracking_loop.jl")
include("gpsl1.jl")
include("gpsl5.jl")
include("galileo_e1b.jl")
include("sat_state.jl")
include("sample_parameters.jl")
include("update_sat_state.jl")
include("downconvert_and_correlate.jl")
include("gpu_downconvert_and_correlate.jl")
include("conventional_pll_and_dll.jl")
include("tracking_state.jl")
include("track.jl")
end
37 changes: 23 additions & 14 deletions src/bit_buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ BitBuffer to buffer bits
struct BitBuffer
buffer::UInt64
length::Int
prompt_accumulator::ComplexF64
prompt_accumulator_integrated_code_blocks::Int
end

function BitBuffer()
BitBuffer(0, 0)
BitBuffer(0, 0, complex(0.0, 0.0), 0)
end

@inline get_bits(bit_buffer::BitBuffer) = bit_buffer.buffer
Expand All @@ -23,24 +25,31 @@ Buffer data bits based on the prompt accumulation and the current prompt value.
function buffer(
system::AbstractGNSS,
bit_buffer,
prompt_accumulator,
integrated_code_blocks,
secondary_code_or_bit_found,
prev_code_phase,
code_phase,
integration_time,
prompt_correlator
prompt
)
prompt_accumulator = prompt_accumulator + secondary_code_or_bit_found *
prompt_correlator
prompt_accumulator = bit_buffer.prompt_accumulator + secondary_code_or_bit_found * prompt
prompt_accumulator_integrated_code_blocks = bit_buffer.prompt_accumulator_integrated_code_blocks +
secondary_code_or_bit_found * integrated_code_blocks

num_code_blocks_that_form_a_bit = Int(get_code_frequency(system) / (get_code_length(system) * get_data_frequency(system)))

if secondary_code_or_bit_found &&
(code_phase - prev_code_phase < 0 || integration_time == 1 / get_data_frequency(system))
return if secondary_code_or_bit_found &&
prompt_accumulator_integrated_code_blocks == num_code_blocks_that_form_a_bit
bit = real(prompt_accumulator) > 0
bit_buffer = BitBuffer(
BitBuffer(
get_bits(bit_buffer) << 1 + UInt64(bit),
length(bit_buffer) + 1
length(bit_buffer) + 1,
zero(prompt_accumulator),
0
)
else
BitBuffer(
bit_buffer.buffer,
bit_buffer.length,
prompt_accumulator,
prompt_accumulator_integrated_code_blocks
)
prompt_accumulator = zero(prompt_accumulator)
end
bit_buffer, prompt_accumulator
end
47 changes: 30 additions & 17 deletions src/cn0_estimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,55 @@ $(SIGNATURES)
MomentsCN0Estimator to estimate the CN0
"""
struct MomentsCN0Estimator{N} <: AbstractCN0Estimator
prompt_buffer::SVector{N, ComplexF64}
struct MomentsCN0Estimator <: AbstractCN0Estimator
end

"""
$(SIGNATURES)
MomentsCN0Estimator to estimate the CN0
"""
struct PromptsBuffer
prompt_buffer::Vector{ComplexF64}
current_index::Int
length::Int
end

function MomentsCN0Estimator(N)
MomentsCN0Estimator{N}(zero(SVector{N, ComplexF64}), 0, 0)
function PromptsBuffer(N)
PromptsBuffer(zeros(ComplexF64, N), 0, 0)
end

length(cn0_state::MomentsCN0Estimator) = cn0_state.length
get_prompt_buffer(cn0_state::MomentsCN0Estimator) = cn0_state.prompt_buffer
get_current_index(cn0_state::MomentsCN0Estimator) = cn0_state.current_index
length(buffer::PromptsBuffer) = buffer.length
get_prompt_buffer(buffer::PromptsBuffer) = buffer.prompt_buffer
get_current_index(buffer::PromptsBuffer) = buffer.current_index

"""
$(SIGNATURES)
Updates the `cn0_estimator` to include the information of the current prompt value.
"""
function update(cn0_estimator::MomentsCN0Estimator{N}, prompt) where N
next_index = mod(get_current_index(cn0_estimator), N) + 1
next_prompt_buffer = setindex(get_prompt_buffer(cn0_estimator), prompt, next_index)
next_length = min(length(cn0_estimator) + 1, N)
MomentsCN0Estimator{N}(next_prompt_buffer, next_index, next_length)
function update(buffer::PromptsBuffer, prompt)
buffer_length = length(buffer.prompt_buffer)
next_index = mod(get_current_index(buffer), buffer_length) + 1
buffer.prompt_buffer[next_index] = prompt
next_length = min(length(buffer) + 1, buffer_length)
PromptsBuffer(buffer.prompt_buffer, next_index, next_length)
end

"""
$(SIGNATURES)
Estimates the CN0 based on the struct `cn0_estimator`.
"""
function estimate_cn0(cn0_estimator::MomentsCN0Estimator, integration_time)
length(cn0_estimator) == 0 && return 0.0dBHz
abs2_prompt_buffer = abs2.(get_prompt_buffer(cn0_estimator))
M₂ = 1 / length(cn0_estimator) * sum(abs2_prompt_buffer)
M₄ = 1 / length(cn0_estimator) * sum(abs2_prompt_buffer .^ 2)
function estimate_cn0(
buffer::PromptsBuffer,
cn0_estimator::MomentsCN0Estimator,
integration_time
)
length(buffer) == 0 && return 0.0dBHz
abs2_prompt_buffer = abs2.(get_prompt_buffer(buffer))
M₂ = 1 / length(buffer) * sum(abs2_prompt_buffer)
M₄ = 1 / length(buffer) * sum(abs2_prompt_buffer .^ 2)
Pd = sqrt(abs(2 * M₂^2 - M₄))
noise_power = (M₂ - Pd)
noise_power_non_neg = noise_power - 2 * (noise_power < 0) * noise_power
Expand Down
Loading

0 comments on commit 2c5daa0

Please sign in to comment.