Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Replace numpy rfft with method closer to uncertainty_DFT methods? #99

Open
eichstaedtPTB opened this issue Mar 29, 2020 · 0 comments
Open
Assignees
Labels

Comments

@eichstaedtPTB
Copy link
Collaborator

Right now calculation of the DFT (and iDFT) mean values in all methods in module propagate_DFT use the numpy.fft methods. The evaluation of uncertainties, though, uses a specific type of DFT for the propagation of uncertainties.

A possible method for a DFT using the same DFT type as for the uncertainty calculations would look as follows:

def calc_DFT(a):
    if len(a.shape)==1:
        N = len(a)
    else:
        N = a.shape[1]

    if np.mod(N, 2) == 0:  # N is even
        M = N + 2
    else:
        M = N + 1
    # For simplified calculation of sensitivities
    beta = 2 * np.pi * np.arange(N) / N
    # sensitivity matrix wrt cosine part
    Cxkc = lambda k: np.cos(k * beta)
    # sensitivity matrix wrt sinus part
    Cxks = lambda k: -np.sin(k * beta)

    if len(a.shape)==1:
        rA = np.zeros(M//2)
        iA = np.zeros(M//2)
        for k in range(M//2):
            rA[k] = np.dot( a, Cxkc(k) )
            iA[k] = np.dot( a, Cxks(k) )
    else:
        rA = np.zeros((a.shape[0], M // 2))
        iA = np.zeros((a.shape[0], M // 2))
        for k in range(M // 2):
            rA[:,k] = np.dot(a, Cxkc(k))
            iA[:,k] = np.dot(a, Cxks(k))

    return np.c_[rA, iA]

A similar function could be written for the inverse DFT. Should this approach be preferred to the current one?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants