diff --git a/Project.toml b/Project.toml index 8a49674..547f224 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Tracking" uuid = "10b2438b-ffd4-5096-aa58-44041d5c8f3b" authors = ["Soeren Zorn "] -version = "0.14.7" +version = "0.14.8" [deps] DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" diff --git a/src/code_replica.jl b/src/code_replica.jl index 4df2e0a..ee92e46 100644 --- a/src/code_replica.jl +++ b/src/code_replica.jl @@ -18,7 +18,7 @@ function gen_code_replica!( start_code_phase::AbstractFloat, start_sample::Integer, num_samples::Integer, - correlator_sample_shifts::SVector, + correlator_sample_shifts::AbstractVector, prn::Integer ) most_early_sample_shift = correlator_sample_shifts[end] diff --git a/src/correlator.jl b/src/correlator.jl index 112c1c2..d58ce14 100644 --- a/src/correlator.jl +++ b/src/correlator.jl @@ -261,13 +261,12 @@ function correlate( start_sample, num_samples ) where {T <: AbstractCorrelator} - accumulators = zero_accumulators(get_accumulators(correlator), downconverted_signal) + a_re = zero_accumulators(get_accumulators(correlator), downconverted_signal) + a_im = zero_accumulators(get_accumulators(correlator), downconverted_signal) d_re = downconverted_signal.re d_im = downconverted_signal.im - a_re = real.(accumulators) - a_im = imag.(accumulators) @avx for i = start_sample:num_samples + start_sample - 1 - for j = 1:length(accumulators) + for j = 1:length(a_re) sample_shift = correlator_sample_shifts[j] - correlator_sample_shifts[1] a_re[j] += d_re[i] * code[i + sample_shift] a_im[j] += d_im[i] * code[i + sample_shift] @@ -278,10 +277,10 @@ function correlate( end function zero_accumulators(accumulators::SVector, signal) - zeros(MVector{length(accumulators), eltype(signal)}) + zeros(MVector{length(accumulators), real(eltype(signal))}) end function zero_accumulators(accumulators::Vector, signal) - zeros(eltype(signal), length(accumulators)) + zeros(real(eltype(signal)), length(accumulators)) end """ @@ -297,14 +296,13 @@ function correlate( start_sample, num_samples, ) where {N} - accumulators = zero(MMatrix{N, length(correlator_sample_shifts), eltype(downconverted_signal)}) - a_re = real.(accumulators) - a_im = imag.(accumulators) + a_re = zero_accumulators(get_accumulators(correlator), downconverted_signal) + a_im = zero_accumulators(get_accumulators(correlator), downconverted_signal) d_re = downconverted_signal.re d_im = downconverted_signal.im @avx for i = start_sample:num_samples + start_sample - 1 - for k = 1:size(accumulators, 2) - for j = 1:size(accumulators, 1) + for k = 1:size(a_re, 2) + for j = 1:size(a_re, 1) shift = correlator_sample_shifts[k] - correlator_sample_shifts[1] a_re[j,k] += d_re[i,j] * code[shift + i] a_im[j,k] += d_im[i,j] * code[shift + i] @@ -312,6 +310,12 @@ function correlate( end end - accumulators_new = SVector(eachcol(complex.(SMatrix(a_re), SMatrix(a_im)))...) - typeof(correlator)(map(+, get_accumulators(correlator), accumulators_new)) + typeof(correlator)(map(+, get_accumulators(correlator), eachcol(complex.(a_re, a_im)))) +end + +function zero_accumulators(accumulators::SVector{NC, <:SVector{NA}}, signal) where {NC, NA} + zeros(MMatrix{NA, NC, real(eltype(signal))}) +end +function zero_accumulators(accumulators::Vector{<:SVector{NA}}, signal) where NA + zeros(real(eltype(signal)), NA, length(accumulators)) end diff --git a/test/correlator.jl b/test/correlator.jl index 33648c6..1539949 100644 --- a/test/correlator.jl +++ b/test/correlator.jl @@ -9,17 +9,33 @@ @test @inferred(get_prompt(correlator, correlator_sample_shifts)) == 0.0 @test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0 + correlator = @inferred EarlyPromptLateCorrelator(NumAnts(1), 3) + @test isa(get_accumulators(correlator), Vector) + correlator = @inferred EarlyPromptLateCorrelator(NumAnts(1)) @test @inferred(get_early(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0 @test @inferred(get_prompt(correlator, correlator_sample_shifts)) == 0.0 @test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0 + correlator = @inferred EarlyPromptLateCorrelator(NumAnts(1), 3) + + @test @inferred(get_early(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0 + @test @inferred(get_prompt(correlator, correlator_sample_shifts)) == 0.0 + @test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == 0.0 + correlator = @inferred EarlyPromptLateCorrelator(NumAnts(2)) @test @inferred(get_early(correlator, correlator_sample_shifts, early_late_index_shift)) == SVector(0.0 + 0.0im, 0.0 + 0.0im) @test @inferred(get_prompt(correlator, correlator_sample_shifts)) == SVector(0.0 + 0.0im, 0.0 + 0.0im) @test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == SVector(0.0 + 0.0im, 0.0 + 0.0im) + + correlator = @inferred EarlyPromptLateCorrelator(NumAnts(2), 3) + + @test @inferred(get_early(correlator, correlator_sample_shifts, early_late_index_shift)) == SVector(0.0 + 0.0im, 0.0 + 0.0im) + @test @inferred(get_prompt(correlator, correlator_sample_shifts)) == SVector(0.0 + 0.0im, 0.0 + 0.0im) + @test @inferred(get_late(correlator, correlator_sample_shifts, early_late_index_shift)) == SVector(0.0 + 0.0im, 0.0 + 0.0im) + end @testset "Zeroing correlator" begin correlator = @inferred EarlyPromptLateCorrelator( @@ -154,6 +170,8 @@ ) ) end + + @testset "Correlate" begin gpsl1 = GPSL1() signal = StructArray{Complex{Float32}}( @@ -166,36 +184,33 @@ (1 + correlator_sample_shifts[1]:2500 + correlator_sample_shifts[end]) * 1023e3 / 2.5e6, 1 ) - correlator = EarlyPromptLateCorrelator(SVector(0.0 + 0.0im, 0.0 + 0.0im, 0.0 + 0.0im)) - - correlator_result = Tracking.correlate( - correlator, - signal, - code, - correlator_sample_shifts, - 1, - 2500 - ) - @test get_early(correlator_result, correlator_sample_shifts, 1) == - get_late(correlator_result, correlator_sample_shifts, 1) - @test get_prompt(correlator_result, correlator_sample_shifts) == 2500 - - signal_mat = repeat(signal, outer = (1,3)) - correlator_sample_shifts = SVector(-1,0,1) - correlator = EarlyPromptLateCorrelator(NumAnts(3)) - - correlator_result = Tracking.correlate( - correlator, - signal_mat, - code, - correlator_sample_shifts, - 1, - 2500, - ) - @test get_early(correlator_result, correlator_sample_shifts, 1) == get_late(correlator_result, correlator_sample_shifts, 1) - @test all(get_early(correlator_result, correlator_sample_shifts, 1) .== 1476) - @test all(get_prompt(correlator_result, correlator_sample_shifts) .== 2500) + @testset "↳ $na antennas" for na ∈ [1, 4, 15] + signal_mat = na == 1 ? signal : repeat(signal, outer=(1,na)) + + @testset "↳ $(string(type)) accumulator" for type ∈ [:SVector, :Vector] + if type == :SVector + correlator = EarlyPromptLateCorrelator(NumAnts(na)) + else + correlator = EarlyPromptLateCorrelator(NumAnts(na), 3) + end + + correlator_result = Tracking.correlate( + correlator, + signal_mat, + code, + correlator_sample_shifts, + 1, + 2500, + ) + early = get_early(correlator_result, correlator_sample_shifts, 1) + prompt = get_prompt(correlator_result, correlator_sample_shifts) + late = get_late(correlator_result, correlator_sample_shifts, 1) + @test early == late + @test all(early .== 1476) + @test all(prompt .== 2500) + end + end end end