No BSD License  

Highlights from
timing

from timing by Byung Yoon Min
A timing error detector for Communication systems with simulink.

ti_det1(t,x,u,flag,thre)
% Institute For Advanced Engineering
% Communications and Electronics Laboratory
% Research Engineer
%
% Name : Byung Yoon Min
% E-mail : bymin@iae.re.kr
% 1999.2.25.
%
%-----------------------
% Timing Detector
%-----------------------
% Refer to : K.H. Mueller and M. Mueller, " Timing recovery in digital synchronous data receivers,"
%                IEEE Trans. Comun., vol COM-24, no. 5, May 1976.
%

function   [sys, x0] = ti_det1(t,x,u,flag,thre)

switch flag,
case 0
   [sys x0] = mdlInitializeSizes;   
case 2
   sys = mdlUpdates(t,x,u,thre);
   
case 3
   sys = mdlOutputs(t,x,u,thre);
   
case {1, 4, 9}
   sys = [];
   
otherwise
   error(['unhandled flag = ', num2str(flag)]);
end

function [sys, x0] = mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 3;
sizes.NumOutputs = 1;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 0;
%sys = simsizes(sizes);
sys = [0;sizes.NumDiscStates;sizes.NumOutputs;sizes.NumInputs;0;0];
x0 = zeros(sizes.NumDiscStates,1);

function sys =mdlUpdates(t,x,u,thre)

sys(2) = u(2);

if (u(2) > thre) & (x(2) ~= u(2))
   sam_v1=u(1);
   sys(1) = sam_v1;
      if ( sam_v1 >= 0.0)
         ak1 = 1.0;
      else
         ak1 = -1.0;
      end
   
      if (x(1) >= 0.0)
         ak2 = 1.0;
      else
         ak2 = -1.0;
     end
   sys(3) = ak2*sam_v1-ak1*x(1);
else
   sys(1) = x(1);
   sys(3) = x(3);
end


function sys = mdlOutputs(t,x,u,thre)

if (u(2) > thre) & (x(2) ~= u(2))
   sam_v1=u(1);
      if ( sam_v1 >= 0.0)
         ak1 = 1.0;
      else
         ak1 = -1.0;
      end
   
      if (x(1) >= 0.0)
         ak2 = 1.0;
      else
         ak2 = -1.0;
     end
   sys = ak2*sam_v1-ak1*x(1);
else
   sys = x(3);
end





Contact us at files@mathworks.com