octave-patch-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-patch-tracker] [patch #8215] thiran function (for controls packa


From: Spencer
Subject: [Octave-patch-tracker] [patch #8215] thiran function (for controls package)
Date: Wed, 23 Oct 2013 22:51:45 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0

URL:
  <http://savannah.gnu.org/patch/?8215>

                 Summary: thiran function (for controls package)
                 Project: GNU Octave
            Submitted by: ssj71
            Submitted on: Wed 23 Oct 2013 10:51:44 PM GMT
                Category: None
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

hopefully this is the correct way to submit. I needed a fractional order delay
and saw matlab has a function called thiran, which generates an allpass filter
with coefficients found using the Thiran approximation. The code below
implements the functionality and also I've made a second version that
calculates it based on an input non-integer number of samples delay rather
than just a time input. Feel free to contact me for feedback, or if there's a
better way to submit this.


%Time version

%generate an all-pass fractional delay using the Thiran approximation This
interpolates between samples to provide a non-integer delay.
%sys = thiran(tau, Ts)
%inputs:
%tau - time of delay
%Ts - sampling time
%
%Outputs:
%sys - transfer function of the filter
%
%Example:
% H = thiran(4.4,.5);
%               generates 9th order fractional delay filter delaying 4.4 
seconds 
%
% H = thiran(8,.01);
%               generate pure delay of 8 seconds 
%See Also: thiran2
function sys = thiran(tau, Ts)
        D = tau/Ts;
        N = ceil(D);
        if(N==D)
                sys = tf([1],[1 zeros(1,N)],Ts);
        else
                
                a =
(-1).^(1:N).*bincoeff(N,1:N).*prod((D-N+[0:N]'*ones(1,N))./(D-N+(1:N)+[0:N]'));
                sys = tf([a(N:-1:1) 1],[1 a],Ts);
        end
end

%the code implements the thiran approximation:
%a = ones(1,N);
%for k=1:N
%       for i=0:N
%               a(k) = a(k)*(D-N+i)/(D-N+k+i);
%       end
%       a(k) = (-1)^k*bincoeff(N,k)*a(k);
%end
                
%sample delay version

%generate an all-pass fractional delay using the Thiran approximation. This
interpolates between samples to provide a non-integer delay.
%sys = thiran2(tau, Ts)
%inputs:
%D - delay in samples
%Ts - sampling time
%
%Outputs:
%sys - transfer function of the filter
%
%Example:
% H = thiran2(4.4, 8000);
%               generate 5th order fractional delay filter delaying 4.4 samples 
%
% H = thiran2(8, 100);
%               generate pure time delay of 8 samples (.08 seconds)
%See Also: thiran
function sys = thiran2(D, Ts)
        N = ceil(D);
        if (N==D)
                sys = tf([1],[1 zeros(1,N)],Ts);
        else
                a =
(-1).^(1:N).*bincoeff(N,1:N).*prod((D-N+[0:N]'*ones(1,N))./(D-N+(1:N)+[0:N]'));
                sys = tf([a(N:-1:1) 1],[1 a],Ts);
        end
end




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/patch/?8215>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]