Esempio n. 1
0
 def test_bandpass_filter_high(self):
     """ Test that the bandpass filter removes high frequencies as expected. """
     bp_filter = spectral.butter_bandpass(1, 10, self.sampling_rate)
     spectrum = spectral.spectrum(self.high_frequency, self.window, bp_filter)
     for power in spectrum:
         # Maximum amplitude expected of filtered frequencies.
         self.assertLessEqual(power, 0.006)
Esempio n. 2
0
 def test_bandpass_filter_complex(self):
     """ Test that the bandpass filter removes low and high frequencies as expected. """
     bp_filter = spectral.butter_bandpass(10, 24, self.sampling_rate)
     spectrum = spectral.spectrum(self.complex_wave, self.window, bp_filter)
     for low_frequency in range(0, 9):
         self.assertLessEqual(spectrum[low_frequency], 0.006)
     for high_frequency in range(25, len(spectrum)):
         self.assertLessEqual(spectrum[high_frequency], 0.006)
     # Assert fundamental is kept.
     self.assertGreaterEqual(spectrum[20], 0.006)
Esempio n. 3
0
 def run(self):
     """ Convert input signal into it's frequency spectrum equivalent. """
     while True:
         signal = self.queue.get()
         frequency_spectrum = spectral.spectrum(signal, self.window,
                                                self.filter)
         self.message_peers(frequency_spectrum)
         dispatcher.send(signal='spectrum',
                         sender=self.channel_id,
                         data=frequency_spectrum)
Esempio n. 4
0
 def setUp(self):
     """ Perform setup of initial parameters. """
     self.sampling_rate = 100
     self.frequency = 5
     self.timestep = arange(self.sampling_rate)
     self.sin_wave = sin(2 * pi * self.frequency * self.timestep /
                         self.sampling_rate)
     bp_filter = spectral.butter_bandpass(1, 48, self.sampling_rate)
     window = spectral.new_window(len(self.sin_wave), 'blackmanharris')
     self.frequency_spectrum = spectral.spectrum(self.sin_wave, window,
                                                 bp_filter)
     self.convolved_signal = spectral.convolve_signal(self.sin_wave)
Esempio n. 5
0
    def setUp(self):
        """ Perform setup of initial parameters. """
        def generate_sine(frequency, sampling_rate, time_step):
            """ Generates a basic sine wave for testing. """
            return sin(2 * pi * frequency * time_step / sampling_rate)

        self.sampling_rate = 50
        time_step = arange(self.sampling_rate)
        self.low_frequency = generate_sine(5, self.sampling_rate, time_step)
        med_frequency = generate_sine(10, self.sampling_rate, time_step)
        self.high_frequency = generate_sine(20, self.sampling_rate, time_step)
        self.complex_wave = self.low_frequency + med_frequency + self.high_frequency
        self.window = spectral.new_window(self.sampling_rate, 'blackmanharris')
        bp_filter = spectral.butter_bandpass(1, 24, self.sampling_rate, 10)
        self.spectrum = spectral.spectrum(self.low_frequency, self.window, bp_filter)
        self.conv_signal = spectral.convolve_signal(self.low_frequency)
Esempio n. 6
0
    def run(self):
        """ Reset object attributes, to latest config values. """
        ffts = []
        while True:

            fft = self.queue.get()
            if fft is not None:
                fft = spectral.spectrum(fft, self.window, None)
                fft = spectral.normalizorFFT(fft)
                ffts.append(fft)
                ffts = ffts[-self.spectrogram_resolution:]
                self.timer = self.timer + 1
                if self.timer == self.spectrogram_resolution:
                    self.message_peers(ffts.copy())
                    dispatcher.send(signal='spectrogram',
                                    sender='spectrogram',
                                    data=ffts)
                    self.timer = 0
Esempio n. 7
0
    def setUp(self):
        """ Perform setup"""
        self.sampling_rate = 44100  # standard sampling rate.
        time_step = arange(self.sampling_rate)

        self.fundamental_freq = 5000
        low_frequency = generate_sine(200, self.sampling_rate, time_step)
        fundamental = generate_sine(self.fundamental_freq, self.sampling_rate,
                                    time_step) * 500  # Fundamental
        high_frequency = generate_sine(12000, self.sampling_rate, time_step)
        noise = normal(
            0, 1,
            self.sampling_rate)  # Add noise to make it harder to detect pitch.
        self.complex_wave = low_frequency + fundamental + high_frequency + noise

        # Pre-processing to setup signal.
        self.window = spectral.new_window(self.sampling_rate, 'blackmanharris')
        self.bp_filter = spectral.butter_bandpass(100, 20000,
                                                  self.sampling_rate, 5)
        self.spectrum = spectral.spectrum(self.complex_wave, self.window,
                                          self.bp_filter)
        self.conv_spectrum = spectral.convolve_signal(self.complex_wave)
Esempio n. 8
0
 def test_bandpass_filter_low(self):
     """ Test that the bandpass filter removes low frequencies as expected. """
     bp_filter = spectral.butter_bandpass(10, 24, self.sampling_rate)
     spectrum = spectral.spectrum(self.low_frequency, self.window, bp_filter)
     for power in spectrum:
         self.assertLessEqual(power, 0.006)