我写了以下函数:
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
此函数运行多次,没有任何错误。但是,当我到达该行时:[num, den] = butter ( butter_deg_vector(i), normalized_co_freq, 'low');
局部变量是:i=3, butter_deg_vector(i)=1, normalized_co_freq=5.625000e-001
MATLAB提示错误说:
??? 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);"
我不明白为什么会出现此问题,尤其是在此次迭代中。为什么这个函数会在这种情况下提示错误?
答案 0 :(得分:-1)
尝试更改以下代码行:
[num, den] = butter (round(butter_deg_vector(i)), normalized_co_freq, 'low');