Пример #1
0
    def test__002_t(self):
        """
        Generate a signal with SNR as given below.
        Calculate the RMSE.
        """
        nsamples = 1024
        n_trials = 100
        samp_rate = 32000
        SNR = 20  # in dB
        self.siggen = siggen.signal_generator(n_sinusoids=1,
                                              SNR=SNR,
                                              samp_rate=samp_rate,
                                              nsamples=nsamples * n_trials)

        self.stream = gr.stream_to_vector(gr.sizeof_gr_complex, nsamples)
        self.esprit = specest.esprit_vcf(n=1, m=64, nsamples=nsamples)
        self.sink = gr.vector_sink_f(vlen=1)
        # wire it up ...
        self.tb.connect(self.siggen, self.stream, self.esprit, self.sink)
        self.tb.run()
        MSE = 0.0
        omega = self.siggen.omegas()[0]
        for i in range(n_trials):
            MSE += (omega - self.sink.data()[i])**2.0
        print '\n' + 70 * '-'
        print 'Testing specest_esprit_vcf ...'
        print 'Ran %u trials to estimate the frequency' % n_trials
        print 'Used %u samples to estimate the frequency' % nsamples
        print 'Sampling rate %s' % eng_notation.num_to_str(samp_rate)
        print 'SNR of %u dB' % SNR
        print 'Root mean square error %g' % numpy.sqrt(MSE / n_trials)
        print 'Cramer-Rao Bound %g' % numpy.sqrt(
            6 / 10**(SNR / 10.0) / nsamples**3)
        print 70 * '-'
Пример #2
0
    def test__002_t (self):
        """
        Generate a signal with SNR as given below.
        Calculate the RMSE.
        """
        nsamples = 1024
        n_trials = 100
        samp_rate = 32000
        SNR = 20 # in dB
        self.siggen = siggen.signal_generator(n_sinusoids = 1,
                                              SNR = SNR, samp_rate = samp_rate,
                                              nsamples = nsamples * n_trials)

        self.stream = gr.stream_to_vector(gr.sizeof_gr_complex, nsamples)
        self.esprit = specest.esprit_vcf(n=1, m=64, nsamples = nsamples)
        self.sink = gr.vector_sink_f(vlen=1)
        # wire it up ...
        self.tb.connect(self.siggen, self.stream, self.esprit, self.sink)
        self.tb.run()
        MSE = 0.0
        omega = self.siggen.omegas()[0]
        for i in range(n_trials):
            MSE += (omega - self.sink.data()[i])**2.0
        print '\n' + 70*'-'
        print 'Testing specest_esprit_vcf ...'
        print 'Ran %u trials to estimate the frequency' % n_trials
        print 'Used %u samples to estimate the frequency' % nsamples
        print 'Sampling rate %s' % eng_notation.num_to_str(samp_rate)
        print 'SNR of %u dB' % SNR
        print 'Root mean square error %g' % numpy.sqrt(MSE/n_trials)
        print 'Cramer-Rao Bound %g' % numpy.sqrt(6/10**(SNR/10.0)/nsamples**3)
        print 70*'-'
Пример #3
0
    def test__001_t(self):
        """
        Generate a signal with n_sinusoids sinusoids
        and a SNR of SNR.
        Another Check to see if it's working at all.
        """
        n_sinusoids = 2
        nsamples = 2048
        samp_rate = 32000
        SNR = 10  # in dB
        decimals = 3
        self.siggen = siggen.signal_generator(n_sinusoids=n_sinusoids,
                                              SNR=SNR,
                                              samp_rate=samp_rate,
                                              nsamples=nsamples)

        self.stream = gr.stream_to_vector(gr.sizeof_gr_complex, nsamples)
        self.esprit = specest.esprit_vcf(n=n_sinusoids,
                                         m=100,
                                         nsamples=nsamples)
        self.sink = gr.vector_sink_f(vlen=n_sinusoids)
        # wire it up ...
        self.tb.connect(self.siggen, self.stream, self.esprit, self.sink)
        for i in range(100):
            self.tb.run()
            for (g, e) in zip(sorted(list(self.sink.data())),
                              self.siggen.omegas()):
                self.assertAlmostEqual(g, e, decimals)
