Skip to content

Commit

Permalink
Fix bug in code replica for phase = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Schoenbrod committed Mar 25, 2021
1 parent 1c0eb71 commit e889fad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Tracking"
uuid = "10b2438b-ffd4-5096-aa58-44041d5c8f3b"
authors = ["Soeren Zorn <[email protected]>"]
version = "0.14.1"
version = "0.14.2"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand Down
38 changes: 11 additions & 27 deletions src/code_replica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,19 @@ function gen_code_replica!(
)
most_early_sample_shift = correlator_sample_shifts[end]
most_late_sample_shift = correlator_sample_shifts[1]
early_late_samples = most_early_sample_shift - most_late_sample_shift
code_length = get_code_length(system)
num_early_late_samples = most_early_sample_shift - most_late_sample_shift
fixed_point = sizeof(Int) * 8 - 1 - min_bits_for_code_length(system)
delta = floor(Int, code_frequency * 1 << fixed_point / sampling_frequency)
modded_start_code_phase = mod(
start_code_phase + (most_late_sample_shift - start_sample) * code_frequency/sampling_frequency,
code_length * get_secondary_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)
code_length_fixed_point = code_length << fixed_point

end_code_phase = modded_start_code_phase + (start_sample + num_samples + early_late_samples) * code_frequency / sampling_frequency
number_of_iterations = floor(Int, end_code_phase / code_length)
first_iteration = floor(Int, (modded_start_code_phase + start_sample * code_frequency / sampling_frequency) / code_length)
fixed_point_code_phase = (start_sample - 1) * delta + fixed_point_start_code_phase - (first_iteration - 1) * code_length_fixed_point

samples_left = num_samples + early_late_samples
for m = first_iteration:number_of_iterations
phase_correction = m * code_length_fixed_point
number_of_samples = min(samples_left,
floor(Int, (2 * code_length_fixed_point - fixed_point_code_phase - delta) / delta)
)
samples_left -= number_of_samples
@inbounds for i = start_sample:start_sample+number_of_samples-1
fixed_point_code_phase = i * delta + fixed_point_start_code_phase - phase_correction
code_index = fixed_point_code_phase >> fixed_point
code_replica[i] = get_code_unsafe(system, code_index, prn)
end
start_sample += number_of_samples
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
code_replica
end
Expand Down

2 comments on commit e889fad

@zsoerenm
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/32798

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.2 -m "<description of version>" e889fad267a8f7929dc514aa26441cc36ec08a9c
git push origin v0.14.2

Please sign in to comment.