diff options
author | shamikam | 2017-11-07 15:59:48 +0530 |
---|---|---|
committer | shamikam | 2017-11-07 15:59:48 +0530 |
commit | c0c0582462720ed597b00e116506570577614e89 (patch) | |
tree | 31dedd23698e5357b19c810b7d7a8464100ef44a /macros/cell2sos.sci | |
download | FOSSEE-Signal-Processing-Toolbox-c0c0582462720ed597b00e116506570577614e89.tar.gz FOSSEE-Signal-Processing-Toolbox-c0c0582462720ed597b00e116506570577614e89.tar.bz2 FOSSEE-Signal-Processing-Toolbox-c0c0582462720ed597b00e116506570577614e89.zip |
initial commit
Diffstat (limited to 'macros/cell2sos.sci')
-rw-r--r-- | macros/cell2sos.sci | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/macros/cell2sos.sci b/macros/cell2sos.sci new file mode 100644 index 0000000..39402b3 --- /dev/null +++ b/macros/cell2sos.sci @@ -0,0 +1,95 @@ +function [s,g] = cell2sos(c) +//Converts a cell array to a second order section matrix +//Calling Sequences +//s=cell2sos(c) +//[s,g]=cell2sos(c) +//Parameters +//c +//A cell array +//g +//The scalar gain +//Description +//s=cell2sos(c) converts a a cell array c = { {B1},{A1}, {B2},{A2}, ... {BL},{AL}} +//to an L-by-6 second-order-section matrix s given by: +// s = [B1 A1 +// B2 A2 +// ... +// BL AL] +//numerator vector Bi and denominator vector Ai contains the coefficients of a +//linear or quadratic polynomial. If the polynomial is linear, the coefficients +//zero-padded on the right. +//[s,g]=cell2sos(c) estimates the gain from the leading term of the cell array +//c={ {[g1,g2]},{B1},{A1}, {B2},{A2}, ... {BL},{AL}} to give g=g1/g2 as the gain +//Example +//c=cell(1,5); +// +//c(1,1).entries=[2, 1]; +// +//c(1,2).entries=rand(1,3); +// +//c(1,3).entries=rand(1,3); +// +//c(1,4).entries=rand(1,3); +// +//c(1,5).entries=rand(1,3); +// +// c = +// column 1 to 3 +// +//![2,1] [0.2113249,0.7560439,0.0002211] [0.3303271,0.6653811,0.6283918] ! +// +// column 4 to 5 +// +//![0.8497452,0.6857310,0.8782165] [0.0683740,0.5608486,0.6623569] ! +//[s,g]=cell2sos(c); +//s = +// +// column 1 to 5 +// +// 0.2113249 0.7560439 0.0002211 0.3303271 0.6653811 +// 0.8497452 0.6857310 0.8782165 0.0683740 0.5608486 +// +// column 6 +// +// 0.6283918 +// 0.6623569 +// +//g = +// +// 2. +//Author +//Ankur Mallick + if(argn(2)~=1) then + error("Wrong number of input arguments"); + end + + L=prod(size(c)); + for i=1:L + if(type(c(i))~=17) + error('Cell contents must themselves be cell objects'); + end + end + if (argn(1)==2) + d=c(1).entries; + if(length(d)==2) + g1=d(1); + g2=d(2); + g=g1/g2; + c=c(2:L); + else + g=1; + end + end + L=prod(size(c)); + s=zeros(L/2,6); + for i=1:2:L-1 + j=ceil(i/2) + b=c(i).entries; + a=c(i+1).entries; + b=b(:).'; + a=a(:).'; + b=[b,zeros(1,3-length(b))]; + a=[a,zeros(1,3-length(b))]; + s(j,:)=[b,a]; + end +endfunction |