How do I change the amount of noise I want to add to a signal?

2 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Krishna Zanwar
Krishna Zanwar il 1 Mar 2019
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

Categorie

Scopri di più su Audio Processing Algorithm Design in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by