Skip to content

Commit

Permalink
Make min und maxFreq inclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
nHackel committed Nov 1, 2024
1 parent ed1de07 commit 91b9704
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/FrequencyFilter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ function filterFrequenciesByMinFreq!(indices, f::MPIFile, minFreq; numPeriodGrou
minIdx = floor(Int, minFreq / rxBandwidth(f) * (nFreq-1) ) + 1
return filterFrequenciesByMinIdx!(indices, minIdx)
end
filterFrequenciesByMinIdx!(indices, minIdx) = minIdx > 0 ? filter!(x -> x[1] > minIdx, indices) : indices
filterFrequenciesByMinIdx!(indices, minIdx) = minIdx > 0 ? filter!(x -> x[1] >= minIdx, indices) : indices

export filterFrequenciesByMaxFreq!
function filterFrequenciesByMaxFreq!(indices, f::MPIFile, maxFreq; numPeriodGrouping = 1)
nFreq = rxNumFrequencies(f, numPeriodGrouping)
maxIdx = ceil(Int, maxFreq / rxBandwidth(f) * (nFreq-1) ) + 1
return filterFrequenciesByMaxIdx!(indices, maxIdx)
end
filterFrequenciesByMaxIdx!(indices, maxIdx) = filter!(x-> x[1] < maxIdx, indices)
filterFrequenciesByMaxIdx!(indices, maxIdx) = filter!(x-> x[1] <= maxIdx, indices)

export filterFrequenciesByMaxMixingOrder!
filterFrequenciesByMaxMixingOrder!(indices, maxMixingOrder, f::MPIFile) = filterFrequenciesByMaxMixingOrder!(indices, maxMixingOrder, mixingFactors(f))
Expand Down
22 changes: 12 additions & 10 deletions test/FrequencyFilter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@test length(unfiltered) == (bandwidth + 1) * numChannels
@test eltype(unfiltered) == CartesianIndex{2}
nFreq = bandwidth + 1
frequencies = rxFrequencies(mdf)

@testset "Filter Receive Channels" begin
@test length(filterFrequencies(mdf, recChannels = 1:numChannels)) == length(unfiltered)
Expand All @@ -36,14 +37,15 @@

@testset "Min and Max Frequencies" begin
# minFreq = 0 -> Offset Frequency with index 1
@test length(filterFrequencies(mdf, minFreq = 0)) == length(unfiltered)
@test length(filterFrequencies(mdf, minFreq = 1)) == length(unfiltered) - numChannels skip = true
@test length(filterFrequencies(mdf, minFreq = bandwidth)) == numChannels skip = true
@test length(filterFrequencies(mdf, minFreq = nFreq)) == 0

@test length(filterFrequencies(mdf, maxFreq = bandwidth)) == length(unfiltered)
@test length(filterFrequencies(mdf, maxFreq = bandwidth - 1)) == length(unfiltered) - numChannels skip = true
@test length(filterFrequencies(mdf, maxFreq = 0)) == numChannels skip = true
@test length(filterFrequencies(mdf, minFreq = frequencies[1])) == length(unfiltered)
@test length(filterFrequencies(mdf, minFreq = 1.0)) == length(unfiltered) - numChannels
@test length(filterFrequencies(mdf, minFreq = frequencies[end])) == numChannels
@test length(filterFrequencies(mdf, minFreq = frequencies[end] + 1.0)) == 0

@test length(filterFrequencies(mdf, maxFreq = frequencies[end])) == length(unfiltered)
@test length(filterFrequencies(mdf, maxFreq = frequencies[end - 1])) == length(unfiltered) - numChannels
@test length(filterFrequencies(mdf, maxFreq = 0.0)) == numChannels
@test isempty(filterFrequencies(mdf, maxFreq = -1.0))
end

@testset "Stop Bands" begin
Expand Down Expand Up @@ -89,8 +91,8 @@
@test length(filterFrequencies(mdf, numUsedFreqs = nFreq + 1)) == length(unfiltered) skip = true
@test length(filterFrequencies(mdf, numUsedFreqs = nFreq - 1)) == length(unfiltered) - numChannels skip = true

freqs = filterFrequencies(mdf, numUsedFreqs = 1)
@test all(i -> i[1] == nFreq, freqs) skip = true
#freqs = filterFrequencies(mdf, numUsedFreqs = 1)
#@test all(i -> i[1] == nFreq, freqs) skip = true
end

end

0 comments on commit 91b9704

Please sign in to comment.