Clear Filters
Clear Filters

tf2zpk vs. zp2tf

7 views (last 30 days)
Yun Zhang
Yun Zhang on 20 Dec 2016
Commented: Vandana Rajan on 21 Feb 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 Comment
David Barry
David Barry on 20 Dec 2016
Yes you forgot to upload some data so we can run the commands.

Sign in to comment.

Answers (1)

Vandana Rajan
Vandana Rajan on 23 Dec 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 Comments
Yun Zhang
Yun Zhang on 27 Dec 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 on 21 Feb 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]

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!