<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.2">Jekyll</generator><link href="https://bencholmes.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://bencholmes.github.io/" rel="alternate" type="text/html" /><updated>2023-01-21T17:42:28-08:00</updated><id>https://bencholmes.github.io/feed.xml</id><title type="html">Ben Holmes</title><subtitle>Audio Hardware Engineer</subtitle><author><name>Ben Holmes</name></author><entry><title type="html">Counting the number of colour pages in a PDF</title><link href="https://bencholmes.github.io/posts/2019/03/" rel="alternate" type="text/html" title="Counting the number of colour pages in a PDF" /><published>2019-03-27T00:00:00-07:00</published><updated>2019-03-27T00:00:00-07:00</updated><id>https://bencholmes.github.io/posts/2019/counting-colour-pages-pdf</id><content type="html" xml:base="https://bencholmes.github.io/posts/2019/03/">&lt;p&gt;This is just a little aside from the audio focus of this blog. Recently I completed my thesis for my PhD, which involves a lot of costly printing. Many printers charge one rate for black &amp;amp; white pages, and a separate, much higher rate for colour pages. As a result I wanted to anticipate how much one printing of the thesis would cost and so needed to know:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The number of pages in the thesis&lt;/li&gt;
  &lt;li&gt;How many of these are colour, and&lt;/li&gt;
  &lt;li&gt;How many of these are black &amp;amp; white&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Performing this task on a pdf file was not immediately clear to me. Thankfully this is a well trodden path so the answer was readily available after a bit of searching and compiling, but I am writing it here so that anyone going down the same path doesn’t have to do the same.&lt;/p&gt;

&lt;p&gt;The solution presented here uses a &lt;strong&gt;shell script&lt;/strong&gt;, written for &lt;strong&gt;bash&lt;/strong&gt;. This was run in the &lt;strong&gt;terminal&lt;/strong&gt; on &lt;strong&gt;macOS&lt;/strong&gt; High Sierra, but should be portable for bash terminals. The target document is a &lt;strong&gt;pdf&lt;/strong&gt; as generated by &lt;strong&gt;LaTeX&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The script requires &lt;a href=&quot;https://www.ghostscript.com/&quot;&gt;ghostscript&lt;/a&gt; to analyse the pdf page colour, this should be installed anyway with your LaTeX distribution, and uses &lt;a href=&quot;https://forensicswiki.org/wiki/Pdfinfo&quot;&gt;pdfinfo&lt;/a&gt; so won’t run on Windows unfortunately!&lt;/p&gt;

&lt;h2 id=&quot;full-script&quot;&gt;Full script&lt;/h2&gt;

&lt;p&gt;For those who just want the code, here it is in a github gist:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/bencholmes/3c9279d9f24758a0bbf084eecf836b2d.js&quot;&gt;&lt;/script&gt;

&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;

&lt;p&gt;I wanted to design a shell script which I could call with a single argument, the file name, and receive the total number of pages and the number of colour/black &amp;amp; white pages. To do this I made a file called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count_colour_pages.sh&lt;/code&gt; in which I wrote the shell script. This file needs to be on your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$PATH&lt;/code&gt; to ensure you can call it anywhere in your file system.&lt;/p&gt;

&lt;p&gt;The output is then three lines in the terminal reporting the desired properties of the pdf document.&lt;/p&gt;

&lt;p&gt;An example:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iMac: thesis-latex$ count_colour_pages.sh main.pdf
Number of pages:    213
Number of b&amp;amp;w:      141
Number of colour:   72
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main.pdf&lt;/code&gt; is my compiled LaTeX document. Despite the ridiculous length of theses, only around 1/3rd of this one has any colour on the page, which saved me a bunch when printing.&lt;/p&gt;</content><author><name>Ben Holmes</name></author><category term="bash" /><category term="script" /><category term="LaTeX" /><category term="research-tools" /><summary type="html">This is just a little aside from the audio focus of this blog. Recently I completed my thesis for my PhD, which involves a lot of costly printing. Many printers charge one rate for black &amp;amp; white pages, and a separate, much higher rate for colour pages. As a result I wanted to anticipate how much one printing of the thesis would cost and so needed to know:</summary></entry><entry><title type="html">Measurement Gotchas: systematic error when averaging</title><link href="https://bencholmes.github.io/posts/2018/04/measurement-gotchas-averaging" rel="alternate" type="text/html" title="Measurement Gotchas: systematic error when averaging" /><published>2018-04-06T00:00:00-07:00</published><updated>2018-04-06T00:00:00-07:00</updated><id>https://bencholmes.github.io/posts/2018/04/measurement-gotchas-averaging</id><content type="html" xml:base="https://bencholmes.github.io/posts/2018/04/measurement-gotchas-averaging">&lt;p&gt;When trying to capture a clean signal from an electronic circuit, a popular strategy is to use averaging. The circuit is driven by the same signal repeatedly creating a set of output signals which can then be averaged, thus reducing noise. I’ve used this technique a lot in the measurement step of my work on training physical models on measured data (see &lt;a href=&quot;http://benholmes.co.uk/publication/2015-12-01-Physical%20model%20parameter%20optimisation&quot;&gt;my DAFx-16 paper&lt;/a&gt; for more information).&lt;/p&gt;

