Esempio n. 1
0
    def test_keep_or_kill(self):
        for _ in range(10):
            freq = random.uniform(0.01, 0.4)
            sr = 1024
            tone = pure_tone(freq * sr, sr=sr, dur=10)

            # For this test we accept 5% tolerance in amplitude, or -26dB in power.
            tol = 5
            zeros = 16

            # If cutoff frequency is under freq, output should be input
            y_pass = filters.highpass_filter(tone, 0.9 * freq, zeros=zeros)
            self.assertSimilar(y_pass,
                               tone,
                               tone,
                               f"freq={freq}, pass",
                               tol=tol)

            # If cutoff frequency is over freq, output should be zero
            y_killed = filters.highpass_filter(tone, 1.1 * freq, zeros=zeros)
            self.assertSimilar(y_killed,
                               0 * tone,
                               tone,
                               f"freq={freq}, kill",
                               tol=tol)
Esempio n. 2
0
 def test_fft_nofft(self):
     for _ in range(10):
         x = th.randn(1024)
         freq = random.uniform(0.01, 0.5)
         y_fft = filters.highpass_filter(x, freq, fft=True)
         y_ref = filters.highpass_filter(x, freq, fft=False)
         self.assertSimilar(y_fft, y_ref, x, f"freq={freq}", tol=0.01)
 def forward(self, audio: torch.Tensor) -> torch.Tensor:
     frequency = self.sample_uniform_frequency()
     cutoff = self.cutoff_frequency(frequency)
     audio = highpass_filter(audio, cutoff=cutoff)
     return audio
Esempio n. 4
0
 def test_constant(self):
     x = th.ones(2048)
     for zeros in [4, 10]:
         for freq in [0.01, 0.1]:
             y_high = filters.highpass_filter(x, freq, zeros=zeros)
             self.assertLessEqual(y_high.abs().mean(), 1e-6, (zeros, freq))
Esempio n. 5
0
    def test_same_as_highpass(self):
        x = th.randn(1024)

        y_ref = filters.highpass_filter(x, 0.2)
        y = filters.bandpass_filter(x, 0.2, 0.5)
        self.assertSimilar(y, y_ref, x)