Esempio n. 1
0
            (2 * float(PLOT_CUTOFF_FREQ) / float(SAMPLE_RATE) * FFT_LENGTH))
        print cutoff_ind
        freq_plot, = freq_ax.plot(np.linspace(0, PLOT_CUTOFF_FREQ, cutoff_ind),
                                  np.zeros(cutoff_ind))
        freq_ax.set_ylim(0, 50)
        freq_ax.set_xlim(0, PLOT_CUTOFF_FREQ)
        freq_ax.set_ylabel('Magnitude')
        freq_ax.set_xlabel('Frequency (Hz)')
        # Show figure
        plt.show(block=False)

    data1 = np.zeros(WINDOW_LENGTH, dtype=DATA_TYPE)
    count = 0
    try:
        while in_stream.is_active() or out_stream.is_active():
            data_is_available = in_buf.wait_for_read(WINDOW_LENGTH, TIMEOUT)
            if data_is_available:  # and out_buf.get_available_write() >= WINDOW_LENGTH:
                #available = min(in_buf.get_available_read(), out_buf.get_available_write())
                #if available >= WINDOW_LENGTH:  # If enough space to transfer data
                # Get data from the circular buffer
                data = in_buf.read_samples(WINDOW_LENGTH)
                # Perform an stft
                stft.performStft(data)
                # Process dfts from windowed segments of input
                dfts = stft.getDFTs()
                process_dfts(dfts)
                if DO_PLOT:
                    # Must update here because dfts are altered upon calling ISTFT since
                    # the dft is performed in place
                    fft = to_full_fft(dfts[0][0][0], dfts[0][1][0])
                # Get the istft of the processed data
        freq_ax = fig.add_subplot(212)
        cutoff_ind = int((2 * float(PLOT_CUTOFF_FREQ) / float(SAMPLE_RATE) * FFT_LENGTH))
        print cutoff_ind
        freq_plot, = freq_ax.plot(np.linspace(0, PLOT_CUTOFF_FREQ, cutoff_ind), np.zeros(cutoff_ind))
        freq_ax.set_ylim(0, 50)
        freq_ax.set_xlim(0, PLOT_CUTOFF_FREQ)
        freq_ax.set_ylabel('Magnitude')
        freq_ax.set_xlabel('Frequency (Hz)')
        # Show figure
        plt.show(block=False)

    data1 = np.zeros(WINDOW_LENGTH, dtype=DATA_TYPE)
    count = 0
    try:
        while in_stream.is_active() or out_stream.is_active():
            data_is_available = in_buf.wait_for_read(WINDOW_LENGTH, TIMEOUT)
            if data_is_available:# and out_buf.get_available_write() >= WINDOW_LENGTH:
            #available = min(in_buf.get_available_read(), out_buf.get_available_write())
            #if available >= WINDOW_LENGTH:  # If enough space to transfer data
                # Get data from the circular buffer
                data = in_buf.read_samples(WINDOW_LENGTH)
                # Perform an stft
                stft.performStft(data)
                # Process dfts from windowed segments of input
                dfts = stft.getDFTs()
                process_dfts(dfts)
                if DO_PLOT:
                    # Must update here because dfts are altered upon calling ISTFT since
                    # the dft is performed in place
                    fft = to_full_fft(dfts[0][0][0], dfts[0][1][0])
                # Get the istft of the processed data