 # DSP.jl: analog filter design

I am using the following on Julia 1.3.1:

``````using DSP
fs=4*5000e6
responsetype = Highpass(4000e6; fs=fs)
designmethod = Elliptic(8, 1.0, 40.0)
fil=analogfilter(responsetype, designmethod)
rng=range(3100e6, stop=4200e6, length=500)
resp=freqs(fil, rng, fs)

using Plots
plot(collect(rng)/1e9, (abs.(resp)))
``````

and I get the plot

This is obviously not a high pass response. Can I get some guidance on what I am doing wrong? I am able to get the equivalent Matlab design working, so I know the design is feasible. My conclusion is that I have not understood the documentation.

Kumar

First tell us what you are trying to do

Second put in all the units in comments

``````using DSP
fs=4*5000e6 # what unit? Hz or rad/sec or cycles/sec
# 4000e6  what unit? Hz or rad/sec or cycles/sec
responsetype = Highpass(4000e6; fs=fs)
designmethod = Elliptic(8, 1.0, 40.0)
fil=analogfilter(responsetype, designmethod)
# what unit? Hz or rad/sec or cycles/sec
rng=range(3100e6, stop=4200e6, length=500)
resp=freqs(fil, rng, fs)

using Plots
plot(collect(rng)/1e9, (abs.(resp)))
``````

All units are in Hz. Final plotting is in GHz

``````using DSP
fs=4*5000e6 # Hz
# 4000e6   Hz
responsetype = Highpass(4000e6; fs=fs)
designmethod = Elliptic(8, 1.0, 40.0)
fil=analogfilter(responsetype, designmethod)
# what unit? Hz
rng=range(3100e6, stop=4200e6, length=500)
resp=freqs(fil, rng, fs)

using Plots
plot(collect(rng)/1e9, (abs.(resp)))
``````

If you plot a larger range you’ll see an HPF response – I plotted from 100 MHz to 5 GHz. Still, the cutoff frequency seems to be wrong (around 1.2 GHz), and the passband ripple seems a little high.

Thanks. Here is an experiment and more detailed comments in the code.

``````
# Test script to design an analog highpass elliptic filter with 8 poles and a cutoff
# frequency of 4000 Hz. Various pressing questions arise:
#           1. What is the scaling of parameters for cutoff frequencies?
#           2. Why does an analog filter need a sampling frequency at all?
#           3. Why does the freqs function need a sampling frequency at all? I can
#              understand this for freqz, but 's'?

using DSP
using Plots

fs=4*5000e6 #Hz
# 4 GHz cutoff and a 20 GHz sampling freqency! Why 'fs" at all?
# Should there be a HighpassAnalog function?
responsetype = Highpass(4000e6; fs=fs)
# This at least is okay
designmethod = Elliptic(8, 1.0, 40.0)
# We want ANALOG, not digital
fil=analogfilter(responsetype, designmethod)

# Lets try to plot the response
rng=range(100e6, stop=4200e6, length=500)
resp=freqs(fil, rng, fs)
# The x-axis is in GHz
plot(collect(rng)/1e9, 20*log10.((abs.(resp))))
``````

This gives the following plot

while if I scale the x-axis as

``````# The x-axis is in GHz scaled by π
plot(collect(rng)/1e9 * π, 20*log10.((abs.(resp))))
``````

I get (voila!)

which does not make sense at all. However, there is clearly some factor of π missing in the DSP documentation as the cutoff is right where I want it to be in the plot. However I have no idea yet whether the filter is designed correctly.

I think the whole analogfilter design is broken. Please see the comments at the top of the code.

If you use `digitalfilter`, the resulting cutoff frequency is correct at 4 GHz. My opinion is that this is a bug; you should file an issue.

You say

sure you do.
you asked for 40dB stop band ripple and got 40dB stop band ripple.
you asked for 1dB passband ripple, and that looks about like what you got.
the frequency cutoff looks like a radian/hertz problem, but after you accound for that it’s in the right place.

That seems like too strong a statement. The /pi problem definitely seems buggish, and is almost certainly due to radian/hertz confusion, but otherwise it designed an elliptic filter for you and it looks like it met the design parameters.

Agreed – this is what I think is a bug.

I also think the demand for a sampling frequency for a continuous time filter is an interface design issue. Moreover, why should freqs also require an fs parameter for an analog filter?

You are correct that a filter is being designed, and it is elliptical. I wonder if its a problem with the documentation and I just don’t fathom what the parameters mean.

I think this is the reason

You asked for a cutoff at 4GHz but you got a cutoff at (4/Pi) GHz

1 Hz = 2 Pi rads/sec = 1 cycle/sec

(4 / Pi) GHz = (4 * 2 Pi / Pi) rads/sec = (4 / Pi) Cycle /sec

So perhaps the unit of Wn is in “Cycles / sec” and not Hz

1 Like

I have to admit “half-cycles/sample” is not particularly clear, and of course has absolutely no meaning for a continuous time filter.

I’m not even exactly sure what it means in the context of a digital filter.

A good question, why indeed.

Generally speaking the DSP library is very, very good. I did industrial strength work with it a while back and every time i thought i found a problem, the problem was me. lol.

1 Like

This issue is a bug and the detailed discussion with a possible solution is in https://github.com/JuliaDSP/DSP.jl/issues/341

Thanks for the discussions that got me strated down this rabbit hole 2 Likes