# Example of wavelet analysis of a surface

**URL:** <https://discourse.julialang.org/t/example-of-wavelet-analysis-of-a-surface/128050>\
**Category:** General Usage\
**Tags:** wavelets\
**Created:** [April 14, 2025, 8:23am UTC](https://discourse.julialang.org/t/example-of-wavelet-analysis-of-a-surface/128050 "2025-04-14T08:23:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Post date:** [April 14, 2025, 8:23am UTC](https://discourse.julialang.org/t/example-of-wavelet-analysis-of-a-surface/128050/1 "2025-04-14T08:23:33Z")

</div>

Dear all,

I would like to analysis images of surface with variable roughness in space. In practice, I would like to quantify the roughness of signals and report it on 2D maps (in the original spatial coordinates). It seems that a discrete wavelet analysis could be the ideal tool for this. If I understand well, I could report the spatial distribution of energy for different frequencies… (I am a newbie on that topic)

Does anyone know an example that does such type of analysis using Julia-based tools?  
It looks like it could be done with Wavelets.jl but I failed at finding a detailed example/tutorial.

Here’s an example of a synthetic signal that may be relevant. I would expect that a wavelet analysis will be able to detect energy in high frequency range in the upper right region. And energy at low frequency in the lower-left region.

Is Wavelets.jl the appropriate tool to carry out such analysis? Is there a tutorial that I could use to get started with this?  
(If not I’d be happy to progress on this example and then contribute to the docs)

```julia
    # Synthetic signal
    nx, ny = 128, 150  
    x = LinRange(0, 1.0, nx)
    y = LinRange(0, 1.0, ny)

    # Create a low frequency part in the the upper-right region
    k = (5., 10) # Wavenumbers
    shift = (0.75, 0.75) # Shift
    gauss = @. exp(-((x .- shift[1]).^2 + (y' .- shift[2]).^2) / 0.1) # Gaussian function for varying energy
    signal_HR = @. gauss * (sin(2π * k[1] * x) + cos(2π * k[2] * y'))

    # Create a low frequency part in the the lower-left region
    k = (2., 2) # Wavenumbers
    shift = (0.25, 0.25) # Shift
    gauss = @. exp(-((x .- shift[1]).^2 + (y' .- shift[2]).^2) / 0.1) # Gaussian function for varying energy
    signal_LR = @. gauss * (sin(2π * k[1] * x) + cos(2π * k[2] * y'))

    # Total signal
    signal = signal_LR .+ signal_HR

```

edit: added the image corresponding to the test signal below

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/3/73f32122ff23021482b04eea4c0e6eb8f6f2a97a.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 16, 2025, 12:02pm UTC](https://discourse.julialang.org/t/example-of-wavelet-analysis-of-a-surface/128050/3 "2025-04-16T12:02:05Z")

</div>

This [quick guide](https://www.mitutoyo.com/webfoo/wp-content/uploads/1984_Surf_Roughness_PG.pdf) to surface roughness measurements is quite clear and defines roughness profiles using wavenumber cutoffs. Is it applicable?

---

<div class="post-metadata">

**Author:** ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Post date:** [April 17, 2025, 11:26am UTC](https://discourse.julialang.org/t/example-of-wavelet-analysis-of-a-surface/128050/4 "2025-04-17T11:26:41Z")

</div>

Thanks, it’s indeed a useful resource, I didn’t know the distinction between roughness and waviness.  
I would still like to analyse the data maps using 2D wavelet analysis. I have tried GPT and Claude but none of them seem to know how to operate Wavelets.jl 😃

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [April 17, 2025, 11:49am UTC](https://discourse.julialang.org/t/example-of-wavelet-analysis-of-a-surface/128050/5 "2025-04-17T11:49:48Z")

</div>

Another common method to analyse roughness is variogram analysis. You could compute the `DirectionalVariogram` along directions `(1, 0)` and `(0, 1)` and then derive properties from the resulting curves.

I explain the concept in this video:

[![](https://global.discourse-cdn.com/julialang/original/3X/5/2/527570c122e313ab55ca131e727713aeb7adfd41.jpeg "GeoStats jl - Tutorial 04 - Variography game") ](https://www.youtube.com/watch?v=z8tZ6qIt9Fc)

The “behavior near the origin” is what you are after.
