Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
cf20a404
Commit
cf20a404
authored
Aug 13, 2015
by
Eddy Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test harness for random number generation routine to ensure statistical properties
parent
740456ae
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
307 additions
and
0 deletions
+307
-0
gaussian_noise.cpp
tools/RandomNumberVerification/gaussian_noise.cpp
+87
-0
generate_noise_csv
tools/RandomNumberVerification/generate_noise_csv
+0
-0
generated_noise.csv
tools/RandomNumberVerification/generated_noise.csv
+100
-0
noise_characteristics.m
tools/RandomNumberVerification/noise_characteristics.m
+41
-0
verify_noise_characteristics.m
...s/RandomNumberVerification/verify_noise_characteristics.m
+79
-0
No files found.
tools/RandomNumberVerification/gaussian_noise.cpp
0 → 100644
View file @
cf20a404
/****************************************************************************
*
* Copyright (C) 2015 PX4 Development Team. All rights reserved.
* Author: Eddy Scott <scott.edward@aurora.aero>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <limits>
#include <iostream> // not needed
#include <fstream> // not needed
using
namespace
std
;
float
generateGaussianNoise
(
float
mu
,
float
variance
)
{
/* Calculate normally distributed variable noise with mean = mu and variance = variance. Calculated according to
Box-Muller transform */
static
const
float
epsilon
=
std
::
numeric_limits
<
float
>::
min
();
//used to ensure non-zero uniform numbers
static
const
float
two_pi
=
2.0
*
3.14159265358979323846
;
// 2*pi
static
float
z0
;
//calculated normal distribution random variables with mu = 0, var = 1;
float
u1
,
u2
;
//random variables generated from c++ rand();
/*Generate random variables in range (0 1] */
do
{
u1
=
rand
()
*
(
1.0
/
RAND_MAX
);
u2
=
rand
()
*
(
1.0
/
RAND_MAX
);
}
while
(
u1
<=
epsilon
);
//Have a catch to ensure non-zero for log()
z0
=
sqrt
(
-
2.0
*
log
(
u1
))
*
cos
(
two_pi
*
u2
);
//calculate normally distributed variable with mu = 0, var = 1
float
noise
=
z0
*
(
variance
*
variance
)
+
mu
;
//calculate normally distributed variable with mu = mu, std = var^2
return
noise
}
int
main
(
int
argc
,
char
*
argv
[])
{
ofstream
fid
;
fid
.
open
(
"generated_noise.csv"
);
float
mu
=
atof
(
argv
[
1
]);
// Define the mean of the noise, for gaussian = 0
float
variance
=
atof
(
argv
[
2
]);
//Define the variance of the noise
int
num_runs
=
atoi
(
argv
[
3
]);
//Define number of runs
int
num_samples
=
atoi
(
argv
[
4
]);
srand
(
time
(
NULL
));
//Seed rand() function so same random variables are not calculated
cout
<<
"Desired Mean: "
<<
mu
<<
"
\n
"
;
cout
<<
"Desired Variance: "
<<
variance
<<
"
\n
"
;
cout
<<
"Desired number of runs: "
<<
num_runs
<<
"
\n
"
;
cout
<<
"Desired number of samples per run: "
<<
num_samples
<<
"
\n
"
;
for
(
int
j
=
0
;
j
<
num_runs
;
j
++
){
if
(
j
!=
0
){
fid
<<
"
\n
"
;
}
for
(
int
i
=
0
;
i
<
num_samples
;
i
++
){
fid
<<
generateGaussianNoise
(
mu
,
variance
)
<<
","
;
}
}
fid
.
close
();
return
0
;
}
tools/RandomNumberVerification/generate_noise_csv
0 → 100755
View file @
cf20a404
File added
tools/RandomNumberVerification/generated_noise.csv
0 → 100644
View file @
cf20a404
This diff is collapsed.
Click to expand it.
tools/RandomNumberVerification/noise_characteristics.m
0 → 100644
View file @
cf20a404
% ****************************************************************************
% *
% * Copyright (C) 2015 PX4 Development Team. All rights reserved.
% * Author: Eddy Scott <scott.edward@aurora.aero>
% *
% * Redistribution and use in source and binary forms, with or without
% * modification, are permitted provided that the following conditions
% * are met:
% *
% * 1. Redistributions of source code must retain the above copyright
% * notice, this list of conditions and the following disclaimer.
% * 2. Redistributions in binary form must reproduce the above copyright
% * notice, this list of conditions and the following disclaimer in
% * the documentation and/or other materials provided with the
% * distribution.
% * 3. Neither the name PX4 nor the names of its contributors may be
% * used to endorse or promote products derived from this software
% * without specific prior written permission.
% *
% * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
% * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
% * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
% * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
% * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
% * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
% * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
% * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
% * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
% * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
% * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% * POSSIBILITY OF SUCH DAMAGE.
% *
% ****************************************************************************/
%% Clean work environment
clear
all
close
all
clc
%% Load the generated noise values
noise_val
=
load
(
'generated_noise.csv'
);
for
i
=
1
:
size
(
noise_val
tools/RandomNumberVerification/verify_noise_characteristics.m
0 → 100644
View file @
cf20a404
% ****************************************************************************
% *
% * Copyright (C) 2015 PX4 Development Team. All rights reserved.
% * Author: Eddy Scott <scott.edward@aurora.aero>
% *
% * Redistribution and use in source and binary forms, with or without
% * modification, are permitted provided that the following conditions
% * are met:
% *
% * 1. Redistributions of source code must retain the above copyright
% * notice, this list of conditions and the following disclaimer.
% * 2. Redistributions in binary form must reproduce the above copyright
% * notice, this list of conditions and the following disclaimer in
% * the documentation and/or other materials provided with the
% * distribution.
% * 3. Neither the name PX4 nor the names of its contributors may be
% * used to endorse or promote products derived from this software
% * without specific prior written permission.
% *
% * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
% * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
% * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
% * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
% * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
% * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
% * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
% * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
% * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
% * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
% * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% * POSSIBILITY OF SUCH DAMAGE.
% *
% ****************************************************************************/
%% Clean work environment
clear
all
close
all
clc
%% Compile and run the noise cpp program
system
(
'g++ gaussian_noise.cpp -o generate_noise_csv'
);
mu_des
=
0.0
;
std_des
=
0.02
;
var_desired
=
sqrt
(
std_des
);
num_samples
=
10000
;
num_runs
=
100
;
if
exist
(
'generated_noise.csv'
,
'file'
)
system
(
'rm generated_noise.csv'
)
end
system
(
sprintf
(
'./generate_noise_csv %s %s %s %s'
,
num2str
(
mu_des
),
num2str
(
var_desired
),
num2str
(
num_runs
),
num2str
(
num_samples
)))
%% Load the generated noise values
noise_vals
=
load
(
'generated_noise.csv'
);
for
i
=
1
:
size
(
noise_vals
,
1
);
run_mean
=
mean
(
noise_vals
(
i
,:));
run_std
=
std
(
noise_vals
(
i
,:));
mean_array
(
i
)
=
run_mean
;
std_array
(
i
)
=
run_std
;
end
%%%%% Display statisitcs of means generated
max_mean
=
max
(
mean_array
);
min_mean
=
min
(
mean_array
);
max_std
=
max
(
std_array
);
min_std
=
min
(
std_array
);
figure
hist
(
mean_array
)
ylabel
(
'Occurances'
)
xlabel
(
'Mean Value'
)
title
(
'Histogram of mean values'
)
figure
hist
(
std_array
)
ylabel
(
'Occurances'
)
xlabel
(
'Std Value'
)
title
(
'Histogram of std values'
)
table
(
min_mean
,
mu_des
,
max_mean
,
min_std
,
std_des
,
max_std
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment