Visualization of wavelet

Leave a comment

Many wavelet does not have functional form, but defined by the MRA coefficient.

The visualization of wavelet can be done by using wavelet construction.

\displaystyle v_{j+1,k} = \sum_{n} g_0(k-2n)v_{j,n} + g_1(k-2n) w_{j,n}

For scaling function, we can define v_0 = {1} and w_0 = {0} .

\displaystyle v_{1,k} = \sum_{n} g_0(k-2n)v_{0,n} = g_0(k)

Similarly, the wavelet can be started with v_0 = {0} and w_0 = {1} .

\displaystyle v_{1,k} = \sum_{n} g_1(k-2n)w_{0,n} = g_1(k)

Then build by iteration,

\displaystyle v_{j+1,k} = \sum_{n} g_0(k-2n) v_{j,n}

From last post on the scaling coefficient, i calculated and plot the wavelet for m = 4.


we can see the wavelet becomes the Haar wavelet as the free parameter goes to 1. In fact, it becomes a shifted Haar wavelet when the free parameter goes to 0, as we can imagine.

When the free parameter is 0.683013, it is the Daubechies-2 wavelet. Notes that some people will absorbed a factor $latex 1/ \sqrt{2} $ into the coefficient, so that their free parameter is 0.683013/\sqrt{2} = 0.482963.

Orthonormal Scaling Coefficient

Leave a comment

A multi-resolution analysis is defined by scaling function and the corresponding wavelet. From the scaling relations

\displaystyle \phi_{j,k}(x) = \frac{1}{\sqrt{2}} \sum_{l} g_0(l) \phi_{j+1,2k+l}(x)

\displaystyle \psi_{j,k}(x) = \frac{1}{\sqrt{2}} \sum_{l} g_1(l) \phi_{j+1,2k+l}(x)

the scaling function and wavelet can be defined from the scaling coefficient g_0, g_1

The coefficients are constrained due to the properties of wavelet and scaling function.

\displaystyle \int \phi(x) dx = 1

\displaystyle \int \phi_{j,k}(x) \phi_{j,k'}(x) dx = \delta_{kk'}

\displaystyle \int \psi(x) dx = 0

\displaystyle \int \psi_{j,k}(x) \psi_{j,k'}(x) dx = \delta_{kk'}

