Interesting Algorithms

Thread Starter

joeyd999

Joined Jun 6, 2011
6,297
How was the accuracy?
Better than a couple of drifty log amps. In numbers? I don't remember -- it was a long time ago. The precision and noise could be adjusted by the choice of the PDM rate and filter cutoff frequency, and the accuracy by the design and component quality of the PDM front end. So, variable.
 

ZCochran98

Joined Jul 24, 2018
351
I'm a bit younger than most of the contributors to this thread, it seems, but even I have a couple books of tables - not for school mind you (especially because I graduated nearly 5 years ago...), but for my own use and research. Abramowitz' book, Handbook of Mathematical Functions, is a fantastic resource (especially for a lot of those transcendental/non-analytic functions and series equivalents and quickly-converging analysis techniques). Bought it solely for the digamma/polygamma functions and have found other uses since.
Plus the Numerical Recipes book I have (for FORTRAN and BASIC!) is just a neat resource.
 

Thread Starter

joeyd999

Joined Jun 6, 2011
6,297
Better than a couple of drifty log amps. In numbers? I don't remember -- it was a long time ago. The precision and noise could be adjusted by the choice of the PDM rate and filter cutoff frequency, and the accuracy by the design and component quality of the PDM front end. So, variable.
Here's what Grok says:

Yes, there are examples of using pulse density modulation (PDM) in contexts involving the multiplication of analog signals, though direct implementations of PDM-based analog multipliers are niche and often appear in patented or specialized signal-processing designs. PDM itself is primarily a technique for representing analog signals as varying pulse densities in a binary stream (e.g., via delta-sigma modulation), but it can be leveraged in multipliers by generating a PDM stream proportional to one input and using it to scale (multiply) another input's amplitude through selective sampling or gating. Below, I'll outline key examples based on available technical literature and patents.1. Patented PDM Multiplier for Linear Signal Transformation (US6563393B2)
  • Description: This patent describes a pulse density modulator (PDM) unit that performs multiplication as part of converting an N-bit digital input (representing one analog-derived value) into an output PDM signal whose density is a linear function of the product of two inputs. A first PDM generates a binary pulse stream representing a "multiplication factor" (derived from one analog signal). This factor then scales an "offset control value" (from the second analog signal) by selecting and accumulating the value only when the PDM pulse is high. The result is an output PDM stream encoding the product, which can be low-pass filtered back to an analog product signal.
  • How it Works for Analog Signals:
    • Analog input 1 → Quantized to digital → PDM stream (density ∝ input amplitude).
    • Analog input 2 → Converted to offset value.
    • Product: Selective accumulation/gating yields density ∝ (input1 × input2).
    • Analog output: Low-pass filter the PDM product stream.
  • Applications: Avoids multi-bit digital multipliers/accumulators in analog-heavy systems like audio processing or sensor scaling, reducing resolution loss from analog device nonlinearities.
  • Advantages: Simple hardware (no explicit analog multiplier IC needed); scales well for low-power embedded systems.
  • Source: Google Patents (filed 2000, granted 2003).
2. PDM-Controlled Analog Scaling in FPGA-Based Systems
  • Description: In FPGA implementations (e.g., for laser current control or DACs), PDM is used to generate a pulse stream from one analog input, which then multiplicatively scales a second analog reference signal. For instance, a Koheron FPGA design uses a 10-bit PDM modulator to produce a high-frequency (125 MHz) square-wave stream from input signal A. This stream gates or duty-cycles a reference voltage B (from the second analog input), effectively multiplying via average value: output average = A × B. The result is filtered to analog.
  • How it Works for Analog Signals:
    • Analog A → Delta-sigma quantization → PDM bitstream (density = A/max).
    • Analog B → Fixed-height pulses gated by PDM stream.
    • Product: Filtered average ∝ density × height = A × B.
  • Applications: Precision analog control in optics (e.g., laser drivers) or RF, where PWM alternatives cause spectral spikes but PDM provides smoother multiplication.
  • Advantages: High resolution (up to 10+ bits) with minimal FPGA resources; low distortion after filtering.
  • Source: Koheron technical blog (2016); similar in Microchip's PDM DAC docs for analog comparators.
