Error in butter command
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (2)
Star Strider
le 12 Avr 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 commentaires
Star Strider
le 12 Avr 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.
Jan
le 12 Avr 2014
Modifié(e) : Jan
le 12 Avr 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)
0 commentaires
Voir également
Catégories
En savoir plus sur Filter Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!