# Tag Info

30

The moving average filter (sometimes known colloquially as a boxcar filter) has a rectangular impulse response: $$h[n] = \frac{1}{N}\sum_{k=0}^{N-1} \delta[n-k]$$ Or, stated differently: $$h[n] = \begin{cases} \frac{1}{N}, && 0 \le n < N \\ 0, && \text{otherwise} \end{cases}$$ Remembering that a discrete-time system's frequency ...

15

If $N$ is the length of the moving average, then an approximate cut-off frequency $F_{co}$ (valid for $N >= 2$) in normalized frequency $F=f/fs$ is: $F_{co} = \frac {0.442947} {\sqrt{N^2-1}}$ The inverse of this is $N = \frac {\sqrt{0.196202 + F_{co}^2}}{F_{co}}$ This formula is asymptotically correct for large N, and has about 2% error for N=2, and ...

9

A moving average can be implemented recursively, but for an exact computation of the moving average you have to remember the oldest input sample in the sum (i.e. the a in your example). For a length $N$ moving average you compute: $$y[n]=\frac{1}{N}\sum_{k=n-N+1}^nx[k]\tag{1}$$ where $y[n]$ is the output signal and $x[n]$ is the input signal. Eq. (1) can ...

8

In more standard DSP terms, you have the following filter: $$y[n] = (1-a) x[n] + a y[n-1]$$ where $x[n]$ and $y[n]$ are the input and output signals at time $n$ respectively. The transfer function (which you didn't ask for) is: $$H(z) = \frac{1-a}{1 - az^{-1}}$$ so here is your single pole, at $z=a$ in the complex plane. This filter is also known as ...

7

Convolution in linear time-invariant system is asociative. So to get the equivalent mask you just need to convolve the kernel with itself twice. This will then then give you a 7x7 kernel: octave:1> a = [ 1 1 1 ; 1 1 1 ; 1 1 1 ] a = 1 1 1 1 1 1 1 1 1 octave:2> conv2(a,conv2(a,a)) ans = 1 3 6 7 6 3 1 3 ...

6

What is wrong with a fading memory (exponential) moving average: ma_new = alpha * new_sample + (1-alpha) * ma_old

6

No you are not missing anything. A moving average with a period of $T = 1/60$ seconds will indeed have a notch at 60 Hz, since the frequency response is a Sinc function with the first null at 1/T. (So it is both a low pass filter with an magnitude envelope that goes down as 1/f combined with a notches at integers of 1/T not including 0). This is because a ...

6

Yes you can consider a zeroth (or first) order SG filter as a moving average filter. Below MATLAB / Octave code computes the impulse response of a SG filter of order $N$ and length $2M+1$ : % Savitzky-Golay Filter % clc; clear all; close all; N = 0; % a0,a1,...,aN : Nth order polynomial M = 3; % x[-M],...,x[M] : 2M +...

5

Is moving median always less sensitive to outliers? Sometimes. It will work if you have a very short spike (preferrably shorter than the median/average sample size). However, if you have a large spike, then taking the median won't help eliminate the spikes. Long spike I have illustrated this using a dataset (with sample size = 5, taking into account 2 left ...

4

Exponential averaging is performed using a first order IIR filter according to the difference equation: $$y[n] = (1-\alpha)\;x[n]+\alpha \; y[n-1]$$ where $x[n]$ and $y[n]$ are the input and output signals at time $n$ and the value of the single coefficient $\alpha$ is given by the equation: \alpha = \exp( \frac{-...

4

Your normalized window is given by $$w(n)=\frac{2}{N+1}\frac{N-n}{N},\quad n=0,1,\ldots,N-1$$ The window satisfies $$\sum_{n=0}^{N-1}w(n)=1$$ which means that the gain of the corresponding moving average filter is 1 at DC. For determining the cut-off frequency, we need to compute the frequency response of the window: $$W(e^{j\theta})=\sum_{n=0}^{N-1}w(... 4 I think you can only approximate the result made with filter of different size, but not to get exactly the same result. Suppose you use box filter two times. This is same as convolving the box kernel with itself - that yields a "triangle" filter - and then using the "triangle" filter on the image just once. Using box filter three times is the same as using ... 4 When you talk about bezier curves, it sounds like you think about them from an "illustrator" point of view, which is not totally right when it comes to spline interpolation (most probably what you are looking for). Splines are piecewise curves that pass thrhough points. Bezier curves are third degrees splines between two points, and a series of them can ... 4 This isn't really an answer, but I thought I'd report what I'm seeing and ask for more information. I've loaded your test.wav file and I can see the signal plotted below. So what you're getting in the plots you show is not so much the median value, but is more like an envelope of the signal. The second issue is that the signal actually seems to be part of ... 4 The fundamental property of averaging filters (in swear words, a linear system) is that the output of a sine is a sine of the same frequency, albeit of zero amplitude. So: Which non-trivial moving average weights would you need to find to get a filter that returns the same output as its input? An averaging in phase with the sine: take a filter full of ... 4 (Update: I just realized that the first part of this covering CIC structures is basically what Hilmar has already answered-- I'll leave this up since it offers more graphics and details in case that his helpful to anyone but it is indeed the same answer) This may not be optimum and although a feedback structure is involved it is strictly not IIR, but want ... 4 This is not a full answer. It explores some basic approximations. For a moving average as long as 600 samples it is informative to look at impulse responses of continuous-time filters as approximations of those of the desired discrete-time filters. Let's have as the ideal desired impulse response a boxcar function normalized to a width of 1 spanning x = 0\... 4 I can show you some low order IIR approximations to an FIR moving average filter. In the figure below you see 3 (infinite) impulse responses that approximate a moving average of length N=600. The filter orders are 1, 2, and 5, respectively, and they all approximate the desired response in a least squares sense. I used the equation error method to ... 4 That system you're referring to is a first-order recursive filter$$y[n]=\alpha x[n]+(1-\alpha)y[n-1],\qquad 0<\alpha<1\tag{1}$$where n is the (integer) time index, y[n] is the output, and x[n] is the input. You chose \alpha=\frac12. That filter is also called exponentially weighted moving average. It has theoretically infinite memory and ... 4 There is a way to do it, it is really similar to a moving average N : number of samples per period Z : Accumulator x[n] : current sample$$Z[n] = Z[n-1]+ x[n]^2 - x[n-N]^2 x_{RMS}[n] = \sqrt{\frac{1}{N}Z[n]}$$Basically, you need a delay line to store the previous x[n] samples or better yet the previous x[n]^2 samples and you need an ... 3 The formula$$ a_n = a_{n-1} \frac{n-1}{n} + \frac{x_n}{n} .$$is a way to compute the average of n samples, and update this average whenever a new sample is obtained, without storing all of the samples individually. Ignoring the part about online computation, I think your question is equivalent to "is there a way to estimate the mean of N identically ... 3 No, it is not possible to achieve the same result with a larger averaging filter. Convolution is a linear process, so it obeys the law of associativity. Thus if your signal is s(t) and your filter is f(t) (and we'll set n to 3 just to make the display easier), then we could mathematically describe the filtering as follows-$$ \begin{align} a(t) &...

3

One way to see the equivalence is to first factor out the $0.5$ in your initial transfer function, i.e. $$H(f) = 0.5(1 + e^{-i2\pi f}).$$ Then you can rewrite the $1$ and $e^{-i2\pi f}$ as follows: $$H(f) = 0.5(e^{i\pi f}e^{-i\pi f} + e^{-i\pi f}e^{-i\pi f}) = 0.5(e^{i\pi f} + e^{-i\pi f})e^{-i\pi f}.$$ Your result then follows as a trivial ...

3

ok the solution was: (in R) emaweights<-function(m) { alpha<-2/(m+1) i<-1:m sm<-sum((alpha*(1-alpha)^(1-i))) return(((alpha*(1-alpha)^(1-i)))/sm) } Here the weights do add up to 1.

3

A simple and general method for filling in missing data, if you have runs of complete data, is to use Linear regression. Say you have 1000 runs of 5 in a row with none missing. Set up the 1000 x 1 vector y and 1000 x 4 matrix X: y X wt[0] wt[-2] wt[-1] wt[1] wt[2] --------------------------------- 68 67 70 70 68 ... Regression will ...

3

So when will you think you need moving average in an algorithm design? If you mean moving average filters; moving averages as the name suggest are computed as averages of samples say, $M-1$ previous samples (+ current sample) from input $x[n]$ to get an average output $y[n]$, repeating the process to get all $y$ samples. Computing their mean to get an ...

3

Is the ADC sample-and-hold fast enough to even capture any envelope peaks or even half cycles? If not, all bets are off. If your ADC does have a fast enough capture time, then randomizing your sample times might be a good bet at capturing a few near extrema. If you know, a priori, the approximate shape of your waveform, then Monte-Carlo sampling might ...

3

A centered moving average filter is a finite impulse response (FIR) filter that affects the same weight to all the samples in the window. If you only care about time domain properties, and do not care about its relatively poor performance in the spectral domain, for a signal $s$ that is quite stationary across the window, you can use it. It has extremely ...

3

Yes sure they are LTI. Let $A$ be the $(L-1)\times (L-1)$ shift matrix $$A := \begin{pmatrix}0 & 1 & 0 && \dots & 0\\0 & 0 & 1 & 0 &\dots &0\\\vdots &&& \ddots && 0\\0&&\dots&&1&0\\0 &&\dots&&0&1\\0&0&\dots&0&0&0\end{pmatrix}$$ and  B ...

3

I am not entirely sure what matlab's LASSO routine does so I started with Ordinary Least Squares (OLS) and worked backwards. From an OLS perspective X1 as you have it won't work. You've got a regressor that is as all ones, but your parameter inputs for you example data (r) doesn't contain an offset. Essentially your model doesn't fit you're data well, ...

Only top voted, non community-wiki answers of a minimum length are eligible