Пример #1
0
 def run(self, conversion):          # Uses assembler for speed
     if self.popfunc is not None:
         self.popfunc(self)          # Populate the data (for fwd transfers, just the real data)
     if conversion != REVERSE:       # Forward transform: real data assumed
         setarray(self.im, 0, self._length)# Fast zero imaginary data
         if self.windata is not None:  # Fast apply the window function
             winapply(self.re, self.windata, self._length)
     fft(self.ctrl, conversion)
     if (conversion & POLAR) == POLAR: # Ignore complex conjugates, convert 1st half of arrays
         topolar(self.re, self.im, self._length//2) # Fast
         if conversion == DB:        # Ignore conjugates: convert 1st half only
             for idx, val in enumerate(self.re[0:self._length//2]):
                 self.re[idx] = -80.0 if val <= 0.0 else 20*math.log10(val) - self.dboffset
Пример #2
0
 def run(self, conversion):          # Uses assembler for speed
     if self.popfunc is not None:
         self.popfunc(self)          # Populate the data (for fwd transfers, just the real data)
     if conversion != REVERSE:       # Forward transform: real data assumed
         setarray(self.im, 0, self._length)# Fast zero imaginary data
         if self.windata is not None:  # Fast apply the window function
             winapply(self.re, self.windata, self._length)
     start = utime.ticks_us()
     fft(self.ctrl, conversion)
     delta = utime.ticks_diff(utime.ticks_us(), start)
     if (conversion & POLAR) == POLAR: # Ignore complex conjugates, convert 1st half of arrays
         topolar(self.re, self.im, self._length//2) # Fast
         if conversion == DB:        # Ignore conjugates: convert 1st half only
             for idx, val in enumerate(self.re[0:self._length//2]):
                 self.re[idx] = -80.0 if val <= 0.0 else 20*math.log10(val) - self.dboffset
     return delta
def INT_TEST():
    print('INT TEST:\n\n')

    #signal x
    x = []

    #making signal a sine wave
    amount = 8
    n = 0
    inkrement = 1
    i = 0
    for i in range(amount):
        x.append(n)
        n = n + inkrement

    N = len(x)

    #Diskrete-Fourier-Transformation
    X = around(dft(x), decimals=6)

    print('Diskrete-Fourier-Transformation:')
    print(f'X = {X}\n')

    #amplitude and phase
    A = [None] * N
    p = [None] * N
    i = 0
    for i in range(len(X)):
        temp1 = abs(X[i])
        A[i] = temp1
        temp2 = angle(X[i])
        p[i] = temp2
        #print(p[i])

    print(f'Amplitude: A = {A}')
    print(f'Phase: p = {p}\n\n')

    #Fast-Fourier-Transformation
    X2 = around(fft(x), decimals=6)

    print('Fast-Fourier-Transformation:')
    print(f'X2 = {X2}\n')

    #amplitude and phase
    A2 = [None] * N
    p2 = [None] * N
    i = 0
    for i in range(len(X2)):
        temp1 = abs(X2[i])
        A2[i] = temp1
        temp2 = angle(X[i])
        p2[i] = temp2

    print(f'Amplitude: A2 = {A2}')
    print(f'Phase: p2 = {p2}\n\n\n')

    plt.plot(x, X, max(x))
def AC_TEST():
    print('AC TEST:\n\n')

    #signal x
    x = []

    #making signal a sine wave
    amount = 8
    n = 0
    inkrement = 2 * pi / amount
    i = 0
    for i in range(amount):
        x.append(sin(n) * 5)
        n = n + inkrement

    N = len(x)

    #original signal
    print(f'signal: x = {x}\n\n')

    #if my ouput is the same it highly possible that is correct
    #try out yourself with the file ProofItWorks.m
    print('Octave(Matlab)-Output:')
    print(
        'fft = 0.00000 +  0.00000i   -0.00000 - 20.00000i    0.00000 -  0.00000i    0.00000 -  0.00000i    0.00000 +  0.00000i    0.00000 +  0.00000i    0.00000 +  0.00000i   -0.00000 + 20.00000i\n'
    )
    print(
        'fft(Amplitude) = 1.6823e-16   2.0000e+01   1.4662e-15   1.7764e-15   1.0564e-15   1.7764e-15   1.4662e-15   2.0000e+01'
    )
    print(
        'fft(Phase)     = 0.00000     -1.57080     -1.13998     -1.56195      0.00000      1.56195      1.13998      1.57080\nthe phase is actually false\n\n'
    )
    #you can also try numpy fft.fft()
    NUMPYFFT = around(npfft.fft(x), decimals=6)
    print(f'NumpyFFT = {NUMPYFFT}\n')
    print(f'Amplitude = {around(abs(NUMPYFFT), decimals=6)}')
    print(f'Phase = {around(npangle(NUMPYFFT), decimals=6)}\n\n')

    #Diskrete-Fourier-Transformation
    X = around(dft(x), decimals=6)

    print('Diskrete-Fourier-Transformation:')
    print(f'X = {X}\n')

    #amplitude and phase
    A = [None] * N
    p = [None] * N
    i = 0
    for i in range(len(X)):
        temp1 = abs(X[i])
        A[i] = temp1
        temp2 = angle(X[i])
        p[i] = temp2
        #print(p[i])

    print(f'Amplitude: A = {A}')
    print(f'Phase: p = {p}\n\n')

    #Fast-Fourier-Transformation
    X2 = around(fft(x), decimals=6)

    print('Fast-Fourier-Transformation:')
    print(f'X2 = {X2}\n')

    #amplitude and phase
    A2 = [None] * N
    p2 = [None] * N
    i = 0
    for i in range(len(X2)):
        temp1 = abs(X2[i])
        A2[i] = temp1
        temp2 = angle(X[i])
        p2[i] = temp2

    print(f'Amplitude: A2 = {A2}')
    print(f'Phase: p2 = {p2}\n\n\n')

    plt.plot(x, X, max(x))
def DC_TEST():
    print('DC TEST:\n\n')

    #signal x
    x = []
    #making a dc signal with 5V here
    amount = 8
    n = 0
    inkrement = 2 * pi / amount
    i = 0
    for i in range(amount):
        x.append(5)
        n = n + inkrement

    N = len(x)

    #original signal
    print(f'signal: x = {x}\n\n')

    #if my ouput is the same it highly possible that is correct
    NUMPYFFT = around(npfft.fft(x), decimals=6)
    print(f'NumpyFFT = {NUMPYFFT}\n')
    print(f'Amplitude = {around(abs(NUMPYFFT), decimals=6)}')
    print(f'Phase = {around(npangle(NUMPYFFT), decimals=6)}\n\n')

    #Diskrete-Fourier-Transformation
    X = around(dft(x), decimals=6)

    print('Diskrete-Fourier-Transformation:')
    print(f'X = {X}\n')

    #amplitude and phase
    A = [None] * N
    p = [None] * N
    i = 0
    for i in range(len(X)):
        temp1 = abs(X[i])
        A[i] = temp1
        temp2 = angle(X[i])
        p[i] = temp2

    print(f'Amplitude: A = {A}')
    print(f'Phase: p = {p}\n\n')

    #Fast-Fourier-Transformation
    X2 = around(fft(x), decimals=6)

    print('Fast-Fourier-Transformation:')
    print(f'X2 = {X2}\n')

    #amplitude and phase
    A2 = [None] * N
    p2 = [None] * N
    i = 0
    for i in range(len(X2)):
        temp1 = abs(X2[i])
        A2[i] = temp1
        temp2 = angle(X[i])
        p2[i] = temp2
    print(f'Amplitude: A2 = {A2}')
    print(f'Phase: p2 = {p2}\n\n\n')

    plt.plot(x, X, max(x))
Пример #6
0
def call_fft ( signal ) :
    dft.fft ( signal )