コード例 #1
0
ファイル: fbmc_test_functions.py プロジェクト: wenh81/gr-fbmc
def rx(samples, prototype, osr):
    # 0. prep
    coeffs = _polyphase_filter_coeffs(prototype[::-1], osr)
    # print coeffs

    # 1. input commutator
    if coeffs.size / 2 == len(prototype) - 1:
        # PHYDYAS filter: first and last sample is zero and therefore cut
        # --> samples must be cut as well
        samples = flipud(samples[1:].reshape((-1, osr // 2)).T)

    else:
        # other filters use the full OSR*overlap + 1 samples
        # --> prefix some zeros to also get transient behavior right
        samples = flipud(append(
            zeros(osr - 1, dtype=samples[0].dtype), samples).reshape((-1, osr // 2)).T)
    # print samples
    # 2. polyphase filters
    samples = append(samples, empty_like(samples), axis=0)
    # out = empty((samples.shape[0], samples.shape[1] + coeffs.shape[1] - 1), dtype=samples.dtype)
    out = samples[:, :-(coeffs.shape[1] - 1)]
    # print np.round(samples)
    # reverse iteration to not override samples for l >= osr/2
    for l in reversed(range(osr)):
    # run filter (draw samples from the first half for l >= osr/2
        out[l, :] = convolve(samples[l % (osr // 2), :], coeffs[l, :], 'valid')
        # print "\n", np.round(samples)
        # print "out\n", np.round(out)

    # 3. spin polyphase signals
    out[:] = osr * ifft(out, osr, 0)

    return out
コード例 #2
0
ファイル: beagleorder.py プロジェクト: junotk/vsm
    def b_conv(v1, v2):
        
        w1 = dual.fft(v1[rand_perm[0]])

        w2 = dual.fft(v2[rand_perm[1]])

        return np.real_if_close(dual.ifft(w1 * w2))
コード例 #3
0
ファイル: nmf.py プロジェクト: chatcannon/nmrpca
 def project_H(self, H, copy=False, phase=False):
     Hft = fft(H, axis=1)
     if phase:
         Hsum = np.sum(Hft, axis=1)
         Hphase = Hsum / np.abs(Hsum)
         Hft /= Hphase[:, None]
     Hft.imag = 0  # Keep only the real part
     Hft[Hft.real <= 0] = 0
     if copy:
         H = ifft(Hft, axis=1)
     else:
         H[:, :] = ifft(Hft, axis=1)
     N = H.shape[1]
     KKfactor = np.linspace(2, 0, N, endpoint=False)
     KKfactor[0] = 1
     H *= KKfactor[None, :]
     if phase:
         return H, Hphase
     else:
         return H
コード例 #4
0
ファイル: KramersKronig.py プロジェクト: chatcannon/nmrpca
 def __call__(self, realdata):
     N = realdata.shape[0]
     ## Not sure which of these ways of calculating tweak_fid is best
     ## TODO: test them out more thoroughly
     tweak_fid = np.empty((N, ), dtype=float)
     tweak_fid[0] = 1
     tweak_fid[1:] = np.linspace(2, 0, N - 1, endpoint=True)
     #tweak_fid = np.linspace(2, 0, N, endpoint=False)
     #tweak_fid[0] = 1
     fid_guess = ifft(fftshift(realdata))
     return fftshift(fft(fid_guess * tweak_fid))
コード例 #5
0
ファイル: nmf.py プロジェクト: chatcannon/nmrpca
 def project_H(self, H, copy=False, phase=False):
     Hft = fft(H, axis=1)
     if phase:
         Hsum = np.sum(Hft, axis=1)
         Hphase = Hsum / np.abs(Hsum)
         Hft /= Hphase[:, None]
     Hft.imag = 0  # Keep only the real part
     Hft[Hft.real <= 0] = 0
     if copy:
         H = ifft(Hft, axis=1)
     else:
         H[:, :] = ifft(Hft, axis=1)
     N = H.shape[1]
     KKfactor = np.linspace(2, 0, N, endpoint=False)
     KKfactor[0] = 1
     H *= KKfactor[None, :]
     if phase:
         return H, Hphase
     else:
         return H
コード例 #6
0
ファイル: KramersKronig.py プロジェクト: chatcannon/nmrpca
 def __call__(self, realdata):
     N = realdata.shape[0]
     ## Not sure which of these ways of calculating tweak_fid is best
     ## TODO: test them out more thoroughly
     tweak_fid = np.empty((N,), dtype=float)
     tweak_fid[0] = 1
     tweak_fid[1:] = np.linspace(2, 0, N - 1, endpoint=True)        
     #tweak_fid = np.linspace(2, 0, N, endpoint=False)
     #tweak_fid[0] = 1
     fid_guess = ifft(fftshift(realdata))
     return fftshift(fft(fid_guess * tweak_fid))
コード例 #7
0
ファイル: pyltessTrack.py プロジェクト: Viproz/pyltess-track
def generateZadoffTimeDomainSeq(seqID):
    fDat = sequences.zcsequence(seqID, 63)
    # fDat is in the frequency domain, convert it to time domain

    # This code was taken from JiaoXianjun/LTE-Cell-Scanner in tle_lib.cpp
    idft_in = np.concatenate((np.zeros(1, np.complex64), fDat[31:61 + 1],
                              np.zeros(65, np.complex64), fDat[0:30 + 1]))
    td = ifft(idft_in) * np.sqrt(128.0 / 62.0) * np.sqrt(128.)

    return np.concatenate((td[119:127 + 1], td))

    return td
コード例 #8
0
                def f(vector_list):

                    if len(vector_list) == 0:
                        return np.zeros(self.dimension)

                    elif len(vector_list) == 1:
                        return vector_list[0]

                    else:
                        v1 = dual.fft(left_permutation(f(vector_list[:-1])))
                        v2 = dual.fft(right_permutation(vector_list[len(vector_list)-1]))
                        return dual.ifft(v1 * v2)
コード例 #9
0
ファイル: nmf.py プロジェクト: chatcannon/nmrpca
    def project_H(self, H, copy=False):
        N = H.shape[1]
        if copy:
            H = np.copy(H)
        H.imag = 0  # Keep only the real part
        H.real[H.real <= 0] = 0

        # Do the Kramers-Kronig convolution
        Hft = ifft(H, axis=1)
        KKfactor = np.linspace(2, 0, N, endpoint=False)
        KKfactor[0] = 1
        Hft *= KKfactor[None, :]
        H = fft(Hft, axis=1)

        # Zero out small negative numbers caused by rounding errors
        H.real[H.real <= 0] = 0
        return H
コード例 #10
0
ファイル: nmf.py プロジェクト: chatcannon/nmrpca
    def project_H(self, H, copy=False):
        N = H.shape[1]
        if copy:
            H = np.copy(H)
        H.imag = 0  # Keep only the real part
        H.real[H.real <= 0] = 0

        # Do the Kramers-Kronig convolution
        Hft = ifft(H, axis=1)
        KKfactor = np.linspace(2, 0, N, endpoint=False)
        KKfactor[0] = 1
        Hft *= KKfactor[None, :]
        H = fft(Hft, axis=1)

        # Zero out small negative numbers caused by rounding errors
        H.real[H.real <= 0] = 0
        return H
コード例 #11
0
ファイル: nmf.py プロジェクト: chatcannon/nmrpca
def NMR_svd_initialise(X, n_components, constraint):
    """Calculate a starting point for the generalised NMF fit of NMR

    Does a standard NNDSVD (as used in standard NMF) on the real part of the
    (approximately phased) NMR spectrum. If the constraint is a FIDconstraint,
    Fourier transforms the X array so the NNDSVD is done on the spectrum."""

    if isinstance(constraint, FIDConstraint):
        FT = True
    else:
        FT = False

    if FT:
        X = fft(X, axis=1)
    W, H = realpart_svd_initialise(X, n_components)
    if FT:
        H = ifft(H, axis=1)

    H = constraint.project_H(H)  # Need to add back in the imaginary part
    W, H = constraint.normalise(W, H)
    return W, H
コード例 #12
0
ファイル: nmf.py プロジェクト: chatcannon/nmrpca
def NMR_svd_initialise(X, n_components, constraint):
    """Calculate a starting point for the generalised NMF fit of NMR

    Does a standard NNDSVD (as used in standard NMF) on the real part of the
    (approximately phased) NMR spectrum. If the constraint is a FIDconstraint,
    Fourier transforms the X array so the NNDSVD is done on the spectrum."""

    if isinstance(constraint, FIDConstraint):
        FT = True
    else:
        FT = False

    if FT:
        X = fft(X, axis=1)
    W, H = realpart_svd_initialise(X, n_components)
    if FT:
        H = ifft(H, axis=1)

    H = constraint.project_H(H)  # Need to add back in the imaginary part
    W, H = constraint.normalise(W, H)
    return W, H
コード例 #13
0
ファイル: KramersKronig.py プロジェクト: chatcannon/nmrpca
 def imag(self, realdata):
     N = realdata.shape[0]
     tweak_fid = np.linspace(-1j, 1j, N, endpoint=False)
     tweak_fid[0] = 0
     fid_guess = ifft(fftshift(realdata))
     return fftshift(fft(fid_guess * tweak_fid)).real
コード例 #14
0
def mifft(f):
    if size(f,0)==1 or size(f,1)==1:
        F = fftshift(ifft(ifftshift(f)))
    else:
        F = fftshift(ifft2(ifftshift(f)))
    return F
コード例 #15
0
    def b_conv(v1, v2):

        w1 = dual.fft(v1[rand_perm[0]])
        w2 = dual.fft(v2[rand_perm[1]])

        return np.real_if_close(dual.ifft(w1 * w2))
コード例 #16
0
ファイル: KramersKronig.py プロジェクト: chatcannon/nmrpca
 def imag(self, realdata):
     N = realdata.shape[0]
     tweak_fid = np.linspace(-1j, 1j, N, endpoint=False)
     tweak_fid[0] = 0
     fid_guess = ifft(fftshift(realdata))
     return fftshift(fft(fid_guess * tweak_fid)).real