示例#1
0
import matplotlib.pyplot as plt
import numpy as np
import math 
import dft_01 
import idft_01 

if __name__ == "__main__":
    X = np.array ([3, 2+4j, 1, 5-3j, 0, 0, 0, 5+3j, 1, 2-4j])
    x_2 = idft_01.idft (X)
    x_2Real = np.real (x_2)
    x_2Imag = np.imag (x_2)
    x_2abs = np.absolute (x_2)

    x = x_2
    X = dft_01.dft (x)
    XReal = np.real (X)
    XImag = np.imag (X)
    Xabs = np.absolute (X)
    Xangle = np.angle (X)
    
    plt.figure (1)
    plt.stem (Xabs)
    plt.grid (True)
    plt.title ("DFT")
    plt.ylabel ('Amplitud')
    plt.xlabel ('Muestras')

    plt.figure (2)
    plt.stem (x_2abs)
    plt.grid (True)
    plt.title ("IDFT")
import matplotlib.pyplot as plt
import math
from scipy import signal

if __name__ == "__main__":
    N = 512
    M = 512
    Fs = 8000
    f1 = 200
    f2 = 250
    ti = np.linspace(0, M, num=M) / Fs
    t = np.transpose(ti)
    x = np.cos(2 * math.pi * f1 * t) + 0.2 * np.cos(2 * math.pi * f2 * t)
    x = np.append(x, np.zeros(N - M))
    x = x * np.kaiser(M, beta=14)
    arr = dft_01.dft(x)
    s = np.absolute(arr)
    s = s / np.max(s)
    fp = Fs * np.linspace(0, N, num=N) / N

    plt.figure(1)
    plt.title('x[n]')
    plt.plot(x, 'o-', markersize=4)

    new_range = len(s) / 2
    plt.figure(2)
    plt.plot(fp[:int(new_range)],
             s[:int(new_range)],
             'o-',
             markersize=4,
             linewidth=0.5)