Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resampleing with Integer or Rational unit rate (1) gives Nyquist frequency error #444

Open
anowacki opened this issue Aug 13, 2021 · 0 comments

Comments

@anowacki
Copy link
Contributor

Trying to resample a signal to its original rate (i.e., with rate = 1 leads to an error in normalize_freq if rate is an Integer or Rational:

julia> using DSP

julia> resample(1:10, 1) # or resample(1:10, 1//1)
ERROR: frequencies must be less than the Nyquist frequency 1.0
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] normalize_freq
   @ ~/.julia/packages/DSP/q9iEF/src/Filters/design.jl:241 [inlined]
 [3] #Lowpass#22
   @ ~/.julia/packages/DSP/q9iEF/src/Filters/design.jl:256 [inlined]
 [4] Lowpass
   @ ~/.julia/packages/DSP/q9iEF/src/Filters/design.jl:256 [inlined]
 [5] resample_filter(rate::Int64, rel_bw::Float64, attenuation::Int64)
   @ DSP.Filters ~/.julia/packages/DSP/q9iEF/src/Filters/design.jl:647
 [6] resample_filter
   @ ~/.julia/packages/DSP/q9iEF/src/Filters/design.jl:628 [inlined]
 [7] resample(x::UnitRange{Int64}, rate::Int64)
   @ DSP.Filters ~/.julia/packages/DSP/q9iEF/src/Filters/stream_filt.jl:732
 [8] top-level scope
   @ REPL[90]:1

Inaccuracy of the 'resampled' signal aside, this at least works as expected with a Real argument:

julia> resample(1:10, 1.0)
10-element Vector{Float64}:
  1.0000535025139883
  2.0001070050279766
  3.000160507541965
  4.000214010055953
  5.000267512569941
  6.00032101508393
  7.000374517597918
  8.000428020111906
  9.000481522625895
 10.000535025139882

I wonder whether it is worth checking whether rate == 1 (which is true for 1.0, 1.f0, 1//1, etc.) first in resample, and simply returning the input (or a copy of it) straight away? If so, I'm happy to submit a PR for that.

@anowacki anowacki changed the title resampleing with Real or Rational unit rate (1) gives Nyquist frequency error resampleing with Integer or Rational unit rate (1) gives Nyquist frequency error Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant