-
Notifications
You must be signed in to change notification settings - Fork 7
/
MkSg_noise.m
53 lines (49 loc) · 1.4 KB
/
MkSg_noise.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function s = MkSg_Noise(whatDistribution,N,params)
% Returns a noisy time series
% Length N
% Sampled from a given distribution whatDistribution
% with defining parameters params
%-------------------------------------------------------------------------------
if nargin < 1 || isempty(whatDistribution)
whatDistribution = 'uniform';
end
if nargin < 2 || isempty(N)
N = 1000;
end
%-------------------------------------------------------------------------------
switch whatDistribution
case 'uniform'
s = rand(N,1);
case 'normal'
s = randn(N,1);
case 'beta'
% Uses the MATLAB Statistics Toolbox
% params specifies a two-component vector [a,b]
if nargin<3 || isempty(params), params = [1,1]; end
a = params(1);
b = params(2);
s = betarnd(a,b,N,1);
case 'exp'
% Uses the MATLAB Statistics Toolbox
% params specifies the mean parameter mu
if nargin<3 || isempty(params), params = 1; end
mu = params;
s = exprnd(mu,N,1);
case 'gamma'
% Uses the MATLAB Statistics Toolbox
% params specifies the gamma distribution parameters [a,b]
if nargin<3 || isempty(params), params = [1,5]; end
a = params(1);
b = params(2);
s = gamrnd(a,b,N,1);
case 'geo'
% Uses the MATLAB Statistics Toolbox
% params specifies the probability parameter p
if nargin<3 || isempty(params), params = 0.5; end
p = params;
s = geornd(p,N,1);
otherwise
disp('Invalid distribution specified');
s = NaN;
end
end