File Exchange

image thumbnail

Surface generator: artificial randomly rough surfaces

version (7.27 KB) by Mona Mahboob Kanafi
Generates randomly rough fractal surfaces with different fractal (Hurst) parameters


Updated 19 Dec 2016

View Version History

View License

This code generates artificial randomly rough isotropic surfaces. These surfaces could be useful for simulating surface roughness or topographies from nanometre features of engineering surfaces to large-scale topography of mountains, terrains or landscapes. The code is based on simulating the surface topography/roughness by means of fractals. It uses the Fourier concept (specifically the power spectral density) for surface generation.
There are two options for surface generation, either the generated surface has a roll-off region or without a roll-off region. If you are not familiar with the concept of roll-off, refer to the uploaded image for this code.
For the code you need 5 inputs (with no roll-off region), or then 6 inputs (including roll-off wavevector). These inputs are:

1- root-mean-square roughness (Rq), i.e. standard deviation of surface heights (sigma σ)
2- Hurst exponent (H), which is related to the fractal dimension of a surface topography D=3-H. For example, a Brownian surface roughness has H= 0.5. The parameter H can take values between 0 and 1.
3- Lx, which is the length of final topography/image in x direction (it could take any values from nanometre to hundreds of metres)
4- m, which is number of pixels in the x direction of final topography/image
5- n, which is number of pixels in the y direction of final topography/image
6- (OPTIONAL INPUT) qr, which is the roll-off wavevector (check uploaded image for its meaning)

Two examples of generated surfaces:

[z , PixelWidth, PSD] = artificial_surf(1e-2, 0.8, 0.1, 512 , 512);
Generates a surface named z with standard deviation of 1 cm, hurst exponent of 0.8 (i.e. fractal dimension of 2.2), length of final image is 10 cm. It generates a square image with 512 data points in x and y direction. The final resolution (i.e Pixel Width) equals Lx/m = 195.3 micron.

[z , PixelWidth, PSD] = artificial_surf(1e-3, 0.8, 0.1, 1024, 512,1000);
Generates a surface named z with standard deviation of 1mm, Hurst exponent of 0.8 (i.e. fractal dimension of 2.2), length of final image is 10 cm. It generates a rectangular image with 1024 data points in x direction and 512 data points in y direction. The surface has a roll-off region at qr = 1000 (1/m), which equals to a wavelength lambda_r = (2*pi)/qr = 6.3 mm. The final resolution (i.e Pixel Width) equals Lx/m = 97.7 micron.

- By increasing m and n (don’t go higher than 2048 on a normal computer) or reducing Lx, you can generate surfaces with higher resolution.

- The surface is generated by its surface roughness power spectrum. This data is stored in the structure named PSD. If interested, for instance, you can check the analysis by comparing this PSD with the results you get by applying power spectral method on generated surface:

Radially Averaged Surface Roughness Power Spectrum (PSD)

Please let me know, if you have any problems or there is a bug!

Cite As

Mona Mahboob Kanafi (2021). Surface generator: artificial randomly rough surfaces (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (22)

Dongwhan Min

Adam Browse

Hi, I'm trying to use this for school and I dont know how to. I've copied in the suggested 5 or 6 values and I'm getting an error asking me to check for multiplication signs and other things. I'm new to MATLAB so any help is appreciated. Thanks

Marius Reinecker

Elijah Uche

Hi Mona,
Please I would like to be able to obtain the underlying equations and maths on which this rough surface model was built on so I could fully appreciate and understand how it works


Can I use this function if only the RMS slope is known?

Elijah Uche

Please how do I obtain correlation length from my PSD
Any ideas would be appreciated

Elijah Uche

How do I integrate dielectric constants into my rough surface model..I am looking at rough surface model for a soil surface and want to understand how the dielectric constants like permittivity, conductivity, and permeability interact with this model.
Kindly assist.

Elijah Uche

Hi Mona,
Thank you for your function.
Please I would like to ask for the relationship between C and q as shown on the upper side of your plot.
I could not replicate the graphs (3 at the top)
Also, how do I do the PSD thingy? tried using surf or plot3 and still couldn't get it... kept getting error messages...

David Beattie

Just thought I'd point out in response to Seok's comment. The code is correct with -2 * (H+1) as can be shown in the following paper: Müser, Martin H., Wolf B. Dapp, Romain Bugnicourt, Philippe Sainsot, Nicolas Lesaffre, Ton A. Lubrecht, Bo NJ Persson et al. "Meeting the contact-mechanics challenge." Tribology Letters 65, no. 4 (2017): 118.


Is there a way to convert the output to integers and still have the desired PSD ?

Seok Joon Kwon

Thanks for the code. There is an error for H.
2*(H+1) -> 2*H + 1


Marc Ng

I am not able to see the surface roughness model when I run this function, does anyone have advice on how to display the surface?

Guangzhi XU

For anyone interested in some maths regarding what's going on in the code, give a read of this paper: Jacobs, Tevis D B and Junge, Till and Pastewka, Lars, 2017: Quantitative characterization of surface topography using spectral analysis. Surface Topography: Metrology and Properties. It basically explains everything.
@Saipraneeth Those lines are computing a scaling factor so the resultant random surface has the desired RMS height. We need this because in constructing the PSD using the power law, the constant C0 (see the paper) is unknown, so the code used C0=1, which would give a RMS height of some other value.

zhibo sun

thanks a lot ,its works well. Did u use the ifft algrorithm to generate this result? Would u like to share some docs about ur algrorithm?

Guangzhi XU

Hi. This is quite cool. Could you give a reference of this method? If I want to use it in my work, how should I cite it?

Ari Tuononen

zhimeng yang

Hi, thank you very much for this code. This is really help for me. By the way, can I get an anisotropic rough surface through its PSD?


thanks for this.
how can i plot the surface, like in your image?

Fang Lei


Hi, thanks for this. This is hugely helpful for me. I have a few doubts. What does the following piece of code do and why are we doing this?

RMS_F2D = sqrt((sum(sum(Cq)))*(((2*pi)^2)/(Lx*Ly)));
alfa = sigma/RMS_F2D;
Cq = Cq.*alfa^2;

Other thing is, if you could share your notes which this code is based on would be really helpful. Thanks.

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!