hello all
please can ou help me out adding a noise signal to my system.
i tried adding a sinus function , but i would like to add a random noise signal rather than the sinus function. I'm running simulation from 1 to 3000
if k>1000 & k<2000
dk(k)=sin(12*k*pi*ts);
x=A*x+B*u(k)+B*dk(k);
else
dk(k)=0;
x=A*x+B*u(k);
end
Thank you so much
Best regards

2 件のコメント

chris matthew
chris matthew 2020 年 3 月 14 日
移動済み: DGM 2023 年 3 月 4 日
how to add noise to audio not for signal
Image Analyst
Image Analyst 2020 年 3 月 14 日
移動済み: DGM 2023 年 3 月 4 日
What does that mean? Audio IS a signal. You can't add noise to audio without adding it to the signal that defines the audio waveform.

サインインしてコメントする。

回答 (6 件)

Thorsten
Thorsten 2015 年 5 月 20 日

2 投票

x = linspace(-2*pi, 2*pi);
plot(sin(x) + 0.5*rand(size(x)))

6 件のコメント

lady bird
lady bird 2015 年 5 月 20 日
編集済み: lady bird 2015 年 5 月 20 日
Thank you Thorsten for your answer. this will create a noisy sinus function. but i'd like rather a noisy signal which doesn't have to be a sinus funtion, may be a white noise signal. but i dont know how to do that.
Regards
Thorsten
Thorsten 2015 年 5 月 20 日
編集済み: Image Analyst 2020 年 2 月 12 日
noisy_signal = rand(1, 100); % Create noise-only signal.
% Now add the noise-only signal to your original noise-free signal to create a noisy signal.
noisy_signal = noise_free_signal + amplitude * rand(1, length(noise_free_signal));
% Adjust amplitude to control the amount of noise.
Tuhin Choudhury
Tuhin Choudhury 2020 年 2 月 12 日
編集済み: Image Analyst 2020 年 2 月 12 日
Hi Thorsten,
For your example:
x = linspace(-2*pi, 2*pi);
plot(sin(x) + 0.5*rand(size(x)))
I wonder what happens when your sin(x) has a very small magnitude (of the scale 10^(-5)). I am guessing the noise would not be scaled in that case leading to 10^6 highly amplified 'noisy signal'.
One way is to manually scale the noise w.r.t the input signal. However, for a signal with largely varying amplitude, what would be the workaround?
Thanks!
Image Analyst
Image Analyst 2020 年 2 月 12 日
Tuhin, you can have the amplitude vary with the signal amplitude if you want. For example
% Create noise-only signal.
noisy_signal = rand(size(noise_free_signal));
% Create an amplitude for that noise that is 10% of the noise-free signal at every element.
amplitude = 0.1 * noise_free_signal;
% Now add the noise-only signal to your original noise-free signal to create a noisy signal.
% Be sure to use .*, not *, so that you do element-by-element multiplication.
noisy_signal = noise_free_signal + amplitude .* rand(size(noise_free_signal));
% Adjust amplitude to control the amount of noise.
Now the noise - the max possible noise amplitude - will vary according to the noise-free signal amplitude. Of course since it's noise, the noise won't always be the max possible, it will be less, but it could potentially get that high.
Tuhin Choudhury
Tuhin Choudhury 2020 年 3 月 16 日
編集済み: Tuhin Choudhury 2020 年 3 月 16 日
Hi,
Thanks. This would be more of a flexible scaling of the noise w.r.t the input signal.
BR- Tuhin
Enac
Enac 2024 年 10 月 10 日
Hi,
This is a great solution. I want to point a subtle improvement. Using this algorithm you would end up with a noisy signal that is always above the original one. This is because rand() gives random numbers ranging from 0 to 1.
Usually, when you want to add noise to a given data you want the noisy function to be centered in the original. To do so you just need to generate random numbers going from -1 to 1. Simply replace
rand(size(noise_free_signal))
with
2*(rand(size(noise_free_signal))-0.5)

サインインしてコメントする。

Image Analyst
Image Analyst 2015 年 5 月 20 日

1 投票

So just use rand() instead of sin().

4 件のコメント

lady bird
lady bird 2015 年 5 月 20 日
i've been reading about this. and i'd like to add a white noise signal. but i really dont know how to do that.
moreover if i have to use the rand() fct you proposed what shall i put between parantheses?
thanks
regards
Image Analyst
Image Analyst 2015 年 5 月 20 日
Try it this way:
% Make up some parameters to get sample data
numElements = 3000; % Whatever...
B = 1; % Whatever...
A = 1; % Whatever...
u = ones(1, numElements); % Whatever...
x = 7 * ones(1, numElements); % Whatever...
% Main code here:
x = A * x + B * u;
% Add noise only between elements 1000 and 2000
noiseSignal = rand(1, numElements);
x(1001:1999) = x(1001:1999) + B * noiseSignal(1001:1999);
Prajakta Yeola
Prajakta Yeola 2017 年 10 月 29 日
Can we use the same code if audio signal is .wav file? i.e. if x is a .wav file
Image Analyst
Image Analyst 2017 年 10 月 29 日
Sure, just figure out the amplitude and add it
yNoisy = yOriginal + amplitude * rand(1, length(yOriginal));

サインインしてコメントする。

KL
KL 2015 年 5 月 20 日

0 投票

Did you check the gaussian noise function?

2 件のコメント

lady bird
lady bird 2015 年 5 月 20 日
i found a awgn function but i dont know how to use it in my case?
KL
KL 2015 年 5 月 20 日
There's a difference between wgn() and awgn(). With the latter, you add noise throughout the whole range. I understand you want to add noise between certain time intervals. So in this case, I would suggest to use wgn(). At the moment I do not have the toolbox to use this function. Anyhow you shall use this function to calculate the noiseSignal variable according to @Image Analyst's code.

サインインしてコメントする。

Aparna Gupta
Aparna Gupta 2017 年 6 月 21 日

0 投票

Can anyone please help me with the code to add awgn noise to an eeg signal,which i have taken from a database and the file is of .mat type?

2 件のコメント

Image Analyst
Image Analyst 2017 年 6 月 21 日
Yes, probably. You can post the code in a new question.
Alper
Alper 2025 年 3 月 11 日
xn=awgn(x,20), SNR=20 dB

サインインしてコメントする。

Mohammad Sohail Khan
Mohammad Sohail Khan 2017 年 11 月 3 日
編集済み: DGM 2023 年 3 月 4 日

0 投票

t = 0:pi/100:40;
x = cos(pi/10*t)+0.5*randn(size(t));
plot(t,x)
Then you know where pi/2, 3pi/4 etc are.
Adewale Obaro
Adewale Obaro 2018 年 9 月 24 日
編集済み: DGM 2023 年 3 月 4 日

0 投票

N = 1000;
t = 0:1/N:2;
x = sin(2*pi*5*t);
Noise = x + randn(1,N)';
plot(t,Noise);
title('Noise in the Amplitude interval (0,0,1,0)');
ylabel('Amplitude [m]')
xlabel('Time [s]')

カテゴリ

タグ

質問済み:

2015 年 5 月 20 日

コメント済み:

2025 年 3 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by