Пример #4
0
 def test_001_t (self):
     """
     Simple test to see if decimation is working at all.
     """
     input_len = 2048
     nsamples = 1024
     decimation = 2
     pspectrum_len = 512
     n = 1
     m = 64
     self.siggen = siggen.signal_generator(n_sinusoids = n,
                                           SNR = 20, samp_rate = 32e3,
                                           nsamples = input_len)
     self.music = specest.music(n, m, nsamples, pspectrum_len, decimation)
     self.sink = gr.vector_sink_f(vlen=pspectrum_len)
     self.tb.connect(self.siggen, self.music, self.sink)
     self.tb.run ()
     self.assertEqual(len(self.sink.data()), input_len / nsamples / decimation * pspectrum_len)
Пример #5
0
 def test_001_t (self):
     """
     Simple test to see if decimation is working at all.
     """
     input_len = 2048
     nsamples = 1024
     decimation = 2
     pspectrum_len = 512
     n = 1
     m = 64
     self.siggen = siggen.signal_generator(n_sinusoids = n,
                                           SNR = 20, samp_rate = 32e3,
                                           nsamples = input_len)
     self.esprit = specest.esprit(n, m, nsamples, pspectrum_len, decimation)
     self.sink = gr.vector_sink_f(vlen=pspectrum_len)
     self.tb.connect(self.siggen, self.esprit, self.sink)
     self.tb.run ()
     self.assertEqual(len(self.sink.data()), input_len / nsamples / decimation * pspectrum_len)
Пример #6
0
    def test__001_t (self):
        n_sinusoids = 5
        nsamples = 2048
        samp_rate = 32000
        SNR = 20 # in dB
        pspectrum_len = 512
        decimals = 4
        self.siggen = siggen.signal_generator(n_sinusoids = n_sinusoids,
                                              SNR = SNR, samp_rate = samp_rate,
                                              nsamples = nsamples)

        self.stream = blocks.stream_to_vector(gr.sizeof_gr_complex, nsamples)
        self.esprit = specest.esprit_spectrum_vcf(n=n_sinusoids, m=100, nsamples = nsamples, pspectrum_len = pspectrum_len)
        self.sink = blocks.vector_sink_f(vlen=pspectrum_len)
        # wire it up ...
        self.tb.connect(self.siggen, self.stream, self.esprit, self.sink)
        x = pylab.arange(start=-0.5, stop=0.5, step=1.0/float(pspectrum_len))
        self.tb.run()
Пример #7
0
    def test__001_t (self):
        n_sinusoids = 5 
        nsamples = 2048
        samp_rate = 32000
        SNR = 20 # in dB
        pspectrum_len = 512
        decimals = 4
        self.siggen = siggen.signal_generator(n_sinusoids = n_sinusoids, 
                                              SNR = SNR, samp_rate = samp_rate,
                                              nsamples = nsamples)

        self.stream = gr.stream_to_vector(gr.sizeof_gr_complex, nsamples)
        self.esprit = specest.esprit_spectrum_vcf(n=n_sinusoids, m=100, nsamples = nsamples, pspectrum_len = pspectrum_len)
        self.sink = gr.vector_sink_f(vlen=pspectrum_len)
        # wire it up ... 
        self.tb.connect(self.siggen, self.stream, self.esprit, self.sink)
        x = pylab.arange(start=-0.5, stop=0.5, step=1.0/float(pspectrum_len))
        self.tb.run()
