How to add 5% random Noise to the dataset in MATLAB
Show older comments
Hello Everyone, I hope you are doing well.
I have the dataset attached below. i want to add 5% random Noise to the dataset. How can i do that in matlab
Any help appreciated :)
2 Comments
Jan
on 26 Feb 2022
5% of what? Giving a percentage is a realtive expression. Then you have to define to which value this relation belongs to: 5% of maximum absolute value of the signal, 5% of each current value, 5% standard-deviation of the signal, 5% of the range, ...?
The actual data do not matters, but the definition of what you want to do is important.
Med Future
on 27 Feb 2022
Answers (1)
Image Analyst
on 27 Feb 2022
Did you try
s = load('datasetvalue.mat')
dataset = s.dataset;
[rows, columns] = size(dataset)
noise = 0.1 * dataset .* (rand(rows, columns) - 0.5);
noisyData = dataset + noise;
13 Comments
Med Future
on 27 Feb 2022
Image Analyst
on 27 Feb 2022
I thought you wanted +/- 5% for a range of 10%. I guess I was wrong. If not, adjust the 0.1 to whatever you want, like 0.05 to go +/- 2.5%
Med Future
on 27 Feb 2022
Not sure why that was confusing. Perhaps this code will illustrate it:
% Make an array with only values of 200 in it.
dataset = 200 * ones(1000000, 1);
[rows, columns] = size(dataset);
noise = 0.05 * dataset .* (rand(rows, columns) - 0.5);
noisyData = dataset + noise;
% Show distribution of values.
histogram(noisyData)
Note how the range of data goes from 195 to 205 as you wanted.
Med Future
on 1 Mar 2022
Med Future
on 1 Mar 2022
Jan
on 1 Mar 2022
rand() creates values from 0 to 1. Subtracting 0.5 replies values from -0.5 to 0.5. Multiplying it by 0.1 converts the values to the range from -0.05 to 0.05 - the 5% you are asking for.
Image Analyst
on 1 Mar 2022
@Med Future the noise is uniformly distributed for each individual value. But your data is not all the same value - there are lots of values, not just 200 only. Thus the value of the noise, even though always +/- 5%, will vary in absolute value. Therefore the overall noise will not be uniformly distributed.
Med Future
on 1 Mar 2022
Med Future
on 1 Mar 2022
Image Analyst
on 1 Mar 2022
You can create uniform data, such as
% Make an array with only values of 200 in it.
dataset = 200 * ones(1000000, 1);
otherwise, with the additive noise you have, that depends on the noise-free value, the noise will be uniform for each gray level one at a time but the overall distribution won't be uniform because your data is not uniform.
Med Future
on 1 Mar 2022
Image Analyst
on 1 Mar 2022
Yes, here is your data. It is not uniform. What is your definition of uniform?

You can make uniformly distributed data with rand, but if you're varying the mean value depending on another value (the pixel value in your data) then it's no longer uniform. You would have to have the mean and stardard deviation of the noise be not dependent on your signal values.
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!