필터 지우기
필터 지우기

Filter Question

조회 수: 1 (최근 30일)
Steve
Steve 2012년 3월 4일
I am trying to use a filter to get rid of noise on some data that I have. However, this data continuously updates. I can run a simple test in the command window and the code works fine:
for i=1:30
num(i)=rand;
end
a = 1;
b = [1/4 1/4 1/4 1/4];
y=filter(b,a,num);
plot(y)
However, when i try to implement this into my program that reads data from the serial port, I get the following error:
??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Note that when this is implemented into my code, the variable num is now a continuously updating value.
How could I get around this error?
  댓글 수: 1
Honglei Chen
Honglei Chen 2012년 3월 4일
Could you post your code snippet and let us know which line errors out?

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

답변 (1개)

Wayne King
Wayne King 2012년 3월 4일
Do you have a variable in your workspace called filter?
If you enter
>>which filter
is it a variable?
If so, clear that variable.
The code you posted should work, but there is no reason to form num using a for loop.
num = rand(30,1);
a = 1;
b = [1/4 1/4 1/4 1/4];
y=filter(b,a,num);
plot(y)

카테고리

Help CenterFile Exchange에서 Digital and Analog Filters에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by