Пример #8
0
 def test_002_t (self):
     """
     Simple test to see if the decimation setters and getters work at all.
     """
     input_len = 1024
     nsamples = 256
     decimation = 1
     pspectrum_len = 512
     n = 1
     m = 64
     self.siggen = siggen.signal_generator(n_sinusoids = n,
                                           SNR = 20, samp_rate = 32e3,
                                           nsamples = input_len)
     self.music = specest.music(n, m, nsamples, pspectrum_len, decimation)
     self.assertEqual(self.music.decimation(), 1)
     self.music.set_decimation(2)
     self.assertEqual(self.music.decimation(), 2)
     self.sink = gr.vector_sink_f(vlen=pspectrum_len)
     self.tb.connect(self.siggen, self.music, self.sink)
     self.tb.run ()
     self.assertEqual(len(self.sink.data()), input_len / nsamples / 2 * pspectrum_len)
Пример #9
0
 def test_002_t (self):
     """
     Simple test to see if the decimation setters and getters work at all.
     """
     input_len = 1024
     nsamples = 256
     decimation = 1
     pspectrum_len = 512
     n = 1
     m = 64
     self.siggen = siggen.signal_generator(n_sinusoids = n,
                                           SNR = 20, samp_rate = 32e3,
                                           nsamples = input_len)
     self.esprit = specest.esprit(n, m, nsamples, pspectrum_len, decimation)
     self.assertEqual(self.esprit.decimation(), 1)
     self.esprit.set_decimation(2)
     self.assertEqual(self.esprit.decimation(), 2)
     self.sink = gr.vector_sink_f(vlen=pspectrum_len)
     self.tb.connect(self.siggen, self.esprit, self.sink)
     self.tb.run ()
     self.assertEqual(len(self.sink.data()), input_len / nsamples / 2 * pspectrum_len)