3. Indirect PDM Multiplication via Averaging/Gating in Embedded Audio
  • Description: In multi-mic audio systems (e.g., averaging PDM streams from two MEMS sensors), logical operations like OR-gating on PDM streams from two analog sources effectively multiply if one stream is treated as a scaling factor. A Reddit discussion on embedded systems details OR-ing two PDM bitstreams (each from an analog mic input) to produce an averaged output density ≈ (density1 + density2)/2, but with phase-aligned inputs, it approximates a product if one is low-density (e.g., for gain control: product = input_signal × gain_factor).
  • How it Works for Analog Signals:
    • Analog 1 & 2 → Individual delta-sigma → PDM streams.
    • Gate/OR: Output density ∝ (density1 × density2) for low-duty cases (avoids saturation).
    • Analog product: Low-pass filter (e.g., RC integrator).
  • Applications: Beamforming in smart mics or low-power wattage estimation (voltage × current analogs via PDM).
  • Advantages: No microcontroller needed; passive analog filtering post-gating.
  • Limitations: Approximate for high densities (clipping when both inputs >50%); better for one input as a slow-varying multiplier.
  • Source: r/embedded discussion (2024); aligns with Audio Precision's PDM audio processing notes.
These examples show PDM's utility in multiplication by exploiting pulse density for proportional scaling, often outperforming traditional analog multipliers (e.g., AD633 ICs) in noise shaping and simplicity for oversampled systems. However, PDM-based approaches trade precision for lower power and easier filtering, making them ideal for audio/sensors but less so for high-accuracy RF. If you need circuit diagrams, simulations, or deeper dives into one example, let me know!
 

MrAl

Joined Jun 17, 2014
13,704
My mouth dropped to the floor at 1:58.


Why do I not know some of these simple concepts?
I think he's making it sound like magic or something. It's just math.
For an expression like x^2.4, we can break it down into x^(12/5) and then we can see that we have x^12 and then take the 5th root.
However, that's just one way of looking at it. We can also split it into real and imaginary parts, which gives us two graphs already, and then take the norm of that and we get a third graph.
Which graph we use is what is needed for the given application. In AC circuit analysis, we get the phase angle from the real and imag parts, and the magnitude (amplitude) from the norm.
 

MrAl

Joined Jun 17, 2014
13,704
look a x ^ x, it has a min for x = 0.3679... 1 / e

View attachment 358097
Now that's real magic :)

When I went to school in Massachusetts, I had one instructor that used to call these kinds of things "PFM". When asked what that meant, we would reply: "Pure F...... Magic".
It was funny.

I guess I've always looked at the number 'e' (2.71828....) as being sort of magic because it appears to be so useful in so many areas of physics. I'd say it's at least on par with 'pi' (3.14159...).

x^x can also be broken down into real an imaginary parts. For x positive we can usually find the result, for x negative the result is:
y=i*abs(x)^x*sin(pi*x)+abs(x)^x*cos(pi*x)

with 'i' being the imaginary operator.
If we look at the real part for x negative (the only valid x for that formula), we see a min at x=-0.9105958...
I don't know if that has any significance or not though.
Running x from around -6 to very slightly less than 0 (0 is undefined) we get a curve that looks like an undamped sinusoidal that grows up until x slightly less than 0, for both real and imaginary parts. That may be unexpected because it's just an algebraic expression.
It might be interesting to see what kind of electrical circuit it would take to create that same response. It would have to be a system with positive feedback, and we'd have to shift the time axis. This equivalent may or may not have real life meaning.

A thought kind of way out there...
Since so many things like e^(-t/RC) deflate toward zero but never actually reach zero and this appears in so much physics, maybe the universe really is analog not quantum like we like to believe in this day and age. There could be something forcing everything to look like that because of some other constraints we have yet to discover. Everything everywhere is a negotiation, where things work together, so everything has an influence on everything else. If there are hidden constraints we don't know about, we'd never see them, just the outcomes.
For example mass and spacetime exist under a contract to act in certain ways under the influence of each other. What if there was some way to isolate mass from spacetime, what would it look like and how would it behave. Could it even be isolated, could we even still call it mass.
Just some way-out-there thoughts that may or may not have significance :)
 
Last edited:

WBahn

Joined Mar 31, 2012
32,847
look a x ^ x, it has a min for x = 0.3679... 1 / e

View attachment 358097
On the one hand, it seems really odd, since x^x would seemingly have nothing to do with the value of e.

We can crank through the math to get this result, of course.

The min occurs as x = Xo such that

\(
\frac{d}{dx} \left( x^x \right) \; \bigg\rvert_{x=X_0}\; = \; 0
\)

The easiest way to take the derivative is to convert the base to base e, but we could use any base we choose. Though the fact that base e is the simplest does foreshadow things to come.

\(
y \; = \ x^x \\
ln(y) \; = \; x \cdot ln(x) \\
y = e^{x \cdot ln(x)}
\)

Now we can take the derivative using the rule that

\(
\frac{d}{dx} \left( e^{f(x)} \right) \; = \; e^{f(x)} \cdot \frac{d}{dx}f(x)
\)

where

\(
f(x) \; = \; x \cdot ln(x) \\
\frac{d}{dx}f(x) \; = \; \frac{d}{dx} \left( x \cdot ln(x) \right) \\
\frac{d}{dx}f(x) \; = \; x \cdot \frac{d}{dx} ln(x) \; + \; ln(x) \cdot \frac{d}{dx} x \\
\frac{d}{dx}f(x) \; = \; x \cdot \frac{1}{x} \; + \; ln(x) \cdot 1 \\
\frac{d}{dx}f(x) \; = \; 1 \; + \; ln(x)
\)

This gives us

\(
\frac{d}{dx} \left( x^x \right) \; = \; x^x \cdot \left( 1 \; + \; ln(x) \right) \\
\frac{d}{dx} \left( x^x \right) \; \bigg\rvert_{x=X_0}\; = \; 0 \\
X_0^{X_0} \cdot \left( 1 \; + \; ln(X_0) \right) \; = \; 0
\)

Since x^x is never zero for non-negative real x, that means that the factor in parentheses must be equal to zero.

\(
1 \; + \; ln(X_0) \; = \; 0 \\
ln(X_0) \; = \; -1 \\
e^{ln(X_0)} \; = \; e^{-1} \\
X_0 \; = \; \frac{1}{e}
\)

It might seem like this is coming about because we chose to use e as the base for our logarithms above, but the choice of base is arbitrary and can't affect the final result, so there really is something unique about e at play here.

There are many ways of defining e in math (and all of the other potential definitions then become consequences of it). Many of these seem somehow fundamental in some way, so that fact that they all come out to the same value of e is what is surprising and makes e truly special.

The definition that I always liked, because it seems so, well, natural, is to consider the function

\(
f(x) \; = \; b^x
\)

If we take the derivative, we notice that it is a scaled version of b^x. So what value of b results in the scaling coefficient being exactly 1? It turns out that that's b=e.

From a math or engineering perspective, this is not the most useful definition, but its one that students just getting introduced to calculus can easily grasp.
 

Futurist

Joined Apr 8, 2025
758
On the one hand, it seems really odd, since x^x would seemingly have nothing to do with the value of e.

We can crank through the math to get this result, of course.

The min occurs as x = Xo such that

\(
\frac{d}{dx} \left( x^x \right) \; \bigg\rvert_{x=X_0}\; = \; 0
\)

The easiest way to take the derivative is to convert the base to base e, but we could use any base we choose. Though the fact that base e is the simplest does foreshadow things to come.

\(
y \; = \ x^x \\
ln(y) \; = \; x \cdot ln(x) \\
y = e^{x \cdot ln(x)}
\)

Now we can take the derivative using the rule that

\(
\frac{d}{dx} \left( e^{f(x)} \right) \; = \; e^{f(x)} \cdot \frac{d}{dx}f(x)
\)

where

