How to add gaussian noise using range of variances
6 次查看(过去 30 天)
显示 更早的评论
Hii experts i want to add gaussian noise using the randn function to a data set consists of 20 columns and 500 rows.Now i want to vary the variance(in the example 1.5) from 0.0015 to 1.5 and want to save the output in output_variancevalue.txt file for each variance value in separate text file( i think for loop is required) .can anybody suggest a solution. i am new to Matlab.Thanks
A = importdata('data.ascii');
A_gaussian = A + 1.5*randn(size(A));
dlmwrite('output_1.5.txt',A_gaussian,'delimiter','\t','precision',3)
0 个评论
回答(1 个)
Ameer Hamza
2020-9-11
Try something like this
A = importdata('data.ascii');
var_values = logspace(log10(0.0015), log10(1.5), 10); % values of variance are taken from this vector
for i = 1:numel(var_values)
A_gaussian = A + sqrt(var_values(i))*randn(size(A));
dlmwrite(['output_' num2str(var_values(i)) '.txt'], A_gaussian,'delimiter','\t','precision',3)
end
2 个评论
Ameer Hamza
2020-9-12
You may specify the var_values manually. For example,
var_values = [0.0015, 0.015, 0.15, 1.5];
By trying different values, you can see what is a good value.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!