&lt;p&gt;One factor that is important to remember during the averaging process is the transient response of the circuit. If the circuit features large valued energy storing components, the transient response can feature long decay times. If the decay time is significant when compared to the length of the signal then the next time you take an average it can be skewed by the previous repeat.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/rc-circuit.png&quot; width=&quot;30%&quot; alt=&quot;RC circuit&quot; align=&quot;middle&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s say we’re trying to model the pictured RC circuit. To do this we drive the circuit with a wide-band signal and compare the measurements to a model and see how good the fit is. The time constant of the circuit is given by&lt;/p&gt;

\[\tau = RC = 5\ \mathrm{k\Omega} \times 1\ \mathrm{\mu F} = 5\ \mathrm{ms}\]

&lt;p&gt;Driving this circuit with a 10ms windowed multi-sine signal consisting of integer multiples of 100 Hz from 1 to 10, the result is the following:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/rc-averaging-error.png&quot; alt=&quot;RC averaging error&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The match between the model and the measurement in the first period is close. However in the second period there is a large discrepancy caused by the overlap of the transient decay from the previous period. If we were to try and fit the model to the average of the two periods, it would appear that there is something significantly wrong with the model!&lt;/p&gt;

&lt;p&gt;By zero-padding the end of the signal, the transient decay can be mitigated:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/rc-averaging-error-lengthened.png&quot; alt=&quot;RC reduced error&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The input signal has had 30 ms of zero-padding added to it and there is still some error in the start of the signal. Adding 30 ms of zero-padding has however increased the measurement length by a factor of 4. Depending on the number of averages required, this can cause problems not only with the duration of the measurements, but also with the amount of data recorded.&lt;/p&gt;

&lt;p&gt;Fortunately this issues is easy to identify if you are aware of it, so the next time you’re averaging a measurement and you see a deviation from the expected starting values of your measurement, try inspecting the first period of your signal to see if the error is present there first.&lt;/p&gt;</content><author><name>Ben Holmes</name></author><category term="measurements" /><category term="modelling" /><category term="sys-id" /><summary type="html">When trying to capture a clean signal from an electronic circuit, a popular strategy is to use averaging. The circuit is driven by the same signal repeatedly creating a set of output signals which can then be averaged, thus reducing noise. I’ve used this technique a lot in the measurement step of my work on training physical models on measured data (see my DAFx-16 paper for more information).</summary></entry><entry><title type="html">Plotting the FFT of a voltage signal</title><link href="https://bencholmes.github.io/posts/2018/05/plotting-voltage-fft" rel="alternate" type="text/html" title="Plotting the FFT of a voltage signal" /><published>2018-04-06T00:00:00-07:00</published><updated>2018-04-06T00:00:00-07:00</updated><id>https://bencholmes.github.io/posts/2018/05/plotting-voltage-fft</id><content type="html" xml:base="https://bencholmes.github.io/posts/2018/05/plotting-voltage-fft">&lt;p&gt;Plotting a signal in the frequency domain is a fundamental analysis tool which can provide great insight into the signal’s behaviour. Something I have struggled with in the past is getting the units correct such that the amplitude response of the frequency-domain representation has physical significance. In this blog post I aim to outline how to properly find useful units with which to represent voltage signals.&lt;/p&gt;

&lt;h2 id=&quot;testcase&quot;&gt;Testcase&lt;/h2&gt;

