What is the physical interpretation of sos in Zp2sos function?
7 views (last 30 days)
Show older comments
I am trying to filtering my signal using the following script.
dt=(t(end)-t(1))/(N-1); %sampling interval (days)
fs=1/dt; fNyq=fs/2; %sampling frequency, Nyquist frequency (cycles/day)
f1=1; f2=4; %bandpass corner frequencies (cycles/day)
[z,p,k]=butter(4,[f1,f2]/fNyq,'bandpass'); %4th order Butterworth bandpass filter coefficients
[sos,g]=zp2sos(z,p,k); %sos representation of the filter
xde=filtfilt(sos,g,y); %apply zero phase filter to ser1
But, i am still not sure about the physical interpretation of few parameteres.
[z,p,k] > are poles, zeroes and gain are converted to sos and g. here what exactly sos shows and why we need to do this.
In my case, i get this as sos matrix, but i am not clear how to interpret this
1 2 1 1 -1.9836 0.9838
1 2 1 1 -1.9918 0.9921
1 -2 1 1 -1.9922 0.9922
1 -2 1 1 -1.9979 0.9979
Amey Waghmare on 23 Nov 2022
As per my understanding, you have used ‘zp2sos’ to obtain Second order section (sos) representation of the filter, and want to understand the interpretation of the resulting sos matrix.
Please refer to the attached image:
The sos representation is returned as a L-by-6 matrix, where L is the number of sections, which depends upon the number of poles and zeros of the filter. Each rows contains the numerator and denominator coefficients 'bik' and 'aik' of the second order sections of the filter. The structure of the filter is shown by H(z) in the above image.
For more information, please refer to the following documentation on zp2sos: https://in.mathworks.com/help/signal/ref/zp2sos.html
Hope this resolves the issue.
Paul on 23 Nov 2022
Addresing the second part of your question: " why we need to do this"
filtfilt will accept either transfer function (b,a) or sos (sos,g) form of the the filter, but not zpk form. So we have to choose one or the other. sos form has better numerical properties for computation.
Example filter parameters
n = 6;
Wn = [2.5e6 29e6]/500e6;
ftype = 'bandpass';
% Zero-Pole-Gain design
[z,p,k] = butter(n,Wn,ftype);
Note that all of the poles are inside the unit circle, as expected.
Convert to transfer function form
[b,a] = zp2tf(z,p,k);
Because of floating point issues, some of the poles are now outside the unit circle, which would be an unstable filter.
Convert to sos form
[sos,g] = zp2sos(z,p,k);
The poles of the sections are inside the unit circle, and they should be very, very close matches to p.
C = cellfun(@(x) roots(x(4:6).'),mat2cell(sos,ones(size(sos,1),1)),'UniformOutput',false);
Do filtfilt with both forms, observe very different results
x = rand(1000,1);
y1 = filtfilt(b,a,x);
y2 = filtfilt(sos,g,x);
Note that filter, which is not part of the signal processing toolbox, does not accept the sos form.
Find more on Digital Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!