コード例 #1
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))
コード例 #2
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)
コード例 #3
0
ファイル: processTNT.py プロジェクト: chatcannon/pytnt
    def LBfft(self, LB=0, zf=0, phase=None, logfile=None, ph1=0,
              DCoffset=None, altDATA=None):
        if altDATA is None:
            DATA = self.DATA
        else:
            DATA = altDATA
        LBdw = -LB * self.dwell[0] * np.pi  # Multiply by pi to match TNMR
        npts = DATA.shape[0]
        npts_ft = npts * (2 ** zf)

        if DCoffset is None:
            # Taking the last eighth of the points seems to give OK (but not
            # perfect) agreement with the TNMR DC offset correction.
            # This hasn't been tested with enough different values of npts
            # to be sure that this is the right formula.
            DCoffset = np.mean(DATA[int(npts / -8):, :, :, :],
                               axis=0, keepdims=True)
            if logfile is not None:
                logfile.write("average DC offset is %g\n" % np.mean(DCoffset))

        lbweight = np.exp(LBdw * np.arange(npts, dtype=float))
        DATAlb = (DATA - DCoffset) * lbweight[:, np.newaxis, np.newaxis, np.newaxis]

        DATAfft = npfast.fft(DATAlb, n=npts_ft, axis=0)
        DATAfft = fftshift(DATAfft, axes=[0])
        DATAfft /= np.sqrt(npts_ft)  # To match TNMR behaviour

        if phase is None:  # Phase automatically
            DATAfft *= np.exp(-1j * np.angle(np.sum(DATAfft)))
        else:
            DATAfft *= np.exp(1j * (phase + ph1 * np.linspace(-0.5, 0.5, npts_ft))
                              )[:, np.newaxis, np.newaxis, np.newaxis]

        return DATAfft
コード例 #4
0
    def LBfft(self, LB=0, zf=0, phase=None, logfile=None, ph1=0,
              DCoffset=None, altDATA=None):
        if altDATA is None:
            DATA = self.DATA
        else:
            DATA = altDATA
        LBdw = -LB * self.dwell[0] * np.pi  # Multiply by pi to match TNMR
        npts = DATA.shape[0]
        npts_ft = npts * (2 ** zf)

        if DCoffset is None:
            # Taking the last eighth of the points seems to give OK (but not
            # perfect) agreement with the TNMR DC offset correction.
            # This hasn't been tested with enough different values of npts
            # to be sure that this is the right formula.
            DCoffset = np.mean(DATA[int(npts / -8):, :, :, :],
                               axis=0, keepdims=True)
            if logfile is not None:
                logfile.write("average DC offset is %g\n" % np.mean(DCoffset))

        lbweight = np.exp(LBdw * np.arange(npts, dtype=float))
        DATAlb = (DATA - DCoffset) * lbweight[:, np.newaxis, np.newaxis, np.newaxis]

        DATAfft = npfast.fft(DATAlb, n=npts_ft, axis=0)
        DATAfft = fftshift(DATAfft, axes=[0])
        DATAfft /= np.sqrt(npts_ft)  # To match TNMR behaviour

        if phase is None:  # Phase automatically
            DATAfft *= np.exp(-1j * np.angle(np.sum(DATAfft)))
        else:
            DATAfft *= np.exp(1j * (phase + ph1 * np.linspace(-0.5, 0.5, npts_ft))
                              )[:, np.newaxis, np.newaxis, np.newaxis]

        return DATAfft
コード例 #5
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))
コード例 #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
ファイル: Recording.py プロジェクト: olavolav/handwaving-ml
 def get_power_spectrum_of_sample_range(self, electrode_index, start_index, end_index):
   if electrode_index < 0 or electrode_index > self.get_number_of_electrodes()-1:
     raise RuntimeError("invalid electrode index")
   if start_index < 0 or start_index > self.get_number_of_samples()-1:
     raise RuntimeError("invalid start sample index")
   if end_index > self.get_number_of_samples()-1:
     raise RuntimeError("invalid end sample index")
   if start_index > end_index:
     raise RuntimeError("end sample index must be greater than start sample index")
   
   # return power spectrum of cutout
   return np.abs( npdual.fft( self.__data[electrode_index, start_index:end_index+1] ) )**2
コード例 #8
0
ファイル: fbmc_test_functions.py プロジェクト: wenh81/gr-fbmc
def rx_fdomain(samples, prototype_freq, osr, oqam='SIOHAN', drop_in=None, drop_in2=None):
    """SMT receiver using a frequency domain filtering
    """
    K = (len(prototype_freq) + 1) // 2

    num_symbols = (len(samples) - (osr * K )) // (osr // 2) + 1

    R_hat = zeros((num_symbols, osr * K), dtype=samples.dtype)
    for i, offset in zip(range(num_symbols), range(0, len(samples), osr // 2)):
        R_hat[i,:] = fft(samples[offset:offset + K * osr]) #/ np.sqrt(osr * K)

    G_hat = _spreading_matrix(prototype_freq, osr)
    d_hat = np.dot(G_hat, R_hat.T)

    return d_hat
コード例 #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 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
コード例 #12
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
コード例 #13
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
コード例 #14
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
コード例 #15
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
コード例 #16
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))
コード例 #17
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
コード例 #18
0
ファイル: test01.py プロジェクト: Tony1886/python_workplace
# coding=gbk
# coding£ºutf-8
'''

 @Created on 2018Äê1ÔÂ26ÈÕ ÏÂÎç2:43:08
 @author: Administrator
'''
from myFunc import mfft, mifft
from math import *
from numpy import *
# import numpy as np
from matplotlib import *
import matplotlib.pyplot as plt
from numpy.dual import fft
from numpy.fft.helper import fftshift
from numpy.core.function_base import linspace

x = linspace(-pi, pi, 100)
print(type(x))
print(shape(x))
y = random.random(size=(1, 10))
print(type(y))
print(type(shape(y)))
print(type(shape(y)))
f = sin(x)
F = fftshift(fft(f))
#F = mfft(f)
plt.subplot(121)
plt.plot(abs(F))
plt.show()
コード例 #19
0
def mfft(f):
    if size(f,0)==1 or size(f,1)==1:
        F = fftshift(fft(ifftshift(f)))
    else:
        F = fftshift(fft2(ifftshift(f)))
    return F