[英]How can i generate gaussian random process using matlab?
How can i generate Gaussian random process using Matlab with zero mean and unit variance ? 如何使用均值为零和单位方差的Matlab生成高斯随机过程?
Gaussian random variable can be implemented by 高斯随机变量可以通过
w=(1/sqrt(2*pi))*exp(-(t.^2)/2); w =(1 / sqrt(2 * pi))* exp(-(t。^ 2)/ 2);
but what about Gaussian random process ? 但是高斯随机过程呢?
If the Gaussian process is white (no correlation between samples at different instants), just use 如果高斯过程为白色 (不同时刻的样本之间没有相关性),则使用
w = randn(1,n);
where n
is the desired number of samples. 其中n
是所需的样本数。
If you need to introduce correlation between samples (that is, the values at different instants are correlated), the usual approach is to generate a white Gaussian process and then apply a low-pass filter (using conv
or filter
). 如果需要在样本之间引入相关性(也就是说,不同时刻的值是相关的),通常的方法是生成白色高斯过程,然后应用低通滤波器(使用conv
或filter
)。 The autocorrelation of the process is determined by the filter shape. 过程的自相关由滤波器形状决定。
For example, 例如,
w = randn(1,500);
y = conv(w,ones(1,100)/10,'same'); %// apply a simple low-pass filter
plot(w)
hold on
plot(y,'r')
You can see that the filtered signal (red) has smoother time variations, because of the (auto)correlation introduced by the filter. 您可以看到,由于滤波器引入的(自)相关性,因此滤波后的信号(红色)具有更平滑的时间变化。
A random Gaussian process with specified correlation length(cl) and RMSE -height(hRMSE) can be generated by passing a white noise with mean 0 and standard deviation hRMSE through a Gaussian filter g=exp(-(x.^2)/(cl^2/2))
. 通过将均值为0和标准偏差hRMSE的白噪声通过高斯滤波器g=exp(-(x.^2)/(cl^2/2))
。
Furthermore, you can find the Matlab code under the below link: http://www.mysimlabs.com/matlab/surfgen/rsgeng1D.m 此外,您可以在以下链接下找到Matlab代码: http : //www.mysimlabs.com/matlab/surfgen/rsgeng1D.m
Which has been transcribed below: 转录如下:
function [f,x] = rsgeng1D(N,rL,h,cl)
%
% [f,x] = rsgeng1D(N,rL,h,cl)
%
% generates a 1-dimensional random rough surface f(x) with N surface points.
% The surface has a Gaussian height distribution function and a Gaussian
% autocovariance function, where rL is the length of the surface, h is the
% RMS height and cl is the correlation length.
%
% Input: N - number of surface points
% rL - length of surface
% h - rms height
% cl - correlation length
%
% Output: f - surface heights
% x - surface points
%
% Last updated: 2010-07-26 (David Bergström).
%
format long;
x = linspace(-rL/2,rL/2,N);
Z = h.*randn(1,N); % uncorrelated Gaussian random rough surface distribution
% with mean 0 and standard deviation h
% Gaussian filter
F = exp(-x.^2/(cl^2/2));
% correlation of surface using convolution (faltung), inverse
% Fourier transform and normalizing prefactors
f = sqrt(2/sqrt(pi))*sqrt(rL/N/cl)*ifft(fft(Z).*fft(F));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.