Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update due to changes in GNSSSignals #40

Merged
merged 9 commits into from
Nov 23, 2022
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ TrackingLoopFilters = "0814aff9-93cb-554c-9fff-9bf1cfdb5efa"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
Acquisition = "0.0.2"
Acquisition = "0.0.2, 0.0.4"
CUDA = "3.5"
DocStringExtensions = "0.6, 0.7, 0.8"
GNSSSignals = "0.15.5"
DocStringExtensions = "0.6, 0.7, 0.8, 0.9"
GNSSSignals = "0.16"
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"
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"
Expand Down
5 changes: 4 additions & 1 deletion src/Tracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module Tracking
export track
export get_bits
export get_num_bits
export get_filtered_prompt
export get_post_corr_filter

export TrackingState
export NumAnts
Expand All @@ -40,6 +42,7 @@ module Tracking
#export VeryEarlyPromptLateCorrelator
export SecondaryCodeOrBitDetector
export GainControlledSignal
export AbstractPostCorrFilter

struct NumAnts{x}
end
Expand All @@ -51,6 +54,7 @@ module Tracking

NumAccumulators(x) = NumAccumulators{x}()

include("post_corr_filter.jl")
include("code_replica.jl")
include("carrier_replica.jl")
include("downconvert.jl")
Expand All @@ -65,6 +69,5 @@ module Tracking
include("gpsl1.jl")
include("gpsl5.jl")
include("galileo_e1b.jl")
include("boc.jl")
include("downconvert_and_correlate.jl")
end
19 changes: 0 additions & 19 deletions src/boc.jl

This file was deleted.

6 changes: 3 additions & 3 deletions src/correlator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ $(SIGNATURES)

Filter the Correlator by the function `post_corr_filter`
"""
function filter(post_corr_filter, correlator::T) where T <: AbstractCorrelator
(T.name.wrapper)(map(x -> post_corr_filter(x), get_accumulators(correlator)))
function apply(post_corr_filter, correlator::T) where T <: AbstractCorrelator
(T.name.wrapper)(map(post_corr_filter, get_accumulators(correlator)))
end

"""
Expand Down Expand Up @@ -246,7 +246,7 @@ $(SIGNATURES)
Normalize the correlator
"""
function normalize(correlator::AbstractCorrelator, integrated_samples)
filter(x -> x / integrated_samples, correlator)
apply(x -> x / integrated_samples, correlator)
end
"""
$(SIGNATURES)
Expand Down
2 changes: 1 addition & 1 deletion src/downconvert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ end
signal_real = reinterpret(reshape, ST, signal)
ds_re = downconverted_signal.re; ds_im = downconverted_signal.im
c_re = carrier_replica.re; c_im = carrier_replica.im
@avx for i = start_sample:num_samples + start_sample - 1, j = 1:size(signal_real, 3)
@avx for i = start_sample:num_samples + start_sample - 1, j = 1:size(ds_re, 2)
ds_re[i, j] = signal_real[1, i, j] * c_re[i] + signal_real[2, i, j] * c_im[i]
ds_im[i, j] = signal_real[2, i, j] * c_re[i] - signal_real[1, i, j] * c_im[i]
end
Expand Down
8 changes: 8 additions & 0 deletions src/post_corr_filter.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
abstract type AbstractPostCorrFilter end

struct DefaultPostCorrFilter <: AbstractPostCorrFilter end

update(filter::DefaultPostCorrFilter, prompt) = filter

