Skip to content

Commit

Permalink
Format files and add docs (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Soeren Schoenbrod
  • Loading branch information
zsoerenm authored Mar 13, 2024
1 parent a7f414c commit 50e643c
Show file tree
Hide file tree
Showing 40 changed files with 2,145 additions and 1,656 deletions.
6 changes: 3 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
The package Tracking is licensed under the MIT License.

> Copyright (c) 2017-2019: Soeren Zorn
>
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
> "Software"), to deal in the Software without restriction, including
> without limitation the rights to use, copy, modify, merge, publish,
> distribute, sublicense, and/or sell copies of the Software, and to
> permit persons to whom the Software is furnished to do so, subject to
> the following conditions:
>
>
> The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.
>
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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"
Expand Down
187 changes: 95 additions & 92 deletions src/Tracking.jl
Original file line number Diff line number Diff line change
@@ -1,107 +1,110 @@
module Tracking

using CUDA
using DocStringExtensions
using GNSSSignals
using LoopVectorization
using StaticArrays
using StructArrays
using TrackingLoopFilters
using CUDA
using DocStringExtensions
using GNSSSignals
using LoopVectorization
using StaticArrays
using StructArrays
using TrackingLoopFilters

using Acquisition: AcquisitionResults
using Unitful: upreferred, Hz, dBHz, ms
import Base.zero, Base.length, Base.resize!, LinearAlgebra.dot
using Acquisition: AcquisitionResults
using Unitful: upreferred, Hz, dBHz, ms
import Base.zero, Base.length, Base.resize!, LinearAlgebra.dot

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
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
const StructVecOrMat{T} = Union{StructVector{T},StructArray{T,2}}

NumAnts(x) = NumAnts{x}()
struct NumAnts{x} end

struct NumAccumulators{x}
end
NumAnts(x) = NumAnts{x}()

NumAccumulators(x) = NumAccumulators{x}()
struct NumAccumulators{x} end

TupleLike{T <: Tuple} = Union{T, NamedTuple{<:Any, T}}
NumAccumulators(x) = NumAccumulators{x}()

struct DopplersAndFilteredPrompt
carrier_doppler::typeof(1.0Hz)
code_doppler::typeof(1.0Hz)
filtered_prompt::ComplexF64
end
TupleLike{T<:Tuple} = Union{T,NamedTuple{<:Any,T}}

"""
$(SIGNATURES)
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
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
@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("bit_buffer.jl")
include("correlator.jl")
include("discriminators.jl")
include("post_corr_filter.jl")
include("secondary_code_or_bit_detector.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")
include("code_replica.jl")
include("carrier_replica.jl")
include("downconvert.jl")
include("cn0_estimation.jl")
include("bit_buffer.jl")
include("correlator.jl")
include("discriminators.jl")
include("post_corr_filter.jl")
include("secondary_code_or_bit_detector.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("downconvert_and_correlate_cpu.jl")
include("downconvert_and_correlate_gpu.jl")
include("conventional_pll_and_dll.jl")
include("tracking_state.jl")
include("track.jl")
end
20 changes: 12 additions & 8 deletions src/bit_buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,33 @@ function buffer(
bit_buffer,
integrated_code_blocks,
secondary_code_or_bit_found,
prompt
prompt,
)
prompt_accumulator = bit_buffer.prompt_accumulator + secondary_code_or_bit_found * prompt
prompt_accumulator_integrated_code_blocks = bit_buffer.prompt_accumulator_integrated_code_blocks +
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)))

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

return if secondary_code_or_bit_found &&
prompt_accumulator_integrated_code_blocks == num_code_blocks_that_form_a_bit
prompt_accumulator_integrated_code_blocks == num_code_blocks_that_form_a_bit
bit = real(prompt_accumulator) > 0
BitBuffer(
get_bits(bit_buffer) << 1 + UInt64(bit),
length(bit_buffer) + 1,
zero(prompt_accumulator),
0
0,
)
else
BitBuffer(
bit_buffer.buffer,
bit_buffer.length,
prompt_accumulator,
prompt_accumulator_integrated_code_blocks
prompt_accumulator_integrated_code_blocks,
)
end
end
11 changes: 6 additions & 5 deletions src/carrier_replica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ function gen_carrier_replica!(
sampling_frequency,
start_phase,
start_sample,
num_samples
) where T
c_re = carrier_replica.re; c_im = carrier_replica.im
num_samples,
) where {T}
c_re = carrier_replica.re
c_im = carrier_replica.im
carrier_freq = upreferred(carrier_frequency / Hz)
sampling_freq = upreferred(sampling_frequency / Hz)
@avx for i in 0:num_samples - 1
c_im[i + start_sample], c_re[i + start_sample] =
@avx for i = 0:num_samples-1
c_im[i+start_sample], c_re[i+start_sample] =
sincos(T(2π) * (i * T(carrier_freq) / T(sampling_freq) + T(start_phase)))
end
carrier_replica
Expand Down
7 changes: 3 additions & 4 deletions src/cn0_estimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ $(SIGNATURES)
MomentsCN0Estimator to estimate the CN0
"""
struct MomentsCN0Estimator <: AbstractCN0Estimator
end
struct MomentsCN0Estimator <: AbstractCN0Estimator end

