JuliaDSP / DSP.jl

Filter design, periodograms, window functions, and other digital signal processing functionality
https://docs.juliadsp.org/stable/contents/
Other
380 stars 110 forks source link

Make the length of the frequency response adjustable #562

Open hyperkomplexe opened 2 months ago

hyperkomplexe commented 2 months ago

When calling H, w = freqresp(filter) the returned frequency axis w is fixed at 257 rows.

This is an issue when someone (like me for example) needs a higher resolution along the frequency axis.

Matlab has an optional argument n which is used to specify the length of the axis required. https://ch.mathworks.com/help/signal/ref/freqz.html

Scipy also has worN as an optional argument allowing this to be specified. https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.freqz.html

I would suggest adding something similar.

I suppose it should be simple enough to implement, just add the length as an optional argument to the freqresp call. https://github.com/JuliaDSP/DSP.jl/blob/3e3524f6ac7a52ab2f06843328f0b3b41bd62bb8/src/Filters/response.jl#L9-L15

Then pass it also into the _freqrange call. https://github.com/JuliaDSP/DSP.jl/blob/3e3524f6ac7a52ab2f06843328f0b3b41bd62bb8/src/Filters/response.jl#L154

Cheers

martinholters commented 2 months ago

One issue here is that we have freqresp(filter::FilterCoefficients, w), where w can be anything that can be broadcast over, including single numbers. So freqresp(filter, 2) already has a meaning -- evaluating the filter at ω=2. Maybe adding a kwarg to the one-argument method of freqresp (that gets then passed on to _freqrange) might be an option, so that one could do e.g. freqresp(filter; n=1000).

(Meanwhile, the work-around would be calling freqresp(filter, range(0, stop=π, length=1000) for z-domain filters.)