Code covered by the BSD License

# Sinusoidal Random Process

### Ashish Meshram (Meet) (view profile)

Modeling of Sinusoidal Random Process where either A,w, and phi can be random variable(s).

RandSine(t,option,varargin)
```function [x] = RandSine(t,option,varargin)
% This function implements sine waveform X(t) = A*sin(w*t + phi), where
% either A,w, and phi can be random variable.
%
% INPUT:
%             t = time row vector;
%             option = string specifying which parameter has to be random
%                      'phi'  for phase
%                      'A'    for Amplitude
%                      'w'    for Angular frequency
%                      'all'  for both Amplitude and phase, angular
%                             frequency being constant
%
% OUTPUT:
%             x = Output vector

% Implemented by ASHISH MESHRAM
%-----------------------------Version History-----------------------------%
%  1.0                Monday, May 20, 2013            Implemented
%-----------------------------Version History-----------------------------%

%---Checking input arguments
if nargin<1||isempty(t),error('Not enough input argument');end
if nargin<2||isempty(option),error('Not enough input argument');end
if nargin>4,error('More than enough input argument');end

n = length(t);%---Get size of time vector
x = zeros(n,n); %---Preallocating

switch option

case 'phi'%---x = RandSine(t,'phi',A,w);
if nargin<3||isempty(varargin{1})
A = 1;
else
A = varargin{1};
end
if nargin<4||isempty(varargin{2})
w = 1;
else
w = varargin{2};
end
phi = rand(size(t));
for ii = 1:length(phi)
x(ii,1:n) = A*sin(w*t + phi(ii));
end

case 'A'%---x = RandSine(t,'phi',w,phi);
if nargin<3||isempty(varargin{1})
w = 1;
else
w = varargin{1};
end
if nargin<4||isempty(varargin{2})
phi = 1;
else
phi = varargin{2};
end
A = rand(size(t));
for ii = 1:length(A)
x(ii,1:n) = A(ii)*sin(w*t + phi);
end

case 'w'%---x = RandSine(t,'phi',A,phi);
if nargin<3||isempty(varargin{1})
A = 1;
else
A = varargin{1};
end
if nargin<4||isempty(varargin{2})
phi = 1;
else
phi = varargin{2};
end
w = rand(size(t));
for ii = 1:length(w)
x(ii,1:n) = A*sin(w(ii).*t + phi);
end

case 'all'%---x = RandSine(t,'all',w); except for w
if nargin<3||isempty(varargin{1})
w = 1;
else
w = varargin{1};
end
A = rand(size(t));
phi = rand(size(t));
for ii = 1:length(A)
for kk = 1:length(phi)
x(ii,kk,1:n) = A(ii).*sin(w*t + phi(kk));
end
end

otherwise
error(strcat(['Option ','"',option,'"',' not defined']));
end

```