フィルターのクリア

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

3 ビュー (過去 30 日間)
Samuel Snell
Samuel Snell 2019 年 2 月 25 日
回答済み: Krishna Zanwar 2019 年 3 月 1 日
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

回答 (1 件)

Krishna Zanwar
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

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by