Forum Rule: Always post complete source code & details to reproduce any issue!

# Thread: Ladder filter frequency and resonance control via pots

1. ## Ladder filter frequency and resonance control via pots

Hey all,

Is it possible to control the ladder filters frequency and resonance inputs via pots? If so how would one go about declaring and altering it within a sketch.

2. Use analogRead() to get the pot position and then call the functions to adjust the filter accordingly.

For an example, check out Part 2-7 in the audio library tutorial, which starts on page 19 in the PDF.

https://www.pjrc.com/store/audio_tutorial_kit.html

The code can be opened in Arduino by clicking File > Examples > Audio > Tutorial > Part_2_07_Filters.

While this example covers the normal filter, the process is pretty much the same for any filter or effect, including the ladder filter.

3. Thanks heaps. Muchly appreciated.

4. Originally Posted by PaulStoffregen
Use analogRead() to get the pot position and then call the functions to adjust the filter accordingly.

For an example, check out Part 2-7 in the audio library tutorial, which starts on page 19 in the PDF.

https://www.pjrc.com/store/audio_tutorial_kit.html

The code can be opened in Arduino by clicking File > Examples > Audio > Tutorial > Part_2_07_Filters.

While this example covers the normal filter, the process is pretty much the same for any filter or effect, including the ladder filter.
Would you be able to help me out in trying to understand what this line does in that sketch? Im trying to get my head across all these things so i can troubleshoot if i have problems.

// quick and dirty equation for exp scale frequency adjust
float freq = expf((float)knob / 150.0) * 10.0 + 80.0;

5. It converts linear scale that your potentiometer has to logarithmic frequency scale (how human hearing works), so equal knob movement represents one octave movements say from 100 to 200Hz and 1kHz to 2kHz (for example)

6. Here's a quick way to see what it (or pretty much any equation) really does.

Code:
```  Serial.begin(9600);
while (!Serial) ; // wait for serial monitor to open
for (int knob=0; knob <= 1000; knob += 50) {
Serial.print(knob);
Serial.print(" -> ");
float freq = expf((float)knob / 150.0) * 10.0 + 80.0;
Serial.println(freq);
}
}

void loop() {
}```
If you run this, you'll see this printed in the serial monitor

Code:
```0 -> 90.00
50 -> 93.96
100 -> 99.48
150 -> 107.18
200 -> 117.94
250 -> 132.94
300 -> 153.89
350 -> 183.12
400 -> 223.92
450 -> 280.86
500 -> 360.32
550 -> 471.21
600 -> 625.98
650 -> 841.98
700 -> 1143.43
750 -> 1564.13
800 -> 2151.27
850 -> 2970.69
900 -> 4114.29
950 -> 5710.30
1000 -> 7937.72```

7. Originally Posted by tomas
It converts linear scale that your potentiometer has to logarithmic frequency scale (how human hearing works), so equal knob movement represents one octave movements say from 100 to 200Hz and 1kHz to 2kHz (for example)
Thank you. If i used a log pot instead of linear would i need to use a linear equation?

8. Originally Posted by PaulStoffregen
Here's a quick way to see what it (or pretty much any equation) really does.

Code:
```  Serial.begin(9600);
while (!Serial) ; // wait for serial monitor to open
for (int knob=0; knob <= 1000; knob += 50) {
Serial.print(knob);
Serial.print(" -> ");
float freq = expf((float)knob / 150.0) * 10.0 + 80.0;
Serial.println(freq);
}
}

void loop() {
}```
If you run this, you'll see this printed in the serial monitor

Code:
```0 -> 90.00
50 -> 93.96
100 -> 99.48
150 -> 107.18
200 -> 117.94
250 -> 132.94
300 -> 153.89
350 -> 183.12
400 -> 223.92
450 -> 280.86
500 -> 360.32
550 -> 471.21
600 -> 625.98
650 -> 841.98
700 -> 1143.43
750 -> 1564.13
800 -> 2151.27
850 -> 2970.69
900 -> 4114.29
950 -> 5710.30
1000 -> 7937.72```
That really helped thanks, ill keep that one handy.

9. Originally Posted by DReilly
If i used a log pot instead of linear would i need to use a linear equation?
Maybe a log pot could avoid the need for the equation. But a log or "audio taper" pot is a poor solution for a couple reasons.

1: The ADC resolution is poorly utilized, with just a tiny part of its range to cover all the lower octaves which are most important for human hearing and most of the analog range used for the top few octaves which aren't nearly as important. Half the analog range gets used for the top octave from approx 10kHz to 20kHz, which hardly any people hear well.

2: Most log / audio taper pots are really just piecewise linear, in many cases with just 2 linear regions, maybe 3 in high quality pots. It's a poor approximation compared to the equation.

The equation is practically "free", especially in Teensy 3.5 to 4.1 which have floating point in hardware.

10. Originally Posted by PaulStoffregen
Maybe a log pot could avoid the need for the equation. But a log or "audio taper" pot is a poor solution for a couple reasons.

1: The ADC resolution is poorly utilized, with just a tiny part of its range to cover all the lower octaves which are most important for human hearing and most of the analog range used for the top few octaves which aren't nearly as important. Half the analog range gets used for the top octave from approx 10kHz to 20kHz, which hardly any people hear well.

2: Most log / audio taper pots are really just piecewise linear, in many cases with just 2 linear regions, maybe 3 in high quality pots. It's a poor approximation compared to the equation.

The equation is practically "free", especially in Teensy 3.5 to 4.1 which have floating point in hardware.
Understood, thanks again Paul. Appreciate the help.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•