What is CWT/Scarogram?
Published: 2024-04-17 13:18:42

## 1. CWT/Scarogram
Scarogram is a 2-dimentional image created by applying CWT(Continous Wavelet Transform) to 1-dimentional signal.

・Scarogram
![Scarogram](https://storage.googleapis.com/zenn-user-upload/460c1323e466-20240414.png)


## 2. Wavelet Transform
### 2.1 Wavelet
What is wavelet? It is a function that take time as an argument. Generally, be represented as {% katex inline %} \Psi(t) {% endkatex %}.

Wavelet has a variety of types. Morlet is a famous one.
・Wavelet
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vtw5feyxi9ck5auh9x63.png)

To be a proper wavelet, function has to satisfy 2 main constraints.
1. Zero mean: {% katex %} \int^{+ \infty}_{- \infty} \Psi (t)dt = 0{% endkatex %}
2. Finite energy: {% katex %} \int^{+ \infty}_{- \infty} |\Psi(t)|^2 dt < \infty {% endkatex %}

Example, sin function not satisfy condition 2, because it has infinite energy.
You can think of those constraints as indicating a converging fanction with zero mean.

### 2.2 Adhust Wavelet
I use wavelet for this transfrom.

#### Morlet
From here on, I will use Morlet as an example.

・Morlet
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwg8cg018270m7ev6mxr.png)

When we adjust {%katex inline%}t{%endkatex%}, the morlet changes shape accordingly.
・{%katex inline%}(t - b){%endkatex%}
b = 2

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltgvu0ltezb66q67cr6x.png)

・{%katex inline%}(\dfrac{t}{a}){%endkatex%}
a = 0.5

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnq834t1d2tiipvgaay1.png)

Then, we can make various morlet by use {% katex inline %} \Psi(\dfrac{t-b}{a}) {% endkatex %},
b = -2, a = 0.25

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k93gywzy7y6si1mdexkr.png)

### 2.3 Wavelet Transform
Wavelet Transform create image that one axis represent frequency, and one another represent time  from signal.

・Wavelet Transform
{%katex%}y(t) \rightarrow T(t,f) {%endkatex%}

The right arrow represent Wavelet Transform, what is going on there? Let's check in below.

・Calculation 1
{% katex %} y(t) \cdot \Psi_{a,b}(t) {% endkatex %}
{% katex inline %}y{% endkatex %}: Be analyzed signal 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/46qm2esd255ylru5tfaw.png)

This calculation creates a ew function that shows how similar each function is. At every point, if the values of each function are close, the new

It represent similarity of two waves y(t) and Ψ. 


・Calculation 2
{% katex %} T(a,b) = \int^{+\infty}_{-\infty} y(t) \cdot \Psi_{a,b}(t) dt {% endkatex %}

This formula calculates the total area of overlap between the Morlet and the original formula, assuming that if the overlapped parts have the same sign, it is a plus, and if they have different signs, it is a minus.
In other words, it shows the degree of overlap between morlet and the original signal.

### 2.4 Imaginary part
Wavelet has a imaginary part. And as same with real part, T_i(a,b) is calculated by imaginary part.

### 2.5 Result of Transform
The T(a, b) is the result of WT.
T is a function representing the degree of matching between the Morlet wavelet and the original function.

If you change parameter b, T shows similarity between two functions in the time direction. It makes a one-dimensional wave show where there is a wave that has the same frequency as T (based on parameter a).

When you repeat the same process by changing parameter a, you can obtain various waves that show where each wave has the same frequency corresponding to parameter a.

After obtaining T(a,b) and T_i(a,b) in this way, obtain the square of their absolute value as power.
{% katex %} power = \sqrt{T(a,b)^2 + T_i(a,b)^2}^2 = T(a,b)^2 + T_i(a,b)^2  {% endkatex %}

When you get this far, all you have to do is color map the frequency components of each power and arrange them in time. And you'll get Scarogram.
It's same operation when you create spectrogram. 

It shows at what time in the original waveform a waveform with the same frequency component (varied by a) as the wavelet exists.

## summary
This time, I explained about CWT/Scarogram.
thank you for reading.

## Reference
(1) [Wavelets: a mathematical microscope](https://www.youtube.com/watch?v=jnxqHcObNK4), Artem Kirsanov