How to add 5% random Noise to the dataset in MATLAB

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

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.
@Jan 5% percent of the curent value. Like if we have value of 200 the range should be between 205 and 195

Sign in to comment.

Answers (1)

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

@Image Analyst its between 210 and 190. why you mutliply with 0.1?
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%
@Image Analyst dont understand your point.Can you please explain it again. If want 5% of noise like my value is 200 then i want to go to 205 and 195 what will do?
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.
@Image Analyst the code you share when i implement it on my dataset. the remaining value are not uniformly distrubeted . Can you please check what should i do to change it
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.
@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.
@Image Analyst then how can i make this data uniform?
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.
@Image Analyst have you seen my above data, the 51 column has different value did it uniformly distributed?
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.

Sign in to comment.

Categories

Products

Release

R2021b

Asked:

on 26 Feb 2022

Commented:

on 1 Mar 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!