\displaystyle \int \psi_{j,k}(x) \phi_{j,k'}(x) dx = 0

These properties lead to

\displaystyle \sum g_0(l) = 2

\displaystyle \sum g_1(l) = 0

\displaystyle \sum_{l,n} g_0(l) g_0(l+2n) = \begin{matrix} 2, & n=0 \\ 0, & else  \end{matrix}

\displaystyle \sum_{l,n} g_1(l) g_1(l+2n) = \begin{matrix} 2, & n=0 \\ 0, & else  \end{matrix}

\displaystyle \sum_{l,n} g_0(l) g_1(l+2n) = 0

The 3rd and 4th constrains requires the numbers of non-zero element in g_0, g_1 are even.

One of the solution is setting

g_1(k) = (-1)^k g_0 (1-k)

so that we don’t need to worry g_1 and the 4th constrain becomes the 3rd constrain, and the 5th constrain is always satisfied. Now, only the 1st, 2nd, and 3rd constrains are needed. This is equivalent to 1+m/2 equations with number of non-zero elements in g_0 is m.

m 1 + \frac{m}{2} Degree of Freedom
2 2 0
4 3 1
6 4 2
8 5 3

For size of 4, the solution is

\displaystyle g_0 = \left(a,  \frac{1-\sqrt{1+4a-4a^2}}{2},  1-a,  \frac{1+\sqrt{1+4a-4a^2}}{2}\right)

In fact, the coefficient for g_0 can be grouped as even and odd, so that

\displaystyle \sum g_0(2k) = \sum g_0(2k+1) = 1

and the constrain 3rd can lead to,

\displaystyle (\sum g_0(2k))^2 + (\sum g_0(2k+1)^2 = 2 ,

which is automatically fulfill.


Absolute polarization measurement by elastic scattering

Leave a comment

The magnitude of proton polarization can be measured by NMR technique with a reference. Because the NMR gives the free-induction decay signal, which is a voltage or current. For Boltzmann polarization using strong magnetic field and low temperature, the polarization can be calculated. However, when a reference point is not available, the absolute magnitude of proton polarization can be measured using proton-proton elastic scattering. The principle is the nuclear spin-orbital coupling. That creates left-right asymmetry on the scattering cross section.

Because of spin-orbital interaction:

V_{ls}(r) = f(r) \vec{l} \cdot \vec{s} ,

where f(r) is the distance function, \vec{l} is the relative angular momentum, \vec{s} is the spin of the incident proton. In the following picture, the spin of the incident proton can be either out of the plane (\uparrow ) or into the plan (\downarrow). When the proton coming above, the angular momentum is into the plane (\downarrow ). The 4 possible sign of the spin-orbital interaction is shown. We can see, when the spin is up, the spin-orbital force repulses the proton above and attracts the proton below. That creates an asymmetry in the scattering cross section.



The cross section is distorted and characterized using analysing power A_y. Analyzing power is proportional to the difference between left-right cross-section. By symmetry (parity, time-reversal) consideration, A_y = 1 + P sin(2\theta) (why?), in center of mass frame. In past post, the transformation between difference Lorentz frame. The angle in the A_y has to be expressed in lab angle. The cross section and A_y can be obtained from .

In scattering experiment, the number of proton (yield) is counted in left and right detectors. The yield should be difference when either proton is polarized. The yield is

Y(\theta, \phi) = L \epsilon \sigma_0 (1 + cos(\phi)A_y(\theta) P) ,

where L is the luminosity, \epsilon is the detector efficiency, \sigma_0 is the integrated cross-section of un-polarized beam and target of the detector, P is the polarization of either the target or beam. When both target and the beam are polarized, the cross section is

\sigma = \sigma_0 (1 + (P + P_T)A_y + P P_T C_yy),

where C_yy is spin-spin correlation due to spin-spin interaction of nuclear force.

Using the left-right yield difference, the absolute polarization of the target or the beam can be found using,

\displaystyle A_y P = \frac{Y_L - Y_R}{Y_L + Y_R} ,

where Y_L = Y(\phi =0) and Y_R = Y(\phi=\pi) .




Hard & soft thresholding

Leave a comment

In usual Fourier transform (FT), the filter is cut-off certain frequency.

This trick is also suitable for wavelet transform (WT). However, there could be some “features” located in high frequency scale (or octave) , a simply cut-off would remove these features.

If the signal to noise level is large, that means the noise has smaller amplitude than that the signal, we can use hard or soft thresholding, which zero any coefficient, which is after the FT or WT,  less then a threshold.

Lets X be the coefficient. The hard thresholding is

Y=\begin{cases} 0, & |X| <\sigma \\ X, & \mbox{else} \end{cases}


The soft thresholding is

Y = \begin{cases} 0, & |X| < \sigma \\ sign(X) f(|X|, \sigma), & \mbox{else} \end{cases}

A popular function

\displaystyle f(x, \sigma) = \frac{x - \sigma}{ X_{max} - \sigma } X_{max}



\displaystyle f(x, \sigma) = x - \sigma


Compiling Fortran-77 code in Ubuntu-16

Leave a comment

Fortran-77 is a very old code, who lives in 32-bit computer.

In Ubuntu-16, the compiler g++, gcc, or gfortran are “basically the same” (as far as I understand, correct me if I am wrong.) that they only support fortran-95.

In order to compile Fortran-77 code, I tried many way, but the only way is install g77 from external source, and add -m32 for the compiling flag.

The g77 compiler can be downloaded in here (I download from the web, If I violated some copy right, please let me know):

or, people can search in google by



people need to extract, change the mod of to be executable.

 tar -xzvf g77_x64_debian_and_ubuntu.tar.gz
 cd g77_x64_debian_and_ubuntu
 chmod +x ./


Somehow, you may face an error in apt-get, saying

Errors were encountered while processing:

you can remove that by

cd /var/lib/dpkg/info
sudo rm g77-3.4-doc*
sudo dpkg --remove --force-remove-reinstreq g77-3.4-doc

Thanks (here)

Hope it help. :)