Audio filtering strange issue with MATLAB -
i'm filternig sound file matlab within function script has function named "filtro_pf" created me band-pass filter , outputs iir corresponding coefficients:
[b,a] = filtro_pf(ap,as,fp1,fs1,fp2,fs2,1); //band pass filter b2 = [0.0039,0,-0.0156,0,0.0234,0,-0.0156,0,0.0039]; a2 =[1.0000,-6.2682,17.2660,-27.3421,27.2582,-17.5284,7.0998,-1.6555,0.1701]; wfpf = filter(b,a,audio_stream); wavplay(wfpf,fs); note sec , 3rd lines (b2 , a2) values function 'filtro_pb()' gives me inputs. i've run 1 time , copied them these variables. now, after run script, if inquire 'a' , 'a2' in console have:
a = 1.0000 -6.2682 17.2660 -27.3421 27.2582 -17.5284 7.0998 -1.6555 0.1701 a2 = 1.0000 -6.2682 17.2660 -27.3421 27.2582 -17.5284 7.0998 -1.6555 0.1701 they pretty much same. if utilize 'a2' instead of 'a' in filter() function, not work. hear kind of tick sound , that's it. 'a' can hear sound correctly filtered. same code used before , work:
%[b,a] = filtro_pa(ap,as,fp,fs,1); //high pass filter b = [0.5411 -1.6232 1.6232 -0.5411]; = [1.0000 -1.8062 1.2298 -0.2925]; wfpa = filter(b2, a2, audio_stream); wavplay(wfpa,fs); again, used script , saw these values (from a2 , b2) output these inputs. instead of calling function 1 time again (which commented way) utilize 'a' , 'b'vectors directly. work lowpass , highpass filter.
all of test purposes not expect suggestions "why utilize vector instead of calling function then?".
i want know, how can function not work sec variable if pretty much same?
there more precision nowadays in variables displayed, means a2 , b2 vectors not same a , b. might appear surprising errors on order create filter unstable, appears happening. should able explore looking @ filter response freqz, , plotting resulting sound vector rather listening it.
you can utilize format long print more precision, these still have rounding error. avoid, save vectors .mat file , reload that. .mat file utilize binary format , store total precision of vectors.
the reason works other filters because filters less sensitive rounding errors in coefficients: have fewer coefficients, , coefficients less extreme in value.
here's sample comparing of frequency response:
[h w] = freqz(b2, a2); % filter (with error) a_error = zeros(size(a2)); a_error(9) = a_error(9)+.001; % little bit of error in single coefficient [he we] = freqz(b2, a2 + a_error); % frequency response of filter plot(log10(abs([h he]))) as can see, little alter makes big difference.
an actual analysis of instability comes looking @ poles , zeros of filter:
[z p k] = tf2zp(b2, a2); abs(p) if poles have magnitude greater 1 (this 1 does), filter unstable. seek real values, "approximate" values, , see happens.
matlab audio
No comments:
Post a Comment