Skip to content

This will help to change a certain time and frequency of a signal using wavelet transform

Notifications You must be signed in to change notification settings

mooxiu/random_WT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

random_WT

This will help to change a certain time and frequency of a signal using wavelet transform.

Original Signal

wavelets.py

This file is used to save wavelet functions. In my respository, the real part of Shannon Wavelet is used as an example. It can be used because real part of Shannon Wavelets are orthogonal[1]. According to Wikipedia of Shannon Wavelet, the expression of the real part of Shannon Wavelets can be written as:

$\psi^{(Sha)}(t)= sinc(\dfrac{t}{2}) \cdot cos(\dfrac{3\pi t}{2})$

In which $sinc(t):= \dfrac{sin \pi t}{\pi t}$.

The window function for wavelet can be written as:

$\psi_{s,\tau}(t)= \dfrac{1}{\sqrt{a}} \psi(\dfrac{t-\tau}{s})$

In which s is scale, $\tau$ is time shift. In the program file, they are written as sca and tshi. And the window wavelet function is represented as WShannon.

WShannon_sp is ???

TFwindow.py

This file is used to calculate the time and frequency window. For a given time shift and scale, we have to decide the center time $t^{*}$ and center scale $\omega ^{*}$, the RMS radius of time $\Delta_{\phi}$ and RMS radius of scale $\Delta_{\hat{\phi}}$. According to This slide, those parameters can be calculated by:

Time center: $t^{*}:= \dfrac{1}{||\phi||^2} \int_{-\infty}^{\infty} t |\phi(t)|^2 dt$

RMS radius of time: $\Delta_{\phi}:= \dfrac{1}{||\phi||}[\int_{-\infty}^{\infty}(t-t^{*})^2|\phi(t)|^2 dt]^{1/2}$

The center and radius for frequency is similar to time, they can be represented as:

Frequecny center: $\omega^{*}:=\dfrac{1}{||\hat{\phi}||^2} \int_{-\infty}^{\infty} \omega |\hat{\phi}(\omega)|^2 d\omega$

RMS radius of frequency: $\Delta_{\hat{\phi}}:= \dfrac{1}{||\hat{\phi}||}[\int_{-\infty}^{\infty} (\omega-\omega^{*})^2|\hat{\phi}(\omega)|^2 d\omega]$

In which, $||\phi||^2$ means the 2 norm of $\phi$, that is $||\phi||^2=\int_{-\infty}^{\infty}|\phi(t)|^2 dt$.

This file are using the formulas above to calculate the important parameters of time-frequency windows.

pycwt.py

This file can be divided into three parts, they are dealing with 1.wavelet transform, 2.phase calculation and randomization, 3. reconstruct of the signal.

wavelet transform

Continuous wavelet transform can cover the whole time and frequency domian, which is unpractical. As we are only considering change a certain part of time and frequency, we can only integrate in a certain range to find out the wavelet coefficient of certain time and frequency.

The wavelet coefficient for all time range and frequency range:

$W_{f}(b,a)=\dfrac{1}{\sqrt{a}}\int_{-\infty}^{\infty} f(t) \bar{\psi}\dfrac{t-b}{a}dt$

If we have assign a certain time and frequency and want to figure out its wavelet coefficient and the wavelet coefficient which is consecutive to it. We have to notice, that the two wavelet have the same frequency but different time shift. However, same frequency means that they have the same RMS time radius. Thus we assume that the distance of center time of two consecutive wavelets is twice the RMS time radius.

We assume to change the signal in scale of 1 and time shift of 10.003( this is to hope that in the later calculation we won't divide by 0).

$W_1$ and $W_2$ are two consecutive wavelet coefficients:

dt= 0.01
i=np.arange(0, 119, dt) 
W1=np.sum(signal[i]* wavelets.WShannon(i, tshi, sca)*dt)
W2=np.sum(signal[i]* wavelets.WShannon(i, tshi+2*TR, sca)*dt)

To find out the corresponding signal of these two parts, we need to do inverse wavelet transform of them. The inverse wavelet transform is :

$f(t)=\dfrac{1}{C_{\psi}}\int_{-\infty}^{\infty} db \int_{-\infty}^{\infty} \dfrac{1}{a^2}[W_{\psi}f(b,a)] \psi_{b,a}(t) da$

We need to calculate the $C_{\psi}$ which is a constant first. The presentation of $C_{\psi}$ is like:

$C_{\psi}= \int_{-\infty}^{\infty} \dfrac{|\hat{\psi}(\omega)|^2}{|\omega|} d\omega$

freq, Amp= TF.FT(wavelets.WShannon, tshi, sca)
dw=freq[1]-freq[0]
i=np.arange(0, len(Amp))
Cpsi=np.sum(Amp[i]**2/freq[i]*dw)

This is the Fourier Transform of the wavelet:

img

Then we can rewrite the presentation of inverse wavelet transform as:

$f(t)=\dfrac{W_{\psi}f(b,a)}{C_{\psi}} \int_{-\infty}^{\infty} db \int_{-\infty}^{\infty} \dfrac{\psi_{b,a}(t)}{a^2}da$

It's obvious that the left part of the sentence $\dfrac{W_{\psi}f(b,a)}{C_{\psi}}$is a constant. And we are going to integrate $\dfrac{\psi_{b,a}(t)}{a^2}$ over time shift $b$ and scale $a$.

In the pyfile $\dfrac{\psi_{b,a}(t)}{a^2}$ is marked as a new function WShannon_sp.

We calculate different time $t$ for the same time shift and frequency range. After that, we will get an array of $\int \int \dfrac{\psi_{b,a}(t)}{a^2} db da$.

We can find the pick up part of the signal.

The phase is assumed to be: $\theta= arctan (W_!/W_2)$, after randomizing the phase we get a new phase $\theta'$. The new wavelet coefficients will be $W_{1new}=\sqrt{W_1^2+W_2^2} \cdot sin\theta'$ and $W_{2new}=\sqrt{W_1^2+W_2^2} \cdot cos\theta'$.

And for the same reason, we will get the picked part of the signal after randomization.

[1]:Fundmentals of Wavelets, p118

About

This will help to change a certain time and frequency of a signal using wavelet transform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages