# Reconstructing band-limited signal's integral from discrete samples [closed]

I'm thinking about building an e-bike consumed power meter.

I'm planning on sampling a low-pass filtered current sensing and voltage analog signals on the battery to e-bike controller connection, then somehow digitally integrating the product of these 2 (instantaneous power) to get the consumed power.

I could over-sample say by 10 or 20X of the analog bandwidth and then use a simple sum of areas of the trapezoids to get a reasonably accurate integral (consumed power).

But I'm thinking maybe there's a relatively simple DSP technique to get the integral without such significant oversampling that can be implemented in an FPGA? (e.g. to get a 5% accuracy with sampling at 3x of the analog bandwidth)

Some digital low-pass filter and then the same sum of trapezoid areas on the result?

## closed as off-topic by A_A, MBaz, lennon310, Matt L., Stanley PawlukiewiczJan 12 at 15:07

• This question does not appear to be about signal processing within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• I'm not sure if this is an appropriate question here, I'm a complete noob here. If it's too complicated / broad of a topic then I'd just delete the question and go with oversampling. – axk Jan 8 at 21:55
• I'm planning to do the multiplication and integration digitally, but to get more or less accurate result with a simple sum of products I would need to over-sample significantly, I thought that I could avoid the oversampling by employing a DSP technique to reconstruct the integral with good accuracy. – axk Jan 8 at 22:34
• I don't understand why you are considering over-sampling. I would guess that the current / voltage of the e-bike motor does not change faster than maybe 10-20 times per second. In cruise control conditions for example, the demand depends on the variation of the terrain. In "free-hand" mode, changes would be fast if the e-bike is in some form of racing. So, do your integration in hardware, with simple (possibly active) integrators and then do a simple acquisition and display in digital form. Except if I got the whole thing wrong and you are trying to do something more than that (?). – A_A Jan 9 at 9:31
• I'm voting to close this question as off-topic because at the time of review, its content is not directly related to DSP and it might have better chances of receiving a practical answer in the electronics related SE. – A_A Jan 9 at 9:34
• I thought how you process digital samples after your acquired them (which is EE) is DSP but I see your point that this site is more academic. – axk Jan 11 at 15:26

Let me rephrase what you want to do as:

I want to approximately calculate the integral of the product of two non-negative discrete-time signals over time. Each signal is sampled from a band-limited continuous-time signal at a sampling frequency $$2N$$ times its highest frequency. A method is preferred that gives about 5 % error at most, is computationally efficient and does not require a large oversampling factor $$N.$$

## Oversampling factor

The bandwidth of the product of two signals is equal to the sum of their bandwidths. Therefore an oversampling factor of $$N = 2$$ will suffice to represent the product without aliasing.

## Integration

Integration is a linear time-invariant operation, basically a continuous-time filter, and applying it does not increase the bandwidth of the signal. What we want to achieve is, with the product signal as "input":

$$\xrightarrow{\text{input}}\boxed{\text{integrate}}\xrightarrow{\text{output}}$$

However, the impulse response of an integrator is of infinite bandwidth and sampling it to form the impulse response of a discrete-time integrator would cause aliasing, corrupting its frequency response. We can insert to the signal path an ideal lowpass filter that has its cutoff at the bandlimit of the input signal. It does nothing to the signal. The output will remain the same as before:

$$\xrightarrow{\text{input}}\boxed{\text{lowpass}}\xrightarrow{\text{input}}\boxed{\text{integrate}}\xrightarrow{\text{output}}$$

We can combine the lowpass filter and integrator to a single filtering operation. The impulse response of this lowpass integrator filter is the convolution of the impulse responses of the lowpass filter and the integrator filter. This shuffling of operations is enabled by the algebraic properties of convolution, namely associativity. We still get the same desired output as before:

$$\xrightarrow{\text{input}}\boxed{\text{lowpass integrate}}\xrightarrow{\text{output}}$$

The lowpass integrator impulse response:

\begin{align} h[k] &= \int_{-\infty}^k\frac{\sin(\pi x)}{\pi x}dx \\ \\ &= \int_0^k\frac{\sin(\pi x)}{\pi x}dx + \frac{1}{2}, \\ \end{align}

is sampled from the integral of the sinc function, without aliasing. Sinc is the impulse response of the ideal continuous-time low-pass filter with a cutoff frequency at $$\pi$$.

Figure 1. Impulse response $$h[k]$$ of an integrator. The impulse response continues indefinitely beyond what is shown, approaching values 0 to the left and 1 to the right.

The impulse response almost represents the process of calculating the sum of (optionally the current sample and) the past samples. As this sum becomes larger and larger, the difference to true integration becomes arbitrarily small, proportionally. The values of $$h[k]$$ approaching 1 for large $$k$$ means that for very old samples just summing them gives virtually no error in the integral estimate.

## Summary

To summarize, oversample the input signals by a factor of two and calculate with a large accumulator a running sum of obtained samples of the product. This will have an arbitrarily small error compared to true integration, as enough data gets accumulated.

## Analog filtering

You should also consider what the analog filtering of the current and voltage signals does to the integral of their product. This can be a big source of error. For example let's say that both signals equal $$\sin^2(x).$$ If this is filtered to remove all oscillation, it becomes a constant signal $$\frac{1}{2}$$. The average value (power) of the square of the unfiltered signal is $$\frac{3}{8}$$ and for the filtered signal $$\frac{1}{4}$$.

• this is legit Olli, but i admit i had an initial cringe reaction when i saw a continuous-time integral in the same equation with a discrete-time impulse response $h[k]$. – robert bristow-johnson Jan 13 at 6:56
• and you shown me how to draw block diagrams with $\LaTeX$. thank you. – robert bristow-johnson Jan 13 at 6:57
• so this simplification relies on the fact that the integral (and therefore the summer) output is getting larger and larger by time, which requires that the integrand is striclty non-negative and that the (delivered to a resisitive load) power signal is just a nice exaple of that... That's pretty neat ;-) – Fat32 Jan 13 at 11:49
• @Fat32 It would also be OK for the integrand to be negative sometimes, as long as the integral grows to a large enough a value by the time the relative error needs to be small. – Olli Niemitalo Jan 14 at 10:43

You do not necessarily need oversampling.

But the closer your sampling rate to the Nyquist rate, then you will have to interpolate the acquired samples so as to get an accurate result from the simple trapezoidal sum computation of the numerical evaluation of the integral.

So if your primary concern is about ADC sampling rate, then you can reduce it, but you would still spend CPU processing power (to interpolate the waveform and sum it) to get an accurate approximation.

• You got my point. I thought maybe there were existing well-known techniques that would combine the interpolation with the integration that are less computationally expensive than doing it in 2 steps. – axk Jan 11 at 22:09
• I'm not pretty sure about the scope of literature on the efficient computation of integral approximations but at a fundamental level, you will be recursively summing those samples to get the integral value at the current time. Not much reducible (at the same accuracy) I guess. – Fat32 Jan 11 at 22:20