(filter::DefaultPostCorrFilter)(x) = x
(filter::DefaultPostCorrFilter)(x::AbstractVector) = last(x)
16 changes: 11 additions & 5 deletions src/tracking_loop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ Track the signal `signal` based on the current tracking `state`, the sampling fr
"""
function track(
signal,
state::TrackingState{S, C, CALF, COLF, CN, DS, CAR, COR},
state::TrackingState{S, C, CALF, COLF, CN, DS, CAR, COR, PCF},
sampling_frequency;
post_corr_filter = get_default_post_corr_filter(get_correlator(state)),
intermediate_frequency = 0.0Hz,
max_integration_time::typeof(1ms) = 1ms,
min_integration_time::typeof(1.0ms) = 0.75ms,
Expand All @@ -40,7 +39,8 @@ function track(
CN <: AbstractCN0Estimator,
DS,
CAR,
COR
COR,
PCF <: AbstractPostCorrFilter,
}
prn = get_prn(state)
system = get_system(state)
Expand Down Expand Up @@ -72,8 +72,10 @@ function track(
prompt_accumulator = get_prompt_accumulator(state)
integrated_samples = get_integrated_samples(state)
cn0_estimator = get_cn0_estimator(state)
post_corr_filter = get_post_corr_filter(state)
signal_start_sample = 1
bit_buffer = BitBuffer()
filtered_prompt = zero(ComplexF64)
valid_correlator = zero(correlator)
valid_correlator_carrier_phase = 0.0
valid_correlator_carrier_frequency = 0.0Hz
Expand Down Expand Up @@ -135,7 +137,9 @@ function track(
valid_correlator = correlator
valid_correlator_carrier_phase = carrier_phase
valid_correlator_carrier_frequency = carrier_frequency
filtered_correlator = filter(post_corr_filter, correlator)
post_corr_filter = update(post_corr_filter, get_prompt(correlator, correlator_sample_shifts))
filtered_correlator = apply(post_corr_filter, correlator)
filtered_prompt = get_prompt(filtered_correlator, correlator_sample_shifts)
pll_discriminator = pll_disc(
system,
filtered_correlator,
Expand Down Expand Up @@ -194,9 +198,10 @@ function track(
num_samples_left == signal_samples_left && break
signal_start_sample += num_samples_left
end
next_state = TrackingState{S, C, CALF, COLF, CN, DS, CAR, COR}(
next_state = TrackingState{S, C, CALF, COLF, CN, DS, CAR, COR, PCF}(
prn,
system,
post_corr_filter,
init_carrier_doppler,
init_code_doppler,
carrier_doppler,
Expand All @@ -218,6 +223,7 @@ function track(
TrackingResults(
next_state,
valid_correlator,
filtered_prompt,
correlator_sample_shifts,
early_late_index_shift,
valid_correlator_carrier_frequency,
Expand Down
19 changes: 17 additions & 2 deletions src/tracking_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct TrackingResults{
}
state::TS
correlator::C
filtered_prompt::ComplexF64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a special reason for putting the filtered prompt signal in the tracking results? In my opinion, this is quite unsafe to evaluate, as the tracking loop might generate more than one prompt (or even no).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's like correlator, but filtered. correlator holds the last valid correlation results (after a complete code length has been integrated). The same applies to filtered prompt. filtered_prompt is needed because in some circumstances the filter can not be reconstructed outside of track. The implementation here allows to update the states of the post correlation filter every time there are new correlation results. Therefore, the state of the post correlation filter might be different at the time that track returns.

correlator_sample_shifts::CS
early_late_index_shift::ELI
correlator_carrier_frequency::typeof(1.0Hz)
Expand Down Expand Up @@ -157,6 +158,20 @@ Check if the secondary code or bit has been found.
"""
$(SIGNATURES)

Check if the secondary code or bit has been found.
Get used system.
"""
@inline get_system(results::TrackingResults) = get_system(get_state(results))

"""
$(SIGNATURES)

Get filtered prompt.
"""
@inline get_filtered_prompt(results::TrackingResults) = results.filtered_prompt

"""
$(SIGNATURES)

Get Post correlation filter.
"""
@inline get_system(results::TrackingResults) = get_system(get_state(results))
@inline get_post_corr_filter(results::TrackingResults) = get_post_corr_filter(get_state(results))
48 changes: 42 additions & 6 deletions src/tracking_state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ struct TrackingState{
CN <: AbstractCN0Estimator,
DS <: Union{DownconvertedSignalCPU, Nothing},
CAR <: Union{CarrierReplicaCPU, Nothing},
COR <: Union{Vector{Int8}, Nothing}
COR <: Union{Vector{<:Real}, Nothing},
PCF <: AbstractPostCorrFilter,
zsoerenm marked this conversation as resolved.
Show resolved Hide resolved
}
prn::Int
system::S
post_corr_filter::PCF
init_carrier_doppler::typeof(1.0Hz)
init_code_doppler::typeof(1.0Hz)
carrier_doppler::typeof(1.0Hz)
Expand All @@ -85,6 +87,33 @@ struct TrackingState{
code::COR
end

function TrackingState(
track_state::TrackingState;
post_corr_filter,
)
TrackingState(
track_state.prn,
track_state.system,
post_corr_filter,
track_state.init_carrier_doppler,
track_state.init_code_doppler,
track_state.carrier_doppler,
track_state.code_doppler,
track_state.carrier_phase,
track_state.code_phase,
track_state.correlator,
track_state.carrier_loop_filter,
track_state.code_loop_filter,
track_state.sc_bit_detector,
track_state.integrated_samples,
track_state.prompt_accumulator,
track_state.cn0_estimator,
track_state.downconverted_signal,
track_state.carrier,
track_state.code
)
end

"""
$(SIGNATURES)