Пример #10
0
 def test__001_t (self):
     """
     Generate a signal with n_sinusoids sinusoids
     and a SNR of SNR.
     Another Check to see if it's working at all.
     """
     n_sinusoids = 2
     nsamples = 2048
     samp_rate = 32000
     SNR = 10 # in dB
     decimals = 3
     self.siggen = siggen.signal_generator(n_sinusoids = n_sinusoids,
                                           SNR = SNR, samp_rate = samp_rate,
                                           nsamples = nsamples)
     self.stream = blocks.stream_to_vector(gr.sizeof_gr_complex, nsamples)
     self.esprit = specest.esprit_vcf(n=n_sinusoids, m=100, nsamples = nsamples)
     self.sink = blocks.vector_sink_f(vlen=n_sinusoids)
     self.tb.connect(self.siggen, self.stream, self.esprit, self.sink)
     for i in range(100):
         self.tb.run()
         for (g,e) in  zip(sorted(list(self.sink.data())), self.siggen.omegas()):
             self.assertAlmostEqual(g,e, decimals)
 def create_rooms(self,N_mutations_per_roomtype,roomtype=0):
     roomtype=self.room_specs[roomtype]
     
     number_rooms=0
         
     for i in range(N_mutations_per_roomtype):
         ################################################################################################
         #random room dimensions
         room_x=(random.randint(roomtype["min_room_dim"][0]*100,roomtype["max_room_dim"][0]*100)/100)
         room_y=(random.randint(roomtype["min_room_dim"][1]*100,roomtype["max_room_dim"][1]*100)/100)
         room_z=(random.randint(roomtype["min_room_dim"][2]*100,roomtype["max_room_dim"][2]*100)/100)
         room_dim=[room_x,room_y,room_z]
         ################################################################################################
         #random materials
         wall_materials=random.choice(roomtype["wall_materials"])
         random.shuffle(wall_materials)
         floor_material=random.choice(roomtype["floor_material"])
         ceiling_material=random.choice(roomtype["ceiling_material"])
         m = pra.make_materials(
             ceiling=ceiling_material,
             floor=floor_material,
             east=wall_materials[0],
             west=wall_materials[1],
             north=wall_materials[2],
             south=wall_materials[3],)
         ################################################################################################
         # create room
         rt60 = 0.5  # seconds
         e_absorption, max_order = pra.inverse_sabine(rt60, room_dim)
         room = pra.ShoeBox(room_dim, fs=self.sr, materials=m, max_order=max_order , air_absorption=True,ray_tracing=False)
         ################################################################################################
         # random mic_positions
         mic_x=(random.randint(0,int(room_x*100))/100)
         mic_y=(random.randint(0,int(room_y*100))/100)
         mic_z=(random.randint(0,int(room_z*100))/100)
         mic_pos=[mic_x,mic_y,mic_z]
         room.add_microphone_array(np.array([mic_pos]).T)
         ################################################################################################
         # add sweep source
         sg=signal_generator(sr=self.sr)
         logsweep=sg.logsweep(w1=100,w2=30000,T=0.3)
         sweep_sourcepos=mic_pos
         if room.is_inside([mic_pos[0],mic_pos[1]+0.1,mic_pos[2]]):
             sweep_sourcepos=[mic_pos[0],mic_pos[1]+0.1,mic_pos[2]]
         else:
             sweep_sourcepos=[mic_pos[0],mic_pos[1]-0.1,mic_pos[2]]
         scaled = np.int16(logsweep.signal/np.max(np.abs(logsweep.signal)) * 32767*0.5)
         room.add_source(sweep_sourcepos, signal=scaled, delay=0.02)
         ################################################################################################
         # add noise source
         fs, audio = wavfile.read("../../data/audio/"+random.choice(os.listdir("../../data/audio/")))
         #fs, audio = wavfile.read("../../data/audio/DevNode1_ex46_154.wav")
         noise_x=(random.randint(0,int(room_x*100))/100)
         noise_y=(random.randint(0,int(room_y*100))/100)
         noise_z=(random.randint(0,int(room_z*100))/100)
         noise_pos=[noise_x,noise_y,noise_z]
         ## Interpolate to higher fps
         duration = audio.shape[0] / fs
         time_old  = np.linspace(0, duration, audio.shape[0])
         time_new  = np.linspace(0, duration, int(audio.shape[0] * 96000 / fs))
         interpolator = interpolate.interp1d(time_old, audio.T)
         audio = interpolator(time_new).T.astype('int16') 
         
         room.add_source(noise_pos, signal=audio.T[0], delay=0.0)
         #room.add_source(noise_pos, signal=np.sin(audio.T[1])*0.01, delay=0.0)
         #room.add_source(noise_pos, signal=np.sin(audio.T[2])*0.01, delay=0.0)
         #room.add_source(noise_pos, signal=np.sin(audio.T[3])*0.01, delay=0.0)
     ################################################################################################
         # store room
         self.rooms.append(room)
         #print("Room "+str(number_rooms)+" created: "+str(room_dim)+" , "+str(wall_materials)+" , "+str(floor_material)+" , "+str(ceiling_material))
         number_rooms+=1
Пример #12
0
if __name__ == '__main__':
    n_cycles = 12
    n_samples = 256
    fs = 15360

    n = n_samples * n_cycles
    ts = 1 / fs
    t = np.arange(0, n) * ts

    f = 60.0
    max_iter = 50

    # Signal choice
    phase = np.deg2rad(0.0)
    signal = signal_generator(t, signal_names['I'], f, phase)

    # Noise addition
    snr = 40.0
    noise = wgn(signal, snr)
    sigma = np.sqrt(np.mean(noise**2))
    if snr == 100.0:
        y = signal
    else:
        y = signal + noise

    tol = 4.0 * (np.mean(y**2) - np.mean(np.cos(2 * np.pi * f * t)**2))

    # Execute ALMP
    tic()
    a_n, f_n, theta_n, ss_t, res, res_n, opt_res_n = almp(y, tol, max_iter, fs)