Skip to content

Commit

Permalink
Merge pull request #2 from ozmaden/master
Browse files Browse the repository at this point in the history
Incorporate the hotfix from the master repo
  • Loading branch information
coezmaden authored Jun 1, 2020
2 parents ad2b607 + 186acde commit 82bcf0f
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 81 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
[compat]
DocStringExtensions = "0.6, 0.7, 0.8"
GNSSSignals = "0.12.1"
LoopVectorization = "0.6.11"
LoopVectorization = "0.6.11, 0.7"
StaticArrays = "0.9, 0.10, 0.11, 0.12"
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"

[extras]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ using Tracking
using Tracking: Hz, GPSL1
carrier_doppler = 1000Hz
code_phase = 50
sample_frequency = 2.5e6Hz
sampling_frequency = 2.5e6Hz
prn = 1
state = TrackingState(GPSL1, carrier_doppler, code_phase)
results = track(signal, state, prn, sample_frequency)
next_results = track(next_signal, get_state(results), prn, sample_frequency)
results = track(signal, state, prn, sampling_frequency)
next_results = track(next_signal, get_state(results), prn, sampling_frequency)
```

If you'd like to track several signals at once (e.g. in the case of phased antenna arrays), you will have to specify the optional parameter `num_ants::NumAnts{N}` and pass a beamforming function to the `track` function:

```julia
state = TrackingState(GPSL1, carrier_doppler, code_phase, num_ants = NumAnts(4)) # 4 antenna channels
results = track(signal, state, prn, sample_frequency, post_corr_filter = x -> x[1]) # Post corr filter is optional
results = track(signal, state, prn, sampling_frequency, post_corr_filter = x -> x[1]) # Post corr filter is optional
```
14 changes: 7 additions & 7 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ These parameters are usually provided by the acquisition process of the satellit

The signal is tracked by
```julia
results = track(signal, state, prn, sample_frequency)
results = track(signal, state, prn, sampling_frequency)
```
where `prn` is the PRN and `sample_frequency` the sample frequency. Refer to [`track`](@ref)
where `prn` is the PRN and `sampling_frequency` the sampling frequency. Refer to [`track`](@ref)
to find about other optional parameters. The result contains the current state as well as
some additional information such as the last valid correlator output, found data bits, etc.
For each of those parameters a helper function exists to get the parameter
(e.g. `get_prompt(results)`) - see [Tracking Results](@ref). The next track function needs
the updated state:
```julia
next_results = track(next_signal, get_state(results), prn, sample_frequency)
next_results = track(next_signal, get_state(results), prn, sampling_frequency)
```

Here is an example for a single PRN:
Expand All @@ -55,11 +55,11 @@ using Tracking
using Tracking: Hz, GPSL1
carrier_doppler = 1000Hz
code_phase = 50
sample_frequency = 2.5e6Hz
sampling_frequency = 2.5e6Hz
prn = 1
state = TrackingState(GPSL1, carrier_doppler, code_phase)
results = track(signal, state, prn, sample_frequency)
next_results = track(next_signal, get_state(results), prn, sample_frequency)
results = track(signal, state, prn, sampling_frequency)
next_results = track(next_signal, get_state(results), prn, sampling_frequency)
```

## Track multiple signals coherently
Expand All @@ -77,7 +77,7 @@ drive the discriminators etc. However, an appropiate beamforming algorithm will
suit better. For that, you'll have to pass a function `post_corr_filter` to the track
function like the following:
```julia
results = track(signal, state, prn, sample_frequency, post_corr_filter = x -> x[end])
results = track(signal, state, prn, sampling_frequency, post_corr_filter = x -> x[end])
```

## Q/A
Expand Down
2 changes: 1 addition & 1 deletion docs/src/loop_filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ next_results = track(
next_signal,
get_state(results),
prn,
sample_frequency,
sampling_frequency,
carrier_loop_filter_bandwidth = 18Hz,
code_loop_filter_bandwidth = 1Hz
)
Expand Down
6 changes: 3 additions & 3 deletions src/agc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ get_amplitude_power(agc::GainControlledSignal) = agc.amplitude_power
@inline function GainControlledSignal!(
agc_signal::StructArray{Complex{Int16}},
signal::AbstractVector,
bits::Integer = 5
bits::Integer = 7
)
size(agc_signal) == size(signal) ||
throw(DimensionMismatch("size of AGC signal not equal to size of signal"))
Expand Down Expand Up @@ -49,7 +49,7 @@ end
@inline function GainControlledSignal!(
agc_signal::StructArray{Complex{Int16}},
signal::AbstractMatrix,
bits::Integer = 5
bits::Integer = 7
)
size(agc_signal) == size(signal) ||
throw(DimensionMismatch("size of AGC signal not equal to size of signal"))
Expand All @@ -62,7 +62,7 @@ end
GainControlledSignal(agc_signal, max_ampl, bits)
end

