필터 지우기
필터 지우기

Error in butter command

조회 수: 3 (최근 30일)
M B
M B 2014년 4월 12일
편집: Jan 2014년 4월 12일
Hello,
I wrote the following function:
function [output_signal] = AddDirectivityError (bat_loc_index, butter_deg_vector, sound_matrix)
global chirp_initial_freq ;
global chirp_end_freq;
global sampling_rate;
global num_of_mics;
global sound_signal_length;
for (i=1 : num_of_mics)
normalized_co_freq = (chirp_initial_freq + chirp_end_freq)/ (1.6* sampling_rate);
A=sound_matrix ( i, : ) ;
peak_signal=max(A);
B=find(abs(A)>peak_signal/100);
if (butter_deg_vector(i)==0)
butter_deg_vector(i)=2;
end
[num, den] = butter ( butter_deg_vector(i), normalized_co_freq, 'low'); // HERE!!!
filtered_signal=filter(num,den, A );
output_signal(i, :)=filtered_signal;
end
This functions runs many-many times without any error. However, when I reach the line: [num, den] = butter ( butter_deg_vector(i), normalized_co_freq, 'low');
AND the local variables are: i=3, butter_deg_vector(i)=1, normalized_co_freq=5.625000e-001
MATLAB prompts an error says:
??? Error using ==> buttap Expected N to be integer-valued.
"Error in ==> buttap at 15 validateattributes(n,{'numeric'},{'scalar','integer','positive'},'buttap','N');
Error in ==> butter at 70 [z,p,k] = buttap(n);"
I don't understand why this problem occurs especially in this iteration. Why does this function prompt an error especially in this case?

답변 (2개)

Star Strider
Star Strider 2014년 4월 12일
Check to see that butter_deg_vector is a positive integer greater than zero. Use floor, round, ceil, or fix to be sure.
  댓글 수: 2
Star Strider
Star Strider 2014년 4월 12일
I can’t reproduce the error.
This (that I believe are the arguments you supplied) works:
[num,den] = butter(1, 5.625000e-001, 'low')
and produces:
num =
549.2457e-003 549.2457e-003
den =
1.0000e+000 98.4914e-003
The only thing I can think of is that somehow butter_deg_vector rounds to zero as you see it but may actually be 1+eps or something similar, the reason I suggested fix and friends.
Image Analyst
Image Analyst 2014년 4월 12일
MB's "Answer" moved here:
Yes, it consists of positive values only.

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


Jan
Jan 2014년 4월 12일
편집: Jan 2014년 4월 12일
Matlab tells you unequivocally that butter_deg_vector(3) is not a positive integer. How do you test if it is one? Note that the numbers are rounded if you display them in the standard format short f. See also:
doc format
Please try this:
d = butter_deg_vector - round(butter_deg_vector);
fprintf('%.16g\n', d)

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by