< 7th term

Recovery from Fourier expansion

Last update on the 29th of October, 2019

Here I study recovery quality of a function after fourier expansion and application of noise and filtration. The function imitates 1-D distribution of molecular electron density. Main results are collected in Table 1.

Table 1. Main results.
Harmonic set Resolution Completeness F noise φ noise Recovery quality
0-1 30 Å 100% 0% 0% Bad
0-13 30/13 Å 100% 0% 0% Medium
0-26 30/26 Å 100% 0% 0% Good
0-40 30/40 Å 100% 0% 0% Excellent
0-1 30 Å 100% 20% 20% Bad
0-13 30/13 Å 100% 20% 20% Medium
0-26 30/26 Å 100% 20% 20% Medium
0-40 30/40 Å 100% 20% 20% Medium
2-40 1.0 Å 96.55% 0% 0% Good
2-17,22-40 1.7 Å 94.12% 0% 0% Good
2-40,50 1.0 Å 96.55% 0% 0% Good

Function generation

I generated sample electron density function with compile-func.py -g 30,3,3+40,3,4.3+2,3.5,6.5+30,3,7.5. The image of the function is presented in Fig. 1.

Fig. 1. Generated function.

Excellent recovery

The Fourier expansion was applied to the function with no noise on amplitudes and phases. Excellent recovery was achieved at the first 40 harmonics of Fourier series (Figs. 2, 3).

Fig. 2. Excellent recovery at 40 harmonics.
Fig. 3. Recovery process.

Noise modelling

20% noise was applied on amplitudes and phases while performing Fourier expansion. Recovery of the function from noisy Fourier expansion achieved medium quality at the first 40 harmonics (Figs. 4, 6). Solid peaks are quite distinguishible from noise but not the small peak (Fig. 5).

Fig. 4. Recovery after noise application.
Fig. 5. Noisy recovery alongside regular recovery.
Fig. 6. Noisy recovery process.

Incomplete set of harmonics

No starter harmonics

Removal of the first two harmonics hasn't almost affected recovery quality: all initial peaks are still distinguishable from the background (Fig. 7).

Fig. 7. No starter harmonics alongside full set of harmonics.

No middle harmonics

Further removal of some middle harmonics has greatly affected peak recovery (Fig. 8).

Fig. 8. No starter and middle harmonics alongside full set of harmonics.

Plus distant harmonic

Addition of the 51st harmonic after removal of the first two harmonics hasnt' rescued imbalanced recovery of the function (Fig. 9).

Fig. 9. No starter and plus distant harmonics alongside full set of harmonics.

Resolution criterion

Resolution of the incomplete set of harmonics is defined by the researcher. First, I developed a function that calculates the completeness of the incomplete set of harmonics at the given resolution.

A python function to find completeness of the set at given resolution.
def calc_completeness(observed, full, res, length):
    """Calculates completeness of set of harmonics.
    Args:
        observed (np.ndarray): array with serial numbers of observed harmonics.
        full (np.ndarray): array with serial numbers of full set of harmonics.
        res (int, float): resolution at which calculate the completeness.
        length (int, float): length of segment at which harmonics are defined.
    Returns:
        (int, float) completeness of observed set of harmonics
        at given resolution.
    """
    total = np.sum((length / full) > res)
    detected = np.sum((length / observed) > res)
    if total != 0:
        return detected / total
    return 0

Completenesses of the three incomplete sets of harmonics are generally desceneding functions of the resolution (Figs. 10-12).

Fig. 10. Completeness of no starter set.
Fig. 11. Completeness of no middle set.
Fig. 12. Completeness of plus end set.

I propose a criterion of the resolution of the incomplete set of harmonics: the lowest resolution with the greatest completeness. Derieved resolutions for the three incomplete sets of harmonics are shown in the Table 2.

A python function to find resolution with maximal completeness.
def max_completeness(completeness):
    """Finds resolution with maximal completeness.
    Args:
        completeness (list of tuples): list of 2-item tuples
            like `(resolution, completeness)`.
    Returns:
        (tuple) resolution with maximal completeness and
        corresponding completeness.
    """
    return max(completeness, key=lambda x: x[1])
Table 2. Resolution with maximal completeness.
Type Resolution Completeness
No starter 1.0 Å 96.55%
No middle 1.7 Å 94.12%
Plus distant 1.0 Å 96.55%