How do I change the amount of noise I want to add to a signal?
2 次查看(过去 30 天)
显示 更早的评论
I have a clean signal from a wav file (of length y) and am trying to add noise to it to test a filter. The amplitude of the signal ranges from -1 to +1 so I have added noise that ranges between -1 and +1. To create the noise I have used a random number generator. However this fills the entire 'noise' matrix with values when all I want is every tenth or 20th value (e.g. for 10% or 5% noise) to be noisy and the rest of the elements in the noise matix to be zero.
noise = zeros(size(y));
n = 3; %number of decimal places in noise elements(below)
noise = randi([-1,1]*10^n,[size(y),1])/10^n;%creates noise between -1 and +1
noisySignal = y + noise; %y is clean signal, noise is what I've generated
Any ideas on how to achieve this? Thanks
0 个评论
回答(1 个)
Krishna Zanwar
2019-3-1
One method to do it is:
>> noise = randi([-10,10]*10^n,[20,1])/10^n
>> for i=1:size(noise)
>> if noise(i)>9
>> b(i)=noise(i)-9;
>> elseif noise(i)<-9
>> b(i)=noise(i)+9;
>> else
>> b(i)=0;
>> end
>> end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!