\(
f(x) \; = \; x \cdot ln(x) \\
\frac{d}{dx}f(x) \; = \; \frac{d}{dx} \left( x \cdot ln(x) \right) \\
\frac{d}{dx}f(x) \; = \; x \cdot \frac{d}{dx} ln(x) \; + \; ln(x) \cdot \frac{d}{dx} x \\
\frac{d}{dx}f(x) \; = \; x \cdot \frac{1}{x} \; + \; ln(x) \cdot 1 \\
\frac{d}{dx}f(x) \; = \; 1 \; + \; ln(x)
\)

This gives us

\(
\frac{d}{dx} \left( x^x \right) \; = \; x^x \cdot \left( 1 \; + \; ln(x) \right) \\
\frac{d}{dx} \left( x^x \right) \; \bigg\rvert_{x=X_0}\; = \; 0 \\
X_0^{X_0} \cdot \left( 1 \; + \; ln(X_0) \right) \; = \; 0
\)

Since x^x is never zero for non-negative real x, that means that the factor in parentheses must be equal to zero.

\(
1 \; + \; ln(X_0) \; = \; 0 \\
ln(X_0) \; = \; -1 \\
e^{ln(X_0)} \; = \; e^{-1} \\
X_0 \; = \; \frac{1}{e}
\)

It might seem like this is coming about because we chose to use e as the base for our logarithms above, but the choice of base is arbitrary and can't affect the final result, so there really is something unique about e at play here.

There are many ways of defining e in math (and all of the other potential definitions then become consequences of it). Many of these seem somehow fundamental in some way, so that fact that they all come out to the same value of e is what is surprising and makes e truly special.

The definition that I always liked, because it seems so, well, natural, is to consider the function

\(
f(x) \; = \; b^x
\)

If we take the derivative, we notice that it is a scaled version of b^x. So what value of b results in the scaling coefficient being exactly 1? It turns out that that's b=e.

From a math or engineering perspective, this is not the most useful definition, but its one that students just getting introduced to calculus can easily grasp.
My math is rusty and gappy these days, so thanks for that analysis, I'll work through it later.

I started reading about tetration yesterday, pretty interesting.
 

Ian0

Joined Aug 7, 2020
13,132
I guess I've always looked at the number 'e' (2.71828....) as being sort of magic because it appears to be so useful in so many areas of physics. I'd say it's at least on par with 'pi' (3.14159...).
And the two are linked together by Euler's equality e^(iπ)=-1
 

MrAl

Joined Jun 17, 2014
13,704
And the two are linked together by Euler's equality e^(iπ)=-1
Yes thanks for mentioning that.

I was thinking of a comparison between 'e' and 'pi' as to how they are used in physics. 'pi' is a little simpler to understand I think.
 

MrAl

Joined Jun 17, 2014
13,704
On the one hand, it seems really odd, since x^x would seemingly have nothing to do with the value of e.

We can crank through the math to get this result, of course.

The min occurs as x = Xo such that

\(
\frac{d}{dx} \left( x^x \right) \; \bigg\rvert_{x=X_0}\; = \; 0
\)

The easiest way to take the derivative is to convert the base to base e, but we could use any base we choose. Though the fact that base e is the simplest does foreshadow things to come.

\(
y \; = \ x^x \\
ln(y) \; = \; x \cdot ln(x) \\
y = e^{x \cdot ln(x)}
\)

Now we can take the derivative using the rule that

\(
\frac{d}{dx} \left( e^{f(x)} \right) \; = \; e^{f(x)} \cdot \frac{d}{dx}f(x)
\)

where

\(
f(x) \; = \; x \cdot ln(x) \\
\frac{d}{dx}f(x) \; = \; \frac{d}{dx} \left( x \cdot ln(x) \right) \\
\frac{d}{dx}f(x) \; = \; x \cdot \frac{d}{dx} ln(x) \; + \; ln(x) \cdot \frac{d}{dx} x \\
\frac{d}{dx}f(x) \; = \; x \cdot \frac{1}{x} \; + \; ln(x) \cdot 1 \\
\frac{d}{dx}f(x) \; = \; 1 \; + \; ln(x)
\)

