Reputation: 29
How can i generate Gaussian random process using Matlab with zero mean and unit variance ?
Gaussian random variable can be implemented by
w=(1/sqrt(2*pi))*exp(-(t.^2)/2);
but what about Gaussian random process ?
Upvotes: 0
Views: 10349
Reputation: 51
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))
.
Furthermore, you can find the Matlab code under the below link: 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));
Upvotes: 2
Reputation: 112749
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.
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
). 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.
Upvotes: 3