@inline function GainControlledSignal(signal, bits::Integer = 5)
@inline function GainControlledSignal(signal, bits::Integer = 7)
GainControlledSignal!(
StructArray{Complex{Int16}}(undef, size(signal)),
signal,
Expand Down
8 changes: 4 additions & 4 deletions src/carrier_replica.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function gen_carrier_replica!(
carrier_replica::StructArray{Complex{Int16}},
carrier_frequency,
sample_frequency,
sampling_frequency,
start_phase,
carrier_amplitude_power::Val{N},
start_sample,
Expand All @@ -10,7 +10,7 @@ function gen_carrier_replica!(
fpcarrier!(
carrier_replica,
carrier_frequency,
sample_frequency,
sampling_frequency,
start_phase,
start_sample = start_sample,
num_samples = num_samples,
Expand Down Expand Up @@ -48,13 +48,13 @@ Updates the carrier phase.
function update_carrier_phase(
num_samples,
carrier_frequency,
sample_frequency,
sampling_frequency,
start_phase,
carrier_amplitude_power::Val{N}
) where N
n = N + 2
fixed_point = 32 - n - 2
delta = floor(Int32, carrier_frequency * 1 << (fixed_point + n) / sample_frequency)
delta = floor(Int32, carrier_frequency * 1 << (fixed_point + n) / sampling_frequency)
fixed_point_start_phase = floor(Int32, start_phase * 1 << (fixed_point + n))
phase_fixed_point = delta * num_samples + fixed_point_start_phase
mod(
Expand Down
10 changes: 5 additions & 5 deletions src/code_replica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ function gen_code_replica!(
code_replica,
::Type{S},
code_frequency,
sample_frequency,
sampling_frequency,
start_code_phase::AbstractFloat,
start_sample::Integer,
num_samples::Integer,
early_late_sample_shift,
prn::Integer
) where S <: AbstractGNSSSystem
fixed_point = sizeof(Int) * 8 - 1 - min_bits_for_code_length(S)
delta = floor(Int, code_frequency * 1 << fixed_point / sample_frequency)
delta = floor(Int, code_frequency * 1 << fixed_point / sampling_frequency)
modded_start_code_phase = mod(
start_code_phase,
get_code_length(S) * get_secondary_code_length(S)
Expand Down Expand Up @@ -77,7 +77,7 @@ function update_code_phase(
::Type{S},
num_samples,
code_frequency,
sample_frequency,
sampling_frequency,
start_code_phase,
secondary_code_or_bit_found
) where S <: AbstractGNSSSystem
Expand All @@ -89,9 +89,9 @@ function update_code_phase(
end
code_length = get_code_length(S) *
(secondary_code_or_bit_found ? secondary_code_or_bit_length : 1)
mod(code_frequency * num_samples / sample_frequency + start_code_phase, code_length)
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 / sample_frequency)
# 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)
Expand Down
4 changes: 2 additions & 2 deletions src/correlator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ Calculate the shift between the early and late in samples.
function get_early_late_sample_shift(
::Type{S},
correlator::EarlyPromptLateCorrelator,
sample_frequency,
sampling_frequency,
preferred_code_shift
) where S <: AbstractGNSSSystem
round(Int, preferred_code_shift * sample_frequency / get_code_frequency(S))
round(Int, preferred_code_shift * sampling_frequency / get_code_frequency(S))
end

"""
Expand Down
41 changes: 23 additions & 18 deletions src/tracking_loop.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
$(SIGNATURES)
Track the signal `signal` based on the current tracking `state`, the sample frequency
`sample_frequency` and PRN `prn`. Optional configurations are:
Track the signal `signal` based on the current tracking `state`, the sampling frequency
`sampling_frequency` and PRN `prn`. Optional configurations are:
- Post correlation filter `post_corr_filter` defaults to `get_default_post_corr_filter(...)`
- Intermediate frequency `intermediate_frequency` defaults to 0Hz
- Maximal integration time `max_integration_time` defaults to 1ms. The actual integration
Expand All @@ -21,13 +21,13 @@ function track(
gain_controlled_signal::GainControlledSignal,
state::TrackingState{S, C, CALF, COLF, CN, DS},
prn::Integer,
sample_frequency;
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,
early_late_sample_shift = get_early_late_sample_shift(S,
get_correlator(state), sample_frequency, 0.5),
get_correlator(state), sampling_frequency, 0.5),
carrier_loop_filter_bandwidth = 18Hz,
code_loop_filter_bandwidth = 1Hz,
velocity_aiding = 0Hz,
Expand All @@ -44,6 +44,8 @@ function track(
if get_data_frequency(S) != 0Hz
@assert rem(1 / get_data_frequency(S), max_integration_time) == 0ms
end
N > 7 && throw(ArgumentError("The carrier amplitude power should be less than 8 to stay within 16 bits."))
(get_amplitude_power(gain_controlled_signal) + N) > 16 && throw(ArgumentError("The AGC amplitude + carrier replica amplitude should not exceed 16 bits"))
signal = get_signal(gain_controlled_signal)
correlator = get_correlator(state)
num_ants = get_num_ants(correlator)
Expand Down Expand Up @@ -73,7 +75,7 @@ function track(
num_samples_left_to_integrate = get_num_samples_left_to_integrate(
S,
max_integration_time,
sample_frequency,
sampling_frequency,
code_doppler,
code_phase,
found(sc_bit_detector)
Expand All @@ -89,7 +91,7 @@ function track(
code_replica,
S,
code_frequency,
sample_frequency,
sampling_frequency,
code_phase,
signal_start_sample,
num_samples_left,
Expand All @@ -99,7 +101,7 @@ function track(
carrier_replica = gen_carrier_replica!(
carrier_replica,
carrier_frequency,
sample_frequency,
sampling_frequency,
carrier_phase,
carrier_amplitude_power,
signal_start_sample,
Expand Down Expand Up @@ -127,7 +129,7 @@ function track(
carrier_phase = update_carrier_phase(
num_samples_left,
carrier_frequency,
sample_frequency,
sampling_frequency,
carrier_phase,
carrier_amplitude_power
)
Expand All @@ -136,11 +138,11 @@ function track(
S,
num_samples_left,
code_frequency,
sample_frequency,
sampling_frequency,
code_phase,
found(sc_bit_detector)
)
integration_time = integrated_samples / sample_frequency
integration_time = integrated_samples / sampling_frequency
if num_samples_left == num_samples_left_to_integrate &&
integration_time >= min_integration_time
got_correlator = true
Expand All @@ -153,7 +155,7 @@ function track(
S,
filtered_correlator,
early_late_sample_shift,
code_frequency / sample_frequency
code_frequency / sampling_frequency
)
carrier_freq_update, carrier_loop_filter = filter_loop(
carrier_loop_filter,
Expand Down Expand Up @@ -220,23 +222,25 @@ end
signal::AbstractArray,
state::TrackingState{S, C, CALF, COLF, CN, DS},
prn::Integer,
sample_frequency;
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,
early_late_sample_shift = get_early_late_sample_shift(S,
get_correlator(state), sample_frequency, 0.5),
get_correlator(state), sampling_frequency, 0.5),
carrier_loop_filter_bandwidth = 18Hz,
code_loop_filter_bandwidth = 1Hz,
velocity_aiding = 0Hz
velocity_aiding = 0Hz,
carrier_amplitude_power::Val{N} = Val(5)
) where {
S <: AbstractGNSSSystem,
C <: AbstractCorrelator,
CALF <: AbstractLoopFilter,
COLF <: AbstractLoopFilter,
CN <: AbstractCN0Estimator,
DS <: StructArray
DS <: StructArray,
N
}
correlator = get_correlator(state)
num_ants = get_num_ants(correlator)
Expand All @@ -245,7 +249,7 @@ end
GainControlledSignal(signal),
state,
prn,
sample_frequency,
sampling_frequency,
post_corr_filter = post_corr_filter,
intermediate_frequency = intermediate_frequency,
max_integration_time = max_integration_time,
Expand All @@ -254,6 +258,7 @@ end
carrier_loop_filter_bandwidth = carrier_loop_filter_bandwidth,
code_loop_filter_bandwidth = code_loop_filter_bandwidth,
velocity_aiding = velocity_aiding,
carrier_amplitude_power = carrier_amplitude_power
)
end

Expand Down Expand Up @@ -316,7 +321,7 @@ Calculates the number of samples to integrate.
function get_num_samples_left_to_integrate(
::Type{S},
max_integration_time,
sample_frequency,
sampling_frequency,
current_code_doppler,
current_code_phase,
secondary_code_or_bit_found
Expand All @@ -328,7 +333,7 @@ function get_num_samples_left_to_integrate(
secondary_code_or_bit_found
)
code_frequency = get_code_frequency(S) + current_code_doppler
ceil(Int, phase_to_integrate * sample_frequency / code_frequency)
ceil(Int, phase_to_integrate * sampling_frequency / code_frequency)
end

"""
Expand Down
8 changes: 4 additions & 4 deletions test/carrier_replica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ end
@testset "Update carrier phase" begin
carrier_phase = 0.25
carrier_frequency = 10Hz
sample_frequency = 100Hz
sampling_frequency = 100Hz
num_samples = 2000
phase = @inferred Tracking.update_carrier_phase(
num_samples,
carrier_frequency,
sample_frequency,
sampling_frequency,
carrier_phase,
Val(7)
)
@test phase mod(0.25 + 0.1 * 2000 + 0.5, 1) - 0.5 atol = 1 / 1 << 30 * 2500

carrier_phase = 0.25
carrier_frequency = 10Hz
sample_frequency = 2.5e6Hz
sampling_frequency = 2.5e6Hz
num_samples = 2500
phase = @inferred Tracking.update_carrier_phase(
num_samples,
carrier_frequency,
sample_frequency,
sampling_frequency,
carrier_phase,
Val(7)
)
Expand Down
Loading

0 comments on commit 82bcf0f

Please sign in to comment.