the Filter function generated output is not as same as what the reference says
이전 댓글 표시
I am using Filter function to get moving average of a data vector.
Here is the the Matlab code:
fileID = fopen('dj_test.txt');
C = textscan(fileID,'%d %d %d');
fclose(fileID);
%STEP 1: moving average:
a = 1;
b = [1/5 1/5 1/5 1/5];
x = filter(b,a,double(C{1}));
y = filter(b,a,double(C{2}));
z = filter(b,a,double(C{3}));
And here is the my date file dj_test.txt:
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
2 2 2
2 2 2
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
2 2 2
2 2 2
The result [x y z] is as:
0.2000 0.2000 0.2000
0.4000 0.4000 0.4000
0.6000 0.6000 0.6000
0.8000 0.8000 0.8000
0.8000 0.8000 0.8000
1.0000 1.0000 1.0000
1.2000 1.2000 1.2000
1.4000 1.4000 1.4000
1.6000 1.6000 1.6000
1.6000 1.6000 1.6000
1.4000 1.4000 1.4000
1.2000 1.2000 1.2000
1.0000 1.0000 1.0000
0.8000 0.8000 0.8000
0.8000 0.8000 0.8000
1.0000 1.0000 1.0000
1.2000 1.2000 1.2000
1.4000 1.4000 1.4000
1.6000 1.6000 1.6000
1.6000 1.6000 1.6000
According to the function reference ( http://www.mathworks.com/help/matlab/ref/filter.html ): The result looks strange to me. For example, the last value should be (2+2+2+2+2)/5=2, I wonder why it is 1.6. Is it because what I use (Filter) is different from what the reference says? If that's the case, how can I set the correct context for using a function that I need. I know there are functions with the same name but do different calculations.
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!