Error in butter command

6 views (last 30 days)
M B
M B on 12 Apr 2014
Edited: Jan on 12 Apr 2014
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?

Answers (2)

Star Strider
Star Strider on 12 Apr 2014
Check to see that butter_deg_vector is a positive integer greater than zero. Use floor, round, ceil, or fix to be sure.
  2 Comments
Star Strider
Star Strider on 12 Apr 2014
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 on 12 Apr 2014
MB's "Answer" moved here:
Yes, it consists of positive values only.

Sign in to comment.


Jan
Jan on 12 Apr 2014
Edited: Jan on 12 Apr 2014
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)

Tags

Community Treasure Hunt

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

Start Hunting!