&lt;p&gt;To illustrate the methods in this post, a voltage signal of two sine waves and a DC offset will be used:&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Component&lt;/td&gt;
      &lt;td&gt;Frequency (Hz)&lt;/td&gt;
      &lt;td&gt;Peak Voltage (V)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;0.1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;50&lt;/td&gt;
      &lt;td&gt;0.01&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;100&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/images/voltagefft/td-example.png&quot; alt=&quot;Voltage time domain signal&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The objective is now to provide a method of illustration that enables quick determination of the frequency components in the summed signal and their respective levels.&lt;/p&gt;

&lt;h2 id=&quot;the-dft&quot;&gt;The DFT&lt;/h2&gt;

&lt;p&gt;The DFT or Discrete Fourier Transform converts a discrete time-domain signal into a discrete frequency-domain signal. One notable algorithm for calculating the DFT is the the &lt;a href=&quot;https://en.wikipedia.org/wiki/Fast_Fourier_transform&quot;&gt;Fast Fourier Transform or FFT&lt;/a&gt; which utilises the symmetry of the DFT to optimise performance, and is typically the algorithm implemented by numerical software packages e.g. MATLAB. The DFT algorithm is given by&lt;/p&gt;

\[\bar{V}(m) = \sum_{n=0}^{N-1}v(n) \cdot \mathrm{e}^{\frac{-2\pi j}{N} m\cdot n},\quad m=0,\ldots,N-1,\]

&lt;p&gt;where \(\bar{V}\) is the DFT of the discrete time domain signal \(v\), each of length \(N\). Immediately there has been a change of units in attempting to find the frequency domain representation: the DFT calculates the sum over the whole length of the signal as opposed to the instantaneous value. This is equivalent to a change from power to energy. Correction is achieved by normalising by the length of the signals i.e.&lt;/p&gt;

\[V = \frac{1}{N} \bar{V},\]

&lt;p&gt;where \(V\) now is the frequency domain representation of the voltage signal. This is a gotcha which got me as the scaling isn’t included in the implementation in most maths software (specifically MATLAB).&lt;/p&gt;

&lt;p&gt;Now, finding the magnitude \(\lvert V \rvert\) already provides a physically significant representation, the results are in the same units as the original signal:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/voltagefft/fd-notdb.png&quot; alt=&quot;Voltage frequency domain without any scaling&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Inspecting the DFT of the signal sampled at \(F_\mathrm{s} = \)500 Hz, the DC component is correct at 0.1 V, although the 100 Hz component is at half the amplitude it should be. This is because the amplitude is split into the bins between 0 Hz - \(F_\mathrm{s}/2\) and \(F_\mathrm{s}/2\) - \(F_\mathrm{s}\) due to the symmetry of the DFT. It is therefore necessary to scale all of the bins that are not DC by a factor of 2:&lt;/p&gt;

\[V(m) = \frac{k(m)}{N} \bar{V(m)},\quad\mathrm{where}\quad
k(m) =
\begin{cases}
2, &amp;amp; m \neq 0\\
1, &amp;amp; m=0
\end{cases}
,\quad m=0,\ldots,N-1.\]

&lt;p&gt;This yields an accurate representation of the signal in the frequency domain. We can do better however as it is difficult to determine the amplitude of the 50 Hz component. This can be solved with…&lt;/p&gt;

&lt;h2 id=&quot;decibels&quot;&gt;Decibels&lt;/h2&gt;

&lt;p&gt;Decibels provide a method of scaling data that is over a large range of values such that it can be read easily, and often helps illustrate trends in data that are otherwise unclear. It is useful here as very small voltages often coincide with very large voltages (typically signals vs noise).&lt;/p&gt;

&lt;p&gt;A logarithmic scaling similar to converting to decibels can be achieved using&lt;/p&gt;

\[10 \cdot \text{log}_{10}(\lvert V \rvert).\]

