File size: 1,734 Bytes
4f58ef1
 
 
 
 
 
 
 
 
 
3596592
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f58ef1
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np

def multipass_average(signal: np.ndarray, npts: int) -> np.ndarray:
    npts_tot = len(signal)
    # npass = npts_tot // npts
    signal_avg = np.zeros(npts)
    for i in range(npts):
        signal_avg[i] = np.average(signal[i:npts_tot:npts])
    return signal_avg

def multipass_average2(data: np.ndarray, npts: int) -> np.ndarray:
    # this function considers that back passes in the data array might be stored also sorted backwards (higher frq first)
    # for this function the whole data array is necessary (i.e. not only one column containing signal, but all columns incl.frequency)
    npts_tot = data.shape[0]    # total points
    npass = npts_tot // npts    # number of passes
    signal_avg_1 = np.zeros(npts)
    signal_avg_2 = np.zeros(npts)
    for i in range(npass):
        j0 = i * npts  # here we have to iterate trough each pass
        j1 = (i + 1) * npts  # defining the starting and ending index of the pass
        tmp_data = np.copy(data[j0:j1, 0:3])  # extract the corresponding pass data
        tmp_data = tmp_data[tmp_data[:, 0].argsort()]  # sort it by frequency containing in the 0-th column
        signal_avg_1 += tmp_data[:, 1]  # now averaging should happen correctly 
        signal_avg_2 += tmp_data[:, 2]  # in both cases sorted and reverse sorted frequencies
    return signal_avg_1 / npass, signal_avg_2 / npass

def rotate_data(ch_x, ch_y, ang):
    ang_rad = ang * np.pi / 180.
    cos_a = np.cos(ang_rad)
    sin_a = np.sin(ang_rad)
    r_x = ch_x[:] * cos_a + ch_y[:] * sin_a
    r_y = -1. * ch_x[:] * sin_a + ch_y[:] * cos_a
    return r_x, r_y

def frq_recalc(frq: np.ndarray, n_harmonic: int, inter_fr: float) -> np.ndarray:
    return frq[:] * n_harmonic + inter_fr