function [zepo,k] = zpssnosp(th,nnu,nny,thresh)
%ZPSS	An auxiliary function to ZP
%       (not relying upon the Signal Processing Toolbox)
%
%	[zepo,k] = zpssnosp(th,nnu,nny)
%

%	L. Ljung 1-16-94
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%	$Revision: 1.2 $  $Date: 1995/01/24 00:54:03 $

[a,b,c,d,km]=eta2ss(th); [nx,nu]=size(b);[ny,nx]=size(c);
if any(nnu>nu),error('There are not that many inputs in the model!'),end
if any(nnu<-ny),error('There are not that many noise sources in the model!'),end
if any(nny>ny) | any(nny<1)
   error('There are not that many outputs in the model!'),end
T=gett(th);
if isempty(nnu),nnu=1:nu;end
if isempty(nny),nny=1:ny;end
lny=length(nny);
if any(nnu==0),
    nnu=[-ny:-1,nnu(find(nnu>0))];
end
if length(nnu)>0
zepo=[];k=[];
for ku=nnu
    [num,den]=th2tf(th,ku);
    p1=roots(den);z1=[];
    for ky=nny
        temp=roots(num(ky,:));
        [rtt,ctt]=size(temp);[rz1,cz1]=size(z1);
        if isempty(z1)
           z1=temp;
        else
           z1=[[z1;zeros(rtt-rz1,1)],[temp;zeros(rz1-rtt,1)]];
        end
    end
    if T>0
       k1=sum(num(nny,:).')/sum(den);
    else
       [rtt,ctt]=size(num);
       k1=num(nny,ctt).'/den(length(den));
    end
    G1=zeros(1+nx,2*lny)+inf;ka1=zeros(2,lny);
    [nzr,nzc]=size(z1);
   [rz1,cz1]=size(z1);
   for kinf=1:cz1
      kind=find(abs(z1(:,kinf))>thresh);
      if ~isempty(kind),z1(kind,kinf)=inf*ones(length(kind),1);end
   end
   G1(1,1:2:2*lny)=1000*(nny-1)+ku;
   G1(1,2:2:2*lny)=1000*(nny-1)+20+ku;ka1(1,1:lny)=1000*(nny-1)+ku;
   [nzr,nzc]=size(z1);
   G1(2:nzr+1,1:2:2*lny)=z1;
   G1(2:length(p1)+1,2:2:2*lny)=p1*ones(1,lny);
   ka1(2,1:lny)=k1;
   k=[k ka1];
   zepo=[zepo G1];
end,end
zepo(1,:)=sign(T)*zepo(1,:);