&lt;p&gt;where the results will now be scaled such that a signal that had a 10 V peak now is at 2 i.e. \(10 \cdot \text{log}_{10}(\lvert 1\times10^2 \rvert) = 2 \), and so a 0.01 V peak is at -2. The exponent in scientific notation is captured in the new value. To present the new data the old values can simply be used as axis labels, and just utilise the new scaling. Most software for plotting encompass a logarithmic plotting option which captures this and displays with the original units, for example with MATLAB and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;semilogy()&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/voltagefft/fd-db.png&quot; alt=&quot;Frequency domain with logarithmic scaling&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now the amplitudes are much easier to distinguish over a larger range (the labels help too!).&lt;/p&gt;</content><author><name>Ben Holmes</name></author><category term="measurements" /><category term="MATLAB" /><summary type="html">Plotting a signal in the frequency domain is a fundamental analysis tool which can provide great insight into the signal’s behaviour. Something I have struggled with in the past is getting the units correct such that the amplitude response of the frequency-domain representation has physical significance. In this blog post I aim to outline how to properly find useful units with which to represent voltage signals.</summary></entry><entry><title type="html">Component meters: DE-5000 and M328</title><link href="https://bencholmes.github.io/posts/2018/02/component-meters" rel="alternate" type="text/html" title="Component meters: DE-5000 and M328" /><published>2018-02-18T00:00:00-08:00</published><updated>2018-02-18T00:00:00-08:00</updated><id>https://bencholmes.github.io/posts/2018/02/component-meters</id><content type="html" xml:base="https://bencholmes.github.io/posts/2018/02/component-meters">&lt;p&gt;Recently I’ve been in need of measuring linear component values to a high degree of accuracy, so decided to purchase a couple of component meters. The first of these is the M328 “transistor tester”, which is a favourite of the DIY community as it is cheap and has all of the plans available on the internet. I put transistor tester in quotes as the meter is designed to measure resistance, capacitance, inductance, transistor type and basic characteristics, and even some parasitic properties. This is quite an impressive boast for a product which I purchased for £6.32!&lt;/p&gt;

&lt;p&gt;The only problem with this is that it does not satisfy the need of precision and accuracy. To accomplish this, I purchased a dedicated LCR meter, the DER EE DE-5000. This LCR meter appears to have been designed to rip off the IET Labs DE-5000, and sell at a fraction of the price. A &lt;a href=&quot;http://www.eevblog.com/forum/testgear/der-ee-de-5000-unboxing-and-teardown/&quot;&gt;teardown at the EEVblog forum&lt;/a&gt; shows that the equipment, while being budget, is of decent quality.&lt;/p&gt;

&lt;h2 id=&quot;quick-specs&quot;&gt;Quick specs&lt;/h2&gt;

&lt;h3 id=&quot;m328&quot;&gt;M328&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Price: £6.38&lt;/li&gt;
  &lt;li&gt;Power supply: 9 V battery&lt;/li&gt;
  &lt;li&gt;Measures:
    &lt;ul&gt;
      &lt;li&gt;Resistance&lt;/li&gt;
      &lt;li&gt;Capacitance&lt;/li&gt;
      &lt;li&gt;Inductance&lt;/li&gt;
      &lt;li&gt;hFE and Uf of BJTs&lt;/li&gt;
      &lt;li&gt;Many other factors&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/files/Ttester_english.pdf&quot;&gt;Manual&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://hackaday.com/2015/04/24/review-transistor-tester/&quot;&gt;Hackaday Review&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;de-5000&quot;&gt;DE-5000&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Price: £80&lt;/li&gt;
  &lt;li&gt;Power supply: 9 V battery or external PSU&lt;/li&gt;
  &lt;li&gt;Measures:
    &lt;ul&gt;
      &lt;li&gt;Resistance&lt;/li&gt;
      &lt;li&gt;Capacitance&lt;/li&gt;
      &lt;li&gt;Inductance&lt;/li&gt;
      &lt;li&gt;Secondary factors including ESR, dissipation and quality.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/files/DE-5000_manual_english.pdf&quot;&gt;Manual&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=sYRxi3BmS_U&quot;&gt;Youtube review&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;meter-operation&quot;&gt;Meter operation&lt;/h2&gt;

&lt;p&gt;To illustrate the performance of both meters I have uploaded videos demonstrating how they perform when measuring a 1 MΩ potentiometer.&lt;/p&gt;

&lt;h3 id=&quot;m328-1&quot;&gt;M328&lt;/h3&gt;
&lt;video width=&quot;400&quot; height=&quot;280&quot; controls=&quot;&quot;&gt;
 &lt;source src=&quot;/images/MTester.mp4&quot; type=&quot;video/mp4&quot; /&gt;
Your browser does not support the video tag.
&lt;/video&gt;

&lt;p&gt;What is really useful about the M328 is that it has three connections, enabling it to measure the minimum resistance of the potentiometer, here measured to be 0.2 Ω.&lt;/p&gt;

