Skip to content

Commit

Permalink
Allow multiple signal types - including integers
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Schoenbrod committed Jun 15, 2021
1 parent 8979b74 commit c6be371
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
7 changes: 3 additions & 4 deletions src/tracking_loop.jl
Expand Up @@ -127,7 +127,6 @@ function track(
if num_samples_left == num_samples_left_to_integrate &&
integration_time >= min_integration_time
got_correlator = true

correlator = normalize(correlator, integrated_samples)
valid_correlator = correlator
valid_correlator_carrier_phase = carrier_phase
Expand Down Expand Up @@ -280,13 +279,13 @@ end
function choose(replica::CarrierReplicaCPU, signal::AbstractArray{Complex{Float64}})
replica.carrier_f64
end
function choose(replica::CarrierReplicaCPU, signal::AbstractArray{Complex{Float32}})
function choose(replica::CarrierReplicaCPU, signal::AbstractArray{Complex{T}}) where T <: Number
replica.carrier_f32
end
function choose(replica::DownconvertedSignalCPU, signal::AbstractArray{Complex{Float64}})
replica.downconverted_signal_f64
end
function choose(replica::DownconvertedSignalCPU, signal::AbstractArray{Complex{Float32}})
function choose(replica::DownconvertedSignalCPU, signal::AbstractArray{Complex{T}}) where T <: Number
replica.downconverted_signal_f32
end

Expand Down Expand Up @@ -411,7 +410,7 @@ function resize!(ds::DownconvertedSignalCPU, b::Integer, signal::AbstractMatrix{
)
end

function resize!(ds::DownconvertedSignalCPU, b::Integer, signal::AbstractMatrix{Complex{Float32}})
function resize!(ds::DownconvertedSignalCPU, b::Integer, signal::AbstractMatrix{Complex{T}}) where T <: Number
num_ants = size(signal, 2)
DownconvertedSignalCPU(
size(ds.downconverted_signal_f32, 1) == b ?
Expand Down
33 changes: 19 additions & 14 deletions test/tracking_loop.jl
Expand Up @@ -8,29 +8,30 @@
@test @inferred(post_corr_filter(SVector(1.0 + 0.0im, 2.0 + 0.0im))) == 1.0 + 0.0im
end

@testset "Resize downconverted signal for multiple ants" for type in (Float32, Float64)
@testset "Resize downconverted signal ($type) for multiple ants" for type in (Int16, Int32, Int64, Float32, Float64)
downconverted_signal_temp = Tracking.DownconvertedSignalCPU(NumAnts(4))
signal = StructArray(ones(Complex{type}, 2500, 4))
downconverted_signal = Tracking.resize!(downconverted_signal_temp, 2500, signal)
if type == Float32
@test size(downconverted_signal.downconverted_signal_f32) == (2500, 4)
@test size(downconverted_signal.downconverted_signal_f64) == (0, 4)
else
if type == Float64
@test size(downconverted_signal.downconverted_signal_f32) == (0, 4)
@test size(downconverted_signal.downconverted_signal_f64) == (2500, 4)
else
@test size(downconverted_signal.downconverted_signal_f32) == (2500, 4)
@test size(downconverted_signal.downconverted_signal_f64) == (0, 4)
end
end

@testset "Resize downconverted signal for single ant" for type in (Float32, Float64)
@testset "Resize downconverted signal ($type) for single ant" for type in (Int16, Int32, Int64, Float32, Float64)
downconverted_signal_temp = Tracking.DownconvertedSignalCPU(NumAnts(1))
signal = StructArray(ones(Complex{type}, 2500))
downconverted_signal = Tracking.resize!(downconverted_signal_temp, 2500, signal)
if type == Float32
@test size(downconverted_signal.downconverted_signal_f32) == (2500,)
@test size(downconverted_signal.downconverted_signal_f64) == (0,)
else
if type == Float64
@test size(downconverted_signal.downconverted_signal_f32) == (0,)
@test size(downconverted_signal.downconverted_signal_f64) == (2500,)
else
@test size(downconverted_signal.downconverted_signal_f32) == (2500,)
@test size(downconverted_signal.downconverted_signal_f64) == (0,)

end
end

Expand Down Expand Up @@ -145,7 +146,7 @@ end
@test code_freq == 1Hz + (2Hz + 3Hz) / 1540 - 0.5Hz
end

@testset "Tracking" begin
@testset "Tracking with signal of type $type" for type in (Int16, Int32, Int64, Float32, Float64)
gpsl1 = GPSL1()
carrier_doppler = 200Hz
start_code_phase = 100
Expand All @@ -156,14 +157,16 @@ end
start_carrier_phase = π / 2
state = TrackingState(gpsl1, carrier_doppler - 20Hz, start_code_phase)

signal = cis.(
signal_temp = cis.(
2π .* carrier_doppler .* range ./ sampling_frequency .+ start_carrier_phase
) .*
get_code.(
gpsl1,
code_frequency .* range ./ sampling_frequency .+ start_code_phase,
prn
)
scaling = 512
signal = type <: Integer ? complex.(floor.(type, real.(signal_temp) * scaling), floor.(type, imag.(signal_temp) * scaling)) : Complex{type}.(signal_temp)

track_result = @inferred track(signal, state, prn, sampling_frequency)

Expand Down Expand Up @@ -230,7 +233,7 @@ end
# plot(imag.(tracked_prompts))
end

@testset "Track multiple signals" begin
@testset "Track multiple signals with signal of type $type" for type in (Int16, Int32, Int64, Float32, Float64)
gpsl1 = GPSL1()
carrier_doppler = 200Hz
start_code_phase = 100
Expand All @@ -249,7 +252,9 @@ end
code_frequency .* range ./ sampling_frequency .+ start_code_phase,
prn
)
signal_mat = repeat(signal, outer = (1,3))
signal_mat_temp = repeat(signal, outer = (1,3))
scaling = 512
signal_mat = type <: Integer ? complex.(floor.(type, real.(signal_mat_temp) * scaling), floor.(type, imag.(signal_mat_temp) * scaling)) : Complex{type}.(signal_mat_temp)

@test_throws ArgumentError track(signal_mat', state, prn, sampling_frequency)

Expand Down

0 comments on commit c6be371

Please sign in to comment.