This gives us

\(
\frac{d}{dx} \left( x^x \right) \; = \; x^x \cdot \left( 1 \; + \; ln(x) \right) \\
\frac{d}{dx} \left( x^x \right) \; \bigg\rvert_{x=X_0}\; = \; 0 \\
X_0^{X_0} \cdot \left( 1 \; + \; ln(X_0) \right) \; = \; 0
\)

Since x^x is never zero for non-negative real x, that means that the factor in parentheses must be equal to zero.

\(
1 \; + \; ln(X_0) \; = \; 0 \\
ln(X_0) \; = \; -1 \\
e^{ln(X_0)} \; = \; e^{-1} \\
X_0 \; = \; \frac{1}{e}
\)

It might seem like this is coming about because we chose to use e as the base for our logarithms above, but the choice of base is arbitrary and can't affect the final result, so there really is something unique about e at play here.

There are many ways of defining e in math (and all of the other potential definitions then become consequences of it). Many of these seem somehow fundamental in some way, so that fact that they all come out to the same value of e is what is surprising and makes e truly special.

The definition that I always liked, because it seems so, well, natural, is to consider the function

\(
f(x) \; = \; b^x
\)

If we take the derivative, we notice that it is a scaled version of b^x. So what value of b results in the scaling coefficient being exactly 1? It turns out that that's b=e.

From a math or engineering perspective, this is not the most useful definition, but its one that students just getting introduced to calculus can easily grasp.
Yes some interesting ways to think about 'e'.

For the curve:
y=1/x
if we find the area under 'y' for x=1 to x=e, the area is equal to 1.

Then there is the limit form:
limit of y as n approaches infinity equals 'e' when y=(1+1/n)^n.
That's used to solve some problems but I can't remember what problems ha ha.
 

Ian0

Joined Aug 7, 2020
13,132
Yes thanks for mentioning that.

I was thinking of a comparison between 'e' and 'pi' as to how they are used in physics. 'pi' is a little simpler to understand I think.
e shows up in equations for diodes, transistors and thermistors - more "semiconductor" or "component" based. π is more "circuit" or "application" based.
Once you have got your long-tailed pair wired up to a common emitter stage and have a complete amplifier you need e less often and π more often!
 

WBahn

Joined Mar 31, 2012
32,847
And the two are linked together by Euler's equality e^(iπ)=-1
I've always seen it slightly differently as

\(
e^{i\pi} \; + \; 1 \; = \; 0
\)

and referred to simply as "the beautiful equation" because it ties five seemingly unrelated mathematical constants, {e, i, π, 1, 0} together is such an elegant and simple way.
 

MrAl

Joined Jun 17, 2014
13,704
e shows up in equations for diodes, transistors and thermistors - more "semiconductor" or "component" based. π is more "circuit" or "application" based.
Once you have got your long-tailed pair wired up to a common emitter stage and have a complete amplifier you need e less often and π more often!
One way I look at it is for electronics 'e' is for time stuff and 'pi' is for frequency stuff.
y=A*e^(-t*a)*sin(2*pi*f*t)
This is natural where 'e' controls the modulation of the sinusoid of frequency f.

'e' also seems to be linked to the transfer of energy. 'pi' linked to its frequency.

I guess there are a lot of epistemic interpretations. I guess I never got around to creating a list and look for some common feature that could shed some light on all of nature.
 

Futurist

Joined Apr 8, 2025
758
The algorithms we invent are often framed by the way we think, the (programming) languages we use, I don't think we actually can think without language, I think Wittgenstein was advocating that.

I suspect my dogs can and do think, they have some understanding (or so it seems) of human language.
 
Last edited:

MrAl

Joined Jun 17, 2014
13,704
The algorithms we invent are often framed by the way we think, the (programming) languages we use, I don't think we actually can think without language, I think Wittgenstein was advocating that.

I suspect my dogs can and do think, they have some understanding (or so it seems) of human language.
Hi,

Yes they understand commands I think in any language not just English.
 
Top