&lt;h3 id=&quot;de-5000-1&quot;&gt;DE-5000&lt;/h3&gt;
&lt;video width=&quot;320&quot; height=&quot;560&quot; controls=&quot;&quot;&gt;
 &lt;source src=&quot;/images/DE-5000.mp4&quot; type=&quot;video/mp4&quot; /&gt;
Your browser does not support the video tag.
&lt;/video&gt;

&lt;p&gt;Obviously the dedicated LCR meter that costs over 10x the price offers better precision with the resistance measurement, however the measured values seem pretty close!&lt;/p&gt;

&lt;h2 id=&quot;gutshots&quot;&gt;Gutshots&lt;/h2&gt;

&lt;p&gt;I had to disassemble the DE-5000 due to the meter indicating a short at all times. This actually turned out to be a calibration issue that was fixed by simply recalibrating. This did help in two ways however: calibration holds even when powered down so that recalibrating isn’t necessary each use, and I took some shots of the inside of the meter.
&lt;img src=&quot;https://i.imgur.com/CrPVbRg.jpg&quot; alt=&quot;Component-side DE-5000&quot; /&gt;
&lt;img src=&quot;https://i.imgur.com/cHPD5DT.jpg&quot; alt=&quot;Button/screen-side DE-5000&quot; /&gt;&lt;/p&gt;</content><author><name>Ben Holmes</name></author><category term="equipment" /><category term="testgear" /><category term="measurements" /><category term="de-5000" /><category term="M328" /><summary type="html">Recently I’ve been in need of measuring linear component values to a high degree of accuracy, so decided to purchase a couple of component meters. The first of these is the M328 “transistor tester”, which is a favourite of the DIY community as it is cheap and has all of the plans available on the internet. I put transistor tester in quotes as the meter is designed to measure resistance, capacitance, inductance, transistor type and basic characteristics, and even some parasitic properties. This is quite an impressive boast for a product which I purchased for £6.32!</summary></entry><entry><title type="html">Modelling logarithmic potentiometer laws</title><link href="https://bencholmes.github.io/posts/2017/11/logarithmic-potentiometer-laws" rel="alternate" type="text/html" title="Modelling logarithmic potentiometer laws" /><published>2017-11-22T00:00:00-08:00</published><updated>2017-11-22T00:00:00-08:00</updated><id>https://bencholmes.github.io/posts/2017/11/logarithmic-potentiometer-laws</id><content type="html" xml:base="https://bencholmes.github.io/posts/2017/11/logarithmic-potentiometer-laws">&lt;p&gt;This post presents a general logarithmic potentiometer law with a curve fit to enable a user to choose a curve that sounds good in their application. The law is computationally expensive as it involves an exponent but is good in terms of flexibility.&lt;/p&gt;

&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;

&lt;p&gt;Recently I have been looking at circuits with potentiometers. They are everywhere in synthesisers, guitar pedals, etc. and used for controlling aspects of circuit behaviour by changing two resistances between three points.&lt;/p&gt;

&lt;p&gt;Potentiometers (pots for short) come in a few flavours: linear, logarithmic, and anti-log. This name defines how the resistance changes with respect to the position of the wiper along the track of the pot. A linear pot means that the primary resistance is proportional to the wiper position, while the secondary resistance is the remaining resistance.&lt;/p&gt;

\[R_\mathrm{tot} = R_1 + R_2,\quad R_1 = \alpha R_\mathrm{tot},\quad R_2 = (1-\alpha)R_\mathrm{tot}\]

&lt;p&gt;In this formulation, \(0 \leq \alpha \leq 1 \).&lt;/p&gt;

&lt;p&gt;Whereas a linear potentiometer can be seen as straight, the remaining potentiometer laws are curvy. A curved mapping is useful for when controlling things such as volume, where our perception fits closely to a curve. The definition of the exact curve of a potentiometer is difficult to pin down as they differ with manufacturer and also price. For use in simulation, we can define a set of curves that a user can choose from for their needs.&lt;/p&gt;

&lt;h2 id=&quot;logarithmic-general-form&quot;&gt;Logarithmic general form&lt;/h2&gt;

&lt;p&gt;The general form of the curve is given by&lt;/p&gt;

\[y = a\ b^x + c\]

