function [su c] = tf2g(num, den, q, n, lambda, x)
%tf2g vraci koeficieny spektra a aproximaci funkce pomoci LF
%num - citatelovy polynom
%den - jmenovatelovy polynom
%q - zakladni rad zlomkove derivace
%n - pocet koeficientu
%lambda - koeficient lambda
%x - vektor casove osy
%su - vysledna aproximace
%c - koeficienty spektra

if length(num) < length(den)
  bil = @(x) (lambda.*(1.+x)./(1.-x));
  [r, p, k, e] = residue (num, den);
  numPol=length(r);
  c=zeros(1,n); 
  
  for i = 1:numPol
    Fs{i} = @(s) ( r(i)./(s.**q .-p(i)).**e(i) );
  end  

  for i=1:n
    d=(0-0.005-0.004*i):0.00001:(0+0.005+0.004*i);
    for j=1:numPol
      a=polyfit(d,(Fs{j}(bil(d))),i); %vypocet derivace
      der=factorial(i)*a(1);
      c(1,i)= c(1,i)-sqrt(2*lambda)*der/factorial(i);
    end    
  end
  
  su=zeros(1,length(x));
  for i=1:n
    L(i,:)=LaguerreFuncN(i-1,1,2*lambda,x);
    su=su+L(i,:).*c(1,i); 
  end
else
  su=NaN;  c=NaN;
end
end