Problems using the filter function with a column vector

조회 수: 2 (최근 30일)
Darryl
Darryl 2013년 11월 15일
댓글: Darryl 2013년 11월 15일
I am having problems using the filter function with a column vector. I have a simple column vector that starts off with numbers like so:
77
76
75
75
77
78
.....
When I apply the filter function my new vector starts with
19.2500
38.2500
57
75.7500
75.7500
76.2500
....
When both these vectors are plotted the first couple of filtered points are completely off as imagined when looking at the first few rows of data. After the preceding error the filtered version follows the unfiltered version as expected.
a = filter([0.25 0.25 0.25 0.25], 1, z);

채택된 답변

Wayne King
Wayne King 2013년 11월 15일
편집: Wayne King 2013년 11월 15일
Not sure why you say it is off. filter() convolves the data with the 4-point moving average filter in a causal manner.
So for the first element you get 77/4 because x(0-k) is only valid when k=0, as soon as k increments to 1, you have x(-1) which is 0. There is no element before the starting element, x(0) (not using MATLAB 1-based indexing here)
For the 2nd element you get (x(1-0)+x(1-1))/4 = (77+76)/4
finally the 4th element gives you 75.75
Using zero-based indexing, filter is outputting the following:
Let h(n) = 1/4 n = 0,1,2,3,4
y(n) = \sum_{k=0}^3 h(k) x(n-k)
start plugging in values for n of n = 0, 1,2, 3 and you'll see why you get the output you observe.
  댓글 수: 1
Darryl
Darryl 2013년 11월 15일
Sorry yes I see now after sketching a moving average diagram and adding the first 3 elements.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by