Effacer les filtres
Effacer les filtres

tf2zpk vs. zp2tf

7 vues (au cours des 30 derniers jours)
Yun Zhang
Yun Zhang le 20 Déc 2016
Commenté : Vandana Rajan le 21 Fév 2017
I used tf2zpk to get zeros, poles and gain, then use zp2tf to get the transfer function, shown below. [z22,p22,k22] = tf2zpk(h22',1); [b,a] = zp2tf(z22,p22,k22); plot(h22-b');
I expect h22 is same as b but there is big difference. Did I miss anything?
Thanks,
Yun
  1 commentaire
David Barry
David Barry le 20 Déc 2016
Yes you forgot to upload some data so we can run the commands.

Connectez-vous pour commenter.

Réponses (1)

Vandana Rajan
Vandana Rajan le 23 Déc 2016
Hi,
There might be some issues with your 'h22'. Note that you should use tf2zpk when working with transfer functions expressed in inverse powers (1 + z-1 + z-2), which is how transfer functions are usually expressed in DSP. A similar function, tf2zp, is more useful for working with positive powers (s2 + s + 1), such as in continuous-time transfer functions.
You may try out the following
[b,a] = butter(3,.4);
fvtool(b,a,'polezero')
[z,p,k] = tf2zpk(b,a)
text(real(z)-0.1,imag(z)-0.1,'\bfZeros','color',[0 0.4 0])
text(real(p)-0.1,imag(p)-0.1,'\bfPoles','color',[0.6 0 0])
[b1,a1] = zp2tf(z,p,k)
b1 and a1 turn out to be equal to b and a.
  2 commentaires
Yun Zhang
Yun Zhang le 27 Déc 2016
I did use tf2zpk, as show below. clear N=4096*2;
filename = 'H0e030a.wav'; [h,fs] = audioread(filename);
h12 = h(:,1); % symetric, h21=h12, h11 = h22 h22 = h(:,2); [H22,freq] = freqz(h22',1,N,fs);
%% search for zeros inside and outside unit circle [z22,p22,k22] = tf2zpk(h22',1); % z22, p22 are column vectors
[h22b,h22a] = zp2tf(z22,p22,k22); [H22p,freq] = freqz(h22b,h22a,N,fs);
figure, semilogx(freq, 20*log10(abs([H22, H22p])));
Vandana Rajan
Vandana Rajan le 21 Fév 2017
Hi,
Computing the transfer function from a large number of zeros creates numerical problems as you multiply several roots together. The problem becomes more visible as the number of filter coefficients increases (as can be seen in this case).
It is never a good idea to directly compute the transfer function of a filter from its roots as you are trying to do in this case. Using second order sections provides a more stable filter representation. This can be observed by adding the following 2 lines of code at the end of your script, for_mathworks.m: sos = zp2sos(z22,p22,k22); fvtool(h22,1,h22b,h22a, sos) You can see how the second order section representation is comparable to the original response in the filter visualization tool output.
You can refer to the following documentation for more information about the fv tool and the 'sos' function: https://www.mathworks.com/help/signal/ref/fvtool.html https://www.mathworks.com/help/dsp/ref/sos.html
[Pasting here the mail sent from MathWorks Technical Support, so that the information can be useful for other community members too]

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by