&lt;p&gt;where \(x\) is the wiper position, \(y\) is the primary resistance, and \(a\), \(b\) and \(c\) are free parameters for curve fitting.&lt;/p&gt;

&lt;p&gt;This mapping is applied prior to calculating resistances, so will effectively map \(x\) to \(\alpha\), i.e. \(y=\alpha\). For this reason it can be assumed that the limits of both \(x\) and \(y\) are zero and one. To fit this curve we then have two equations, when both \(x\) and \(y\) are 0:&lt;/p&gt;

\[0 = a + c,\quad c = -a\]

&lt;p&gt;And therefore we are given a simpler equation with only two parameters:&lt;/p&gt;

\[y = a\ b^x - a\]

&lt;p&gt;Constraining with our second set of points:&lt;/p&gt;

\[1 = ab - a,\quad \frac{1}{b-1} = a\]

&lt;p&gt;There is still one equation left to determine the parameter values. I find it useful to map this as a mid-point of the curve, for example saying that when the wiper is at half way I want the resistance to be at 10% of the total. This can be parameterised again so that we can change the midpoint, saying \(x = 0.5\), \(y = y_m\). This gives our final constraint&lt;/p&gt;

\[y_m = a(\sqrt{b} - 1),\quad y_m = \frac{\sqrt{b} - 1}{b-1},\quad b = \left(\frac{1}{y_m} - 1\right)^2\]

&lt;h2 id=&quot;results&quot;&gt;Results&lt;/h2&gt;

&lt;p&gt;By setting the value for \(y_m\) we can create a variety of mappings:&lt;/p&gt;

&lt;div&gt;
    &lt;a href=&quot;https://plot.ly/~benholmes/4/?share_key=8cPOlabSsDaHuJ2drdG1CG&quot; target=&quot;_blank&quot; title=&quot;log-pot&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;img src=&quot;https://plot.ly/~benholmes/4.png?share_key=8cPOlabSsDaHuJ2drdG1CG&quot; alt=&quot;log-pot&quot; style=&quot;max-width: 100%;width: 600px;&quot; width=&quot;600&quot; onerror=&quot;this.onerror=null;this.src='https://plot.ly/404.png';&quot; /&gt;&lt;/a&gt;
    &lt;script data-plotly=&quot;benholmes:4&quot; sharekey-plotly=&quot;8cPOlabSsDaHuJ2drdG1CG&quot; src=&quot;https://plot.ly/embed.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;
&lt;/div&gt;

&lt;p&gt;Note that when setting \(y_m = 0.5\) that \(a = \infty\)! But for this value we can just use a linear map so no need to waste the computation time for the exponent.&lt;/p&gt;

&lt;p&gt;Choosing for example \(y_m = 0.15\) will give quite a good approximation of a log pot, though I say this without measurements or further evidence. For an anti-log pot one could select a value around \(0.85\).&lt;/p&gt;

&lt;p&gt;If you’re interested in further playing around with this, here is the MATLAB gist (although it should be fairly compatible to Octave, and also self-explanatory if you want to port it):&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/bencholmes/87ceeaee702ec0dc1d0426283d2ae2f6.js&quot;&gt;&lt;/script&gt;</content><author><name>Ben Holmes</name></author><category term="curve fitting" /><category term="circuit modelling" /><category term="optimisation" /><category term="micro-research" /><category term="electronics" /><summary type="html">This post presents a general logarithmic potentiometer law with a curve fit to enable a user to choose a curve that sounds good in their application. The law is computationally expensive as it involves an exponent but is good in terms of flexibility.</summary></entry><entry><title type="html">Mathjax Test</title><link href="https://bencholmes.github.io/posts/2017/11/Mathjax-test" rel="alternate" type="text/html" title="Mathjax Test" /><published>2017-11-07T00:00:00-08:00</published><updated>2017-11-07T00:00:00-08:00</updated><id>https://bencholmes.github.io/posts/2017/11/mathjax-test</id><content type="html" xml:base="https://bencholmes.github.io/posts/2017/11/Mathjax-test">&lt;p&gt;This is a test page to see if Mathjax is working. \(\pi\)&lt;/p&gt;

\[P(E) = {n \choose k} p^k (1-p)^{ n-k}\]</content><author><name>Ben Holmes</name></author><category term="test-post" /><category term="maths" /><summary type="html">This is a test page to see if Mathjax is working. \(\pi\)</summary></entry></feed>