# Once upon a time Series, Shunt and Ladder attenuator calculator for selectable (ie. ≥ 24, ≤24) steps

#### Hearinspace

Paid Member
Years ago there were online a few resistance value calculators for stepped attenuators with user selectable number of steps with at least one going well above 60 (100?) steps if you put that in.
Does anybody happen to remember any calculators of that sort? Even if there's no longer an active link, if you do remember whose it was there's a chance it could be found in the archive.
Thanks

#### swich401

Are you looking for series, shunt or ladder attenuator calculation?

Paid Member
1 user

#### swich401

For a series stepped attenuator, you can use: https://pynative.com/online-python-code-editor-to-execute-python-code/

And run the following code (input your desired values where it says #example usage):

from math import sqrt, pow, log10

def calculate_attenuator_resistors(num_steps, db_per_step, total_attenuator_impedance):
attenuation_ratio = pow(10, db_per_step / 10)
total_attenuation = pow(attenuation_ratio, num_steps)
resistance_ratio = sqrt(attenuation_ratio)

current_resistor = total_attenuator_impedance / ((1 - resistance_ratio ** num_steps) / (1 - resistance_ratio))

print("Step\tResistor Value (ohms)")

resistor_values = []

for step in range(1, num_steps + 1):
print(f"{step}\t{current_resistor}")
resistor_values.append(current_resistor)
current_resistor *= resistance_ratio

print("Resistor Values:")
for resistor_value in resistor_values:
print(resistor_value)

# Example usage
num_steps = 60
db_per_step = -2
total_attenuator_impedance = 100000

calculate_attenuator_resistors(num_steps, db_per_step, total_attenuator_impedance)

#### Hearinspace

Paid Member
Well , holy smoke , you guys were quick ! Thanks ! ! !
Trying to make the first post as short as I could I deleted the rotary word thinking it wasn't essential in thinking of value calculations. I'd forgotten about relay based circuits.
Nevertheless, now there are other suggestions for relay based attenuators (thanks Mark!) the thread may be more generally useful.

The original reason i asked is because these days 24 steps seems to have become the de facto standard for calculators based on rotary switches, but the best deals at surplus storefronts are often on old overstock custom types from OEM or MIL shelves.
For example, one local place has a bin of 32 position switches with heavily tarnished or dirty contacts but with 5\$ price tag might be worth mixing and matching some of their parts to make up a good working unit. Mulling it over and poking around on the web it's clear most don't consider other than 24 steps a possibility.

. . . . and to answer swich401's first question, . . . . All three.

Thanks

#### Hearinspace

Paid Member
Hi swich401,

After clearing the instruction on line one , I tried to run a direct copy and paste of your code from above but got errors of unexpected indent and expected indent. On following the prompts eventually got to 'attenuation_ratio' is not defined. Haven't tried past that. Does a direct copy and paste work on your machine?

Thanks

#### swich401

The forum keeps removing the indenting from the code. You need to indent the lines like the image shows below (click the start of the line and hit the tab key on your keyboard):

#### Mark Johnson

Paid Member
Include the correctly indented code within a file whose file extension is ".txt" and then include that file within a .zip archive. Post the .zip archive and voila, you have successfully communicated the correct indentations, using the Forum.

1 user

#### Hearinspace

Paid Member
Here's the file. Thanks swich401 and Mark !

#### Attachments

• Python Series Resistor .txt
916 bytes · Views: 81
1 user