Beispiel #1
0
def q2_4():
    ipx_1 = [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
    ipx_2 = [
        1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    ]
    len_of_sample = len(ipx_1)
    DTFS_result_1 = myDTFS(ipx_1, len_of_sample)
    DTFS_magnitude_1 = [abs(result) for result in DTFS_result_1]
    DTFS_phase_1 = [cmath.phase(result) for result in DTFS_result_1]
    DTFS_result_2 = myDTFS(ipx_2, len_of_sample)
    DTFS_magnitude_2 = [abs(result) for result in DTFS_result_2]
    DTFS_phase_2 = [cmath.phase(result) for result in DTFS_result_2]
    _, ax = plt.subplots(2, 1)
    ax[0].stem(DTFS_magnitude_1)
    ax[0].grid()
    ax[1].stem(DTFS_phase_1)
    ax[1].grid()
    plt.show()
    _, ax = plt.subplots(2, 1)
    ax[0].stem(DTFS_magnitude_2)
    ax[0].grid()
    ax[1].stem(DTFS_phase_2)
    ax[1].grid()
    plt.show()
Beispiel #2
0
def q2_2_c():
    ipx = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    len_of_sample = len(ipx)
    DTFS_result = myDTFS(ipx, len_of_sample)
    IDTFS_result = myIDTFS(DTFS_result)
    DFT_result = myDFT(ipx, len_of_sample)
    IDFT_result = myIDFT(DFT_result)
    FFT_result = fft(ipx, len_of_sample)
    print(np.allclose(np.array(DTFS_result) * len_of_sample, FFT_result))
    print(np.allclose(DFT_result, FFT_result))
    print(np.allclose(ipx, IDTFS_result))
    print(np.allclose(ipx, IDFT_result))
Beispiel #3
0
def q2_4():
    for N in [12, 24,48,96]:
        ipx = [1, 1, 1, 1, 1, 1, 1]
        ipx = np.pad(ipx, (0, N - len(ipx)), 'constant')
        DTFS_result = myDTFS(ipx, N)
        DTFS_magnitude = [abs(result) for result in DTFS_result]
        DTFS_phase = [cmath.phase(result) for result in DTFS_result]
        _, ax = plt.subplots(2, 1)
        ax[0].stem(DTFS_magnitude)
        ax[0].grid()
        ax[1].stem(DTFS_phase)
        ax[1].grid()
        plt.show()
Beispiel #4
0
def q2_2_b():
    ipx = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    len_of_sample = len(ipx)
    DTFS_result = myDTFS(ipx, len_of_sample)
    DTFS_magnitude = [abs(result) for result in DTFS_result]
    DTFS_phase = [cmath.phase(result) for result in DTFS_result]
    DFT_result = myDFT(ipx, len_of_sample)
    DFT_magnitude = [abs(result) for result in DFT_result]
    DFT_phase = [cmath.phase(result) for result in DFT_result]
    _, ax = plt.subplots(2, 1)
    ax[0].stem(DTFS_magnitude)
    ax[0].grid()
    ax[1].stem(DTFS_phase)
    ax[1].grid()
    plt.show()
    _, ax = plt.subplots(2, 1)
    ax[0].stem(DFT_magnitude)
    ax[0].grid()
    ax[1].stem(DFT_phase)
    ax[1].grid()
    plt.show()