summaryrefslogtreecommitdiffstats
path: root/volume_pot
diff options
context:
space:
mode:
authorJames McKenzie <root@ka-ata-killa.panaceas.james.local>2025-08-30 14:14:05 +0100
committerJames McKenzie <root@ka-ata-killa.panaceas.james.local>2025-08-30 14:14:05 +0100
commite7111e23a23ddec941b5ebca0a3ce40f4948d69d (patch)
treee3dc908e016c2af66600009c6097cfef94b06217 /volume_pot
parentfbeff397441f1fa681157293501e6bff6c68eb25 (diff)
downloadvictoria-001-e7111e23a23ddec941b5ebca0a3ce40f4948d69d.tar.gz
victoria-001-e7111e23a23ddec941b5ebca0a3ce40f4948d69d.tar.bz2
victoria-001-e7111e23a23ddec941b5ebca0a3ce40f4948d69d.zip
plot frequency responses better
Diffstat (limited to 'volume_pot')
-rwxr-xr-xvolume_pot/volume.pl109
1 files changed, 59 insertions, 50 deletions
diff --git a/volume_pot/volume.pl b/volume_pot/volume.pl
index 07d7d49..3dc0cd3 100755
--- a/volume_pot/volume.pl
+++ b/volume_pot/volume.pl
@@ -35,88 +35,97 @@ sub par($$) {
@fns = ();
@frqs = ();
-$rac = 470000.;
+# calc gain for taps at te,td frequeny f and knob position k (0-10)
-$te = 0.20; # terminal e
-$td = 0.66; # terminal d
+sub calc_gain($$) {
+ my ( $f, $k ) = @_;
+
+ my $te = 0.4; # terminal e
+ my $td = 0.6; # terminal d
+
+ my $rac = 470000.;
-for ( $f = 20. ; $f < 20010. ; $f = $f * sqrt(10.) ) {
- #
#terminal c is input
#terminal b is output
#terminal a is ground
- $cnf = -i * ( 1. / ( 0.000000001 * 2 * pi * $f ) );
+ my $cnf = -i * ( 1. / ( 0.000000001 * 2 * pi * $f ) );
- $ld = 18000. + ( ( 1. / 47. ) * $cnf ); #18k+47nF
- $le = 4700. + ( ( 1. / 250. ) * $cnf ); #4.7k+250nF
+ # loads on terminals d and e
+ my $ld = 18000. + ( ( 1. / 47. ) * $cnf ); #18k+47nF
+ my $le = 4700. + ( ( 1. / 250. ) * $cnf ); #4.7k+250nF
#compute resistances of track
+ my $rae = $rac * logpot($te);
+ my $rad = $rac * logpot($td);
- $rae = $rac * logpot($te);
- $rad = $rac * logpot($td);
-
- $red = $rad - $rae;
+ my $red = $rad - $rae;
- $rdc = $rac - $rad;
+ my $rdc = $rac - $rad;
- $tot = $rae + $red + $rdc;
+ my $tot = $rae + $red + $rdc;
print "Track resistances: $rae + $red + $rdc = $tot\n";
- # next compute the efective resistances of each leg at HF
+ # next compute the efective impedances of each leg
- $erae = par( $rae, $le );
- $erad = par( $erae + $red, $ld );
- $ered = $erad - $erae;
- $erac = $erad + $rdc;
- $erdc = $erac - $erad;
+ my $erae = par( $rae, $le );
+ my $erad = par( $erae + $red, $ld );
+ my $ered = $erad - $erae;
+ my $erac = $erad + $rdc;
+ my $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;
+ # compute the potentials for a 1V input
- $fn = sprintf( "volume-%d.dat", int( $f + .1 ) );
- push @fns, $fn;
- push @frqs, int( $f + .1 ) . " Hz";
-
- open F, ">", $fn;
+ my $pe = $erae / $erac;
+ my $pd = $erad / $erac;
+ my $ped = $pd - $pe;
+ my $pda = 1 - $pd;
- for ( my $v = 0.01 ; $v < 1 ; $v += 0.01 ) {
+ my $v = $k / 10.;
+ my $hf;
- $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, " ", abs($hf), " ", $lf, "\n";
+ 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. ) );
}
- close F;
+ return abs($hf);
}
open P, "|gnuplot";
print P "set term png size 1280,1024\n";
print P "set output 'volume.png'\n";
+print P "set logscale x\n";
print P "set logscale y\n";
-print P "set xlabel 'knob position'\n";
+print P "set yrange [:1.1]\n";
+print P "set xlabel 'frequency/Hz'\n";
print P "set ylabel 'gain'\n";
print P "plot ";
-for $i ( 0 .. $#fns ) {
- print P " '"
- . $fns[$i]
- . "' using 1:2 with lines title '"
- . $frqs[$i] . "',";
+
+for ( my $k = 1 ; $k < 10.5 ; ++$k ) {
+ my $gmax = 0;
+ for ( my $f = 20 ; $f < 20000.1 ; $f *= 1.1 ) {
+ my $g = calc_gain( $f, $k );
+ $gmax = $g if $g > $gmax;
+ }
+ my $fn = "volume-" . $k . ".dat";
+ open F, ">", $fn;
+ for ( my $f = 20 ; $f < 20000.1 ; $f *= 1.1 ) {
+ my $g = calc_gain( $f, $k );
+ print F $f, " ", $g, " ", $g / $gmax, "\n";
+ }
+ close F;
+
+ print P " '" . $fn . "' using 1:2 with lines title '" . $k . "',";
+
}
print "\n";
close P;