Sliding Window Filter using FIR filter in Simulink

3 views (last 30 days)
Alan
Alan on 25 Sep 2012
I'm trying to create a "sliding window" or "moving average" filter. Before implementing into my larger model, I created a test model. I have a sine wave input followed by a quantizer, then a discrete FIR filter. The intent is to output the average of the last 20 samples.
The parameters on the FIR filter are:
Coefficient source: Dialog parameters
Filter structure: Direct form
Coefficients: ones(1,20)/20
Input processing: Elements as channels (sample based)
Initial states: 0
Sample time: .01
Here is the quantized data (left) and the FIR output (right):
0 0
22 8.80000000000000
44 24.2000000000000
44 44.0000000000000
66 58.3000000000000
66 66.0000000000000
88 81.4000000000000
88 88.0000000000000
88 88.0000000000000
88 88.0000000000000
88 88.0000000000000
66 73.7000000000000
66 66.0000000000000
44 50.6000000000000
22 38.5000000000000
22 22.0000000000000
0 1.10000000000000
-22 -15.4000000000000
-44 -30.8000000000000
-44 -44.0000000000000
-66 -64.9000000000000
-66 -66.0000000000000
-88 -88.0000000000000
-88 -88.0000000000000
-88 -88.0000000000000
-88 -88.0000000000000
-88 -88.0000000000000
-66 -67.1000000000000
-66 -66.0000000000000
-44 -44.0000000000000
-22 -31.9000000000000
0 -16.5000000000000
0 0
22 22.0000000000000
44 37.4000000000000
66 49.5000000000000
66 66.0000000000000
88 72.6000000000000
88 88.0000000000000
88 88.0000000000000
88 88.0000000000000
88 88.0000000000000
66 82.5000000000000
66 66.0000000000000
44 59.4000000000000
44 44.0000000000000
22 26.4000000000000
0 9.90000000000000
-22 -5.50000000000000
-22 -22.0000000000000
-44 -44.0000000000000
-66 -56.1000000000000
-66 -66.0000000000000
-88 -78.1000000000000
-88 -88.0000000000000
-88 -88.0000000000000
-88 -88.0000000000000
-88 -88.0000000000000
-66 -77
-66 -66.0000000000000
As you can see, it is not outputting the intended data. It appears to only be considering the current sample and one previous. What have I done wrong?

Answers (0)

Community Treasure Hunt

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

Start Hunting!