Effacer les filtres
Effacer les filtres

Find moving average with filter

6 vues (au cours des 30 derniers jours)
Benjamin
Benjamin le 28 Jan 2013
This is a class assignment. Teacher is assuming everyone has experience with filters and stuff. I definitely don't althought the rest of the class seems to.
We're supposed to use the "filter" command to find the running average of a vector containing integers from 1 to 10, ie y1 = 0.5*(x1+x2), y2= 0.5*(x2+x3) etc...
My approach would've been:
x = [1:1:10]
for j = 1:10 k = j+1 y(j) = 0.5*(x(j) + k) end
But they want us to use this filter function. I really can't interpret the documentation since I have no idea what a filter is even.
  1 commentaire
Matt J
Matt J le 28 Jan 2013
In my experience, it's a bad idea to take courses you lack prerequisites for.

Connectez-vous pour commenter.

Réponses (4)

Daniel Shub
Daniel Shub le 28 Jan 2013
The key part of the documentation is:
y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
- a(2)*y(n-1) - ... - a(na+1)*y(n-na)
If you let all the a's be zero you get
y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
If you then let b(1) = 0.5, and b(2) = 0.5, and zero otherwise
y(n) = 0.5*x(n) + 0.5*x(n-1) = 0.5*(x(n)+x(n-1))
Does that help?

Shashank Prasanna
Shashank Prasanna le 28 Jan 2013
Modifié(e) : Shashank Prasanna le 28 Jan 2013
Appreciate your honesty. I recommend you go to wikipedia or your favorite signal processing book and take a deep loop at FIR filters.
Pay close attention to the block diagram. Although I will give you the code below, I want you to look at the block diagram and relate it to the "for" loop you wrote. Think about how the coefficients b0 b1 are the 1/2s and z_inverse delays the input in order to sum them. Think hard till it hits you and you will be like ah! and trust me you need this now for the rest of your course. Here is the block diagram from wiki:
and the code, go to the documentation of FILTER to see what each argument means.
data = 1:10;
filter([1 1]/2,1,data,1)

Matt Kindig
Matt Kindig le 28 Jan 2013
Modifié(e) : Matt Kindig le 28 Jan 2013
Or even easier, go to the "Help" in Matlab, and search "moving average filter". The first or second link (the one entitled "Example: Moving Average Filter") will show you exactly how to do this using the 'filter' function.
  1 commentaire
Jan
Jan le 28 Jan 2013
Modifié(e) : Image Analyst le 28 Jan 2013
Searching in the help is an answer for which I cannot vote enough.

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 28 Jan 2013
Why not simply use conv()?
filteredSignal = conv(originalSignal, [.5, .5], 'valid');
  1 commentaire
Daniel Shub
Daniel Shub le 28 Jan 2013
Presumably because question number 2 requires an IIR filter ...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Statistics and Linear Algebra dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by