"""
$(SIGNATURES)
Expand All @@ -33,7 +32,7 @@ $(SIGNATURES)
Updates the `cn0_estimator` to include the information of the current prompt value.
"""
function update(buffer::PromptsBuffer, prompt)
buffer_length = length(buffer.prompt_buffer)
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)
Expand All @@ -48,7 +47,7 @@ Estimates the CN0 based on the struct `cn0_estimator`.
function estimate_cn0(
buffer::PromptsBuffer,
cn0_estimator::MomentsCN0Estimator,
integration_time
integration_time,
)
length(buffer) == 0 && return 0.0dBHz
abs2_prompt_buffer = abs2.(get_prompt_buffer(buffer))
Expand Down
32 changes: 18 additions & 14 deletions src/code_replica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ function gen_code_replica!(
start_sample::Integer,
num_samples::Integer,
correlator_sample_shifts::AbstractVector,
prn::Integer
prn::Integer,
)
earliest_sample_shift = correlator_sample_shifts[end]
latest_sample_shift = correlator_sample_shifts[1]
latest_sample_shift = correlator_sample_shifts[1]
total_samples = num_samples + earliest_sample_shift - latest_sample_shift
gen_code!(
view(code_replica, start_sample:start_sample + total_samples - 1),
view(code_replica, start_sample:start_sample+total_samples-1),
system,
prn,
sampling_frequency,
code_frequency,
start_code_phase,
latest_sample_shift
latest_sample_shift,
)
code_replica
end
Expand All @@ -47,20 +47,24 @@ function update_code_phase(
code_frequency,
sampling_frequency,
start_code_phase,
secondary_code_or_bit_found
secondary_code_or_bit_found,
)
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)))
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) *
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)
# fixed_point = sizeof(Int) * 8 - 1 - min_bits_for_code_length(S)
# delta = floor(Int, code_frequency * 1 << fixed_point / sampling_frequency)
# fixed_point_start_phase = floor(Int, start_code_phase * 1 << fixed_point)
# phase_fixed_point = delta * num_samples + fixed_point_start_phase
# mod(phase_fixed_point / 1 << fixed_point, code_length)
# fixed_point = sizeof(Int) * 8 - 1 - min_bits_for_code_length(S)
# delta = floor(Int, code_frequency * 1 << fixed_point / sampling_frequency)
# fixed_point_start_phase = floor(Int, start_code_phase * 1 << fixed_point)
# phase_fixed_point = delta * num_samples + fixed_point_start_phase
# mod(phase_fixed_point / 1 << fixed_point, code_length)
end

"""
Expand Down
Loading

0 comments on commit 50e643c

Please sign in to comment.