how to generate a Gaussian white noise with a mean of zero inside ODE function

39 ビュー (過去 30 日間)
SALEH ALHUMAID
SALEH ALHUMAID 2020 年 5 月 2 日
回答済み: Sai Sri Pathuri 2020 年 5 月 18 日
Hi,
I am new to the matlab, I am trying to generate a Gaussian white noise with a mean of zero ranging from -0.03 to 0.03 like the attached photo, inside an ODE function.
I was using
White_noise= wgn(1,1,0);
but i don't think it is correct! should i used randn istead?
my code
function dydt = surfeq(t,y)
no=0.1;
n00=0.011;
v=80*1000/3600;
gq=1024;
white_noise= wgn(1,1,0);
%noise = rand(1);
x = 2*pi*no*sqrt(gq*v)*white_noise;
dydt = -2*pi*n00*v*y(1)+x;

回答 (2 件)

Sai Sri Pathuri
Sai Sri Pathuri 2020 年 5 月 5 日
You are using correct function to generate white gaussian noise samples. However, you may not create white gaussian noise within a given range. As a workaround, you may follow below procedure.
% Create a vector of wgn samples
white_noise = wgn(1000,1,0);
j = 1;
% Get the samples within required range
for i = 1:1000
if white_noise(i) >= -0.03 && white_noise(i) <= 0.03
white_noise_inRange(j) = white_noise(i);
j = j+1;
end
end
  1 件のコメント
SALEH ALHUMAID
SALEH ALHUMAID 2020 年 5 月 16 日
thanks for your help, but when I plot the (white_noise_inRang) i get few results, only 29 datas?

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


Sai Sri Pathuri
Sai Sri Pathuri 2020 年 5 月 18 日
Try to use more samples (n) of white_noise such that you get desired number of samples within range -0.03 to 0.03
white_noise = wgn(n,1,0);

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by