Code covered by the BSD License  

Highlights from
PLL_mfile_cal

PLL_mfile_cal

by

 

15 Jan 2014 (Updated )

Phase-locked loop.m this is an mfile to calculate the same outputs of the PLL simulink block.

cumtrapzt(x,y,dim)
function z = cumtrapzt(x,y,dim)
%CUMTRAPZ Cumulative trapezoidal numerical integration.
%   Z = CUMTRAPZ(Y) computes an approximation of the cumulative
%   integral of Y via the trapezoidal method (with unit spacing).  To
%   compute the integral for spacing different from one, multiply Z by
%   the spacing increment.
%
%   For vectors, CUMTRAPZ(Y) is a vector containing the cumulative
%   integral of Y. For matrices, CUMTRAPZ(Y) is a matrix the same size as
%   X with the cumulative integral over each column. For N-D arrays,
%   CUMTRAPZ(Y) works along the first non-singleton dimension.
%
%   Z = CUMTRAPZ(X,Y) computes the cumulative integral of Y with respect
%   to X using trapezoidal integration.  X and Y must be vectors of the
%   same length, or X must be a column vector and Y an array whose first
%   non-singleton dimension is length(X).  CUMTRAPZ operates across this
%   dimension.
%
%   Z = CUMTRAPZ(X,Y,DIM) or CUMTRAPZ(Y,DIM) integrates along dimension
%   DIM of Y. The length of X must be the same as size(Y,DIM)).
%
%   Example: If Y = [0 1 2
%                    3 4 5]
%
%   then cumtrapz(Y,1) is [0   0   0    and cumtrapz(Y,2) is [0 0.5 2
%                          1.5 2.5 3.5]                       0 3.5 8];
%
%   Class support for inputs X,Y:
%      float: double, single
%
%   See also CUMSUM, TRAPZ, INTEGRAL.

%   Copyright 1984-2012 The MathWorks, Inc. 
%   $Revision: 1.15.4.7 $  $Date: 2012/09/25 21:43:11 $

%   Make sure x and y are column vectors, or y is a matrix.

perm = []; nshifts = 0;
if nargin == 3, % cumtrapz(x,y,dim)
  perm = [dim:max(length(size(y)),dim) 1:dim-1];
  y = permute(y,perm);
  [m,n] = size(y);
elseif nargin==2 && isequal(size(y),[1 1]) % cumtrapz(y,dim)
  dim = y; y = x;
  perm = [dim:max(length(size(y)),dim) 1:dim-1];
  y = permute(y,perm);
  [m,n] = size(y);
  x = 1:m;
else
  if nargin < 2, y = x; end
  [y,nshifts] = shiftdim(y);
  [m,n] = size(y);
  dim = nshifts + 1;
  if nargin < 2, x = 1:m; end
end
if ~isvector(x)
  error(message('MATLAB:cumtrapz:xNotVector'));
end
% Make sure we have a column vector.
x = x(:);
if length(x) ~= m
    error(message('MATLAB:cumtrapz:LengthXMismatchY',dim));
end

dt = repmat(diff(x,1,1),1,n);
z1 = cumsum(y(1:end,:),1);
z = [zeros(1,n,class(y)); dt.*z1(1:end-1,:)];

siz = size(y); siz(1) = max(1,siz(1));
z = reshape(z,[ones(1,nshifts),siz]);
if ~isempty(perm), z = ipermute(z,perm); end

Contact us