-
Notifications
You must be signed in to change notification settings - Fork 0
/
mvaddnrandom.m
61 lines (54 loc) · 1.59 KB
/
mvaddnrandom.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
54
55
56
57
58
59
60
61
function [noisespect]=mvaddnrandom(X,ampl,plots)
%MVADDRANDOM -- adds normally distributed random noise to spectra
%
% Usage:
% [noisespect] = mvaddnrandom(X,ampl,plots)
%
% Inputs:
% X is the input data matrix or vector
% ampl is the amplification of the noise (optional)
% plots if 1, plot input and output spectra
%
% Outputs:
% noisespect spectra with random noise added
%
% Description:
% This function adds normally distributed random noise to the input
% spectra. The noise is generated using the Matlab randn()
% function, with values chosen from a normal distribution with mean
% zero and variance one. To increase/decrease the noise, use the
% 'ampl' input.
%
% Copying:
% MVARTOOLS, Copyright (C) 1999-2001 Rune Mathisen <[email protected]>
% MVARTOOLS comes with ABSOLUTELY NO WARRANTY; for details type
% `mvwarranty'. This is free software, and you are welcome to
% redistribute it under certain conditions; type `mvcopying' for
% details. For more information on MVARTOOLS, type 'mvreadme'.
% $Id: mvaddnrandom.m,v 1.2 2001/12/04 09:03:38 rune Exp $
if (nargin == 1),
ampl = 1;
plots = 0;
elseif (nargin == 2),
plots = 0;
end
% find size of input spectra
[m,n]=size(X);
% generate random noise
noise = randn(m,n).*ampl;
% add random noise to spectra
noisespect=X + noise;
% plotting
if plots == 1,
wl = 1:1:n;
figure
subplot(2,1,1);
plot(wl,X,'b');
title('Original spectra');
axis tight
subplot(2,1,2);
plot(wl,noisespect,'r');
title('Noise added.');
axis tight
end
% end of mvaddnrandom