Expand All @@ -106,6 +135,7 @@ function TrackingState(
system::S,
carrier_doppler,
code_phase;
post_corr_filter::PCF = DefaultPostCorrFilter(),
code_doppler = carrier_doppler * get_code_center_frequency_ratio(system),
carrier_phase = 0.0,
carrier_loop_filter::CALF = ThirdOrderBilinearLF(),
Expand All @@ -123,7 +153,8 @@ function TrackingState(
C <: AbstractCorrelator,
CALF <: AbstractLoopFilter,
COLF <: AbstractLoopFilter,
CN <: AbstractCN0Estimator
CN <: AbstractCN0Estimator,
PCF <: AbstractPostCorrFilter
}
if found(sc_bit_detector)
code_phase = mod(code_phase, get_code_length(system) *
Expand All @@ -133,11 +164,12 @@ function TrackingState(
end
downconverted_signal = DownconvertedSignalCPU(num_ants)
carrier = CarrierReplicaCPU()
code = Vector{Int8}(undef, 0)
code = Vector{get_code_type(system)}(undef, 0)

TrackingState{S, C, CALF, COLF, CN, typeof(downconverted_signal), typeof(carrier), typeof(code)}(
TrackingState{S, C, CALF, COLF, CN, typeof(downconverted_signal), typeof(carrier), typeof(code), PCF}(
prn,
system,
post_corr_filter,
carrier_doppler,
code_doppler,
carrier_doppler,
Expand All @@ -164,6 +196,7 @@ function TrackingState(
carrier_doppler,
code_phase;
num_samples,
post_corr_filter::PCF = DefaultPostCorrFilter(),
code_doppler = carrier_doppler * get_code_center_frequency_ratio(system),
carrier_phase = 0.0,
carrier_loop_filter::CALF = ThirdOrderBilinearLF(),
Expand All @@ -180,7 +213,8 @@ function TrackingState(
C <: AbstractCorrelator,
CALF <: AbstractLoopFilter,
COLF <: AbstractLoopFilter,
CN <: AbstractCN0Estimator
CN <: AbstractCN0Estimator,
PCF <: AbstractPostCorrFilter
}
if found(sc_bit_detector)
code_phase = mod(code_phase, get_code_length(system) *
Expand All @@ -192,9 +226,10 @@ function TrackingState(
carrier = nothing
code = nothing

TrackingState{S, C, CALF, COLF, CN, Nothing, Nothing, Nothing}(
TrackingState{S, C, CALF, COLF, CN, Nothing, Nothing, Nothing, PCF}(
prn,
system,
post_corr_filter,
carrier_doppler,
code_doppler,
carrier_doppler,
Expand Down Expand Up @@ -242,3 +277,4 @@ end
@inline get_carrier(state::TrackingState) = state.carrier
@inline get_code(state::TrackingState) = state.code
@inline get_prn(state::TrackingState) = state.prn
@inline get_post_corr_filter(state::TrackingState) = state.post_corr_filter
18 changes: 0 additions & 18 deletions test/boc.jl

This file was deleted.

17 changes: 9 additions & 8 deletions test/correlator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@
@testset "Filter correlator" begin
correlator = @inferred EarlyPromptLateCorrelator(
SVector(
SVector(1.0 + 0.0im, 1.0 + 0.0im),
SVector(1.0 + 0.0im, 1.0 + 0.0im),
SVector(1.0 + 0.0im, 1.0 + 0.0im)
SVector(1.0 + 0.0im, 1.0 + 1.0im),
SVector(1.0 + 0.0im, 2.0 + 0.0im),
SVector(1.0 + 1.0im, 1.0 + 3.0im)
)
)
filtered_correlator = @inferred Tracking.filter(x -> x[1], correlator)
default_post_corr_filter = Tracking.DefaultPostCorrFilter()
filtered_correlator = @inferred Tracking.apply(default_post_corr_filter, correlator)
@test filtered_correlator == EarlyPromptLateCorrelator(
SVector(
1.0 + 0.0im,
1.0 + 0.0im,
1.0 + 0.0im
1.0 + 1.0im,
2.0 + 0.0im,
1.0 + 3.0im
)
)

Expand All @@ -94,7 +95,7 @@
1.0 + 0.0im
)
)
filtered_correlator = @inferred Tracking.filter(x -> 2 * x, correlator)
filtered_correlator = @inferred Tracking.apply(x -> 2 * x, correlator)
@test filtered_correlator == EarlyPromptLateCorrelator(
SVector(
2.0 + 0.0im,
Expand Down
18 changes: 0 additions & 18 deletions test/cuda/boc.jl

This file was deleted.

Loading