summaryrefslogtreecommitdiffstats
path: root/volume_pot
diff options
context:
space:
mode:
authorJames McKenzie <root@ka-ata-killa.panaceas.james.local>2025-08-30 13:32:52 +0100
committerJames McKenzie <root@ka-ata-killa.panaceas.james.local>2025-08-30 13:32:52 +0100
commit4747c3081e71eb760045a0e7702ffb4396e334ec (patch)
treed75380575c18683a0ebbc77a90055285a84c3430 /volume_pot
parent7c5191c539539d43f1628515a5ab866190b0ca7f (diff)
downloadvictoria-001-4747c3081e71eb760045a0e7702ffb4396e334ec.tar.gz
victoria-001-4747c3081e71eb760045a0e7702ffb4396e334ec.tar.bz2
victoria-001-4747c3081e71eb760045a0e7702ffb4396e334ec.zip
better volume code
Diffstat (limited to 'volume_pot')
-rwxr-xr-xvolume_pot/volume.pl100
1 files changed, 100 insertions, 0 deletions
diff --git a/volume_pot/volume.pl b/volume_pot/volume.pl
new file mode 100755
index 0000000..d6ced7c
--- /dev/null
+++ b/volume_pot/volume.pl
@@ -0,0 +1,100 @@
+#!/usr/bin/env perl
+
+sub logpot($) {
+ my $x = shift;
+
+ my $ym = 0.2;
+
+ my $b = ( ( 1. / $ym ) - 1. );
+ $b = $b * $b;
+
+ my $a = 1. / ( $b - 1. );
+
+ return $a * ( $b**$x ) - $a;
+}
+
+sub logprop($$$) {
+ my ( $v, $t1, $t2 ) = @_;
+
+ $v = logpot($v);
+ $t1 = logpot($t1);
+ $t2 = logpot($t2);
+
+ return ( $v - $t1 ) / ( $t2 - $t1 );
+}
+
+sub par($$) {
+ my ( $a, $b ) = @_;
+
+ return 1. / ( ( 1. / $a ) + ( 1. / $b ) );
+}
+
+#terminal c is input
+#terminal b is output
+#terminal a is ground
+
+$te = 0.20; # terminal e
+$td = 0.66; # terminal d
+
+$ld = 18.; #18k+47nF
+$le = 4.7; #4.7k+250nF
+
+#compute resistances of track
+
+$rac = 470.;
+$rae = $rac * logpot($te);
+$rad = $rac * logpot($td);
+
+$red = $rad - $rae;
+
+$rdc = $rac - $rad;
+
+$tot = $rae + $red + $rdc;
+
+print "Track resistances: $rae + $red + $rdc = $tot\n";
+
+# next compute the efective resistances of each leg at HF
+
+$erae = par( $rae, $le );
+$erad = par( $erae + $red, $ld );
+$ered = $erad - $erae;
+$erac = $erad + $rdc;
+$erdc = $erac - $erad;
+
+print "Effective total HF resistance: $erae + $ered + $erdc = $erac\n";
+
+$pe = $erae / $erac;
+$pd = $erad / $erac;
+$ped = $pd - $pe;
+$pda = 1 - $pd;
+
+open F, ">volume.dat";
+
+for ( my $v = 0.01 ; $v < 1 ; $v += 0.01 ) {
+
+ $lf = logpot($v);
+
+ if ( $v < $te ) {
+ $hf = $pe * logprop( $v, 0, $te );
+ }
+ elsif ( $v < $td ) {
+ $hf = $pe + ( $ped * logprop( $v, $te, $td ) );
+ }
+ else {
+ $hf = $pd + ( $pda * logprop( $v, $td, 1. ) );
+ }
+
+ print F 10. * $v, " ", $hf, " ", $lf, "\n";
+}
+
+close F;
+
+open P, "|gnuplot";
+print P "set term png size 1280,1024\n";
+print P "set output 'volume.png'\n";
+print P "set logscale y\n";
+print P "set xlabel 'knob position'\n";
+print P "set ylabel 'gain'\n";
+print P "plot 'volume.dat' using 1:2 with lines title 'high frequency',";
+print P "'volume.dat' using 1:3 with lines title 'low frequency'\n";
+close P;