Example #1
0
    def test_channel_merge(self):
        dummyData = np.r_[1:6]  /10  +1
        dummyData2ch = np.vstack((dummyData, dummyData+1))

        s_1ch = pyspt.Signal(dummyData, 1, comment="one ch")
        s_2ch =  pyspt.Signal(dummyData2ch, 1, comment="two channels")
                
        tmp = s_2ch | s_2ch
        self.assertEqual(tmp.nChannels, 4)
        tmp =s_1ch | s_1ch
        self.assertEqual(tmp.nChannels, 2)
        tmp =s_1ch | s_2ch
        self.assertEqual(tmp.nChannels, 3)
Example #2
0
    def test_time_shift_for_individual_channels(self):
        sig =  pyspt.Signal(range(101),1)
        sig |= sig

        sig2 = pyspt.dsp.time_shift(sig, [-10, 10] )   # list
        sig2 = pyspt.dsp.time_shift(sig, np.array([-10, 10])) # array of int
        sig2 = pyspt.dsp.time_shift(sig, np.array([-1.10, 10.1]) )        # array of float
Example #3
0
 def test_time_shift(self):    
     plt.figure()
     sig =  pyspt.Signal(range(101),1)
     sig |= sig
     plot = False
     if plot:
         #% matplotlib
         sig.plot_time(ax=plt.subplot(511))
         plt.title('original')
      
     sig2 = pyspt.dsp.sample_shift(sig, 20, cyclic=True)
     if plot:
         sig2.plot_time(ax=plt.subplot(523))
         plt.title('cyclic shift +20 samples')
     sig2 = pyspt.dsp.sample_shift(sig, 20, cyclic=False)
     if plot:
         sig2.plot_time(ax=plt.subplot(524))
         plt.title('shift +20 samples')
         
     sig2 = pyspt.dsp.sample_shift(sig, -20, cyclic=True)
     if plot:
         sig2.plot_time(ax=plt.subplot(525))
         plt.title('cyclic shift -20 samples')
     sig2 = pyspt.dsp.sample_shift(sig, -20, cyclic=False)
     if plot:
         sig2.plot_time(ax=plt.subplot(526))
         plt.title('shift -20 samples')
     
     sig2 = pyspt.dsp.time_shift(sig, 40, cyclic=True)
     if plot:
         sig2.plot_time(ax=plt.subplot(527))
         plt.title('cyclic shift 40 sec')
     sig2 = pyspt.dsp.time_shift(sig, 40, cyclic=False)
     if plot:
         sig2.plot_time(ax=plt.subplot(528))
         plt.title('shift 40 sec')
     
     sig2 = pyspt.dsp.time_shift(sig, -40, cyclic=True)
     if plot:
         sig2.plot_time(ax=plt.subplot(529))
         plt.title('cyclic shift -40 sec')
     sig2 = pyspt.dsp.time_shift(sig, -40, cyclic=False)
     if plot:
         sig2.plot_time(ax=plt.subplot(5,2,10))
         plt.title('shift -40 sec')
Example #4
0
sweep = pyspt.generate_sweep(signal_length=3,
                             f_stop=20000,
                             bandwidth=1 / 24,
                             zero_padding=0.5)
#sweep = pyspt.dsp.normalize(sweep)

inv_sweep = pyspt.dsp.invert_spk(sweep, [20, 20000])
# inv_sweep.plot_freq()
# tmp = sweep * inv_sweep
# tmp.plot_freq()

# do meausrements
rec_dat = sd.playrec(sweep.timeData.T * 0.5, sweep.samplingRate, channels=1)
time.sleep(sweep.length)
rec = pyspt.Signal(rec_dat.T, sweep.samplingRate, domain='time')

# measurement post processing
ir = rec * inv_sweep
ir.signalType = 'energy'
ir.comment = "Impulse response"
ir.plot_freq()
ir.plot_time()

cmp = pyspt.other_functions.merge([sweep, rec])
cmp.plot_freq()


def get_delay(ir):
    idx_max = np.argmax(np.abs(ir.timeData))
    delay_time = ir.timeVector[idx_max]
Example #5
0
import sys
import matplotlib.pyplot as plt
import importlib
%matplotlib
# %%

# reload file 
del sys.modules['pyspt'] 
import pyspt
help(pyspt)


# %%

testSig = np.array(range(80)).reshape((8,10))
t = pyspt.Signal(testSig, 1)


plt.plot(testSig.T)


# %%



del sys.modules['pyspt'] 
import pyspt

defaultColorCycle = ['r', 'g', 'b', 'y']
lineStyles = ['-', '--']
Example #6
0
arrayconfig = configparser.ConfigParser()
arrayconfig.read('array_config.ini')

x_spacing = float(arrayconfig['array_info']['x_spacing'])
nBeams = float(arrayconfig['array_info']['nbeams'])
beamSep = float(arrayconfig['array_info']['beam_sep'])

# %% read file

with open(fileName, 'rb') as fh:
    tx_rf_outdata = pickle.load(fh)

nAntennas, nSamplesRF = tx_rf_outdata.shape

tx_sig = pyspt.Signal(tx_rf_outdata, tx_rf_samplingRate, iqInterleaved=True)
tx_sig.length /= nPulses  # take only first pulse

# %% up-mixing

tmp = pyspt.dsp.resample(tx_sig, tx_sig.samplingRate + usrp_mixing_freq * 2)
tx_sig = pyspt.dsp.frequency_mixer(tmp, usrp_mixing_freq)

# %% check phase in time signals
tData = tx_sig.timeData
iSample = 2000
print("angles in deg in time data: {}".format(
    np.angle(tData[1:, iSample] / tData[0, iSample]) / np.pi * 180))

# %%
# array on x-axis, y axis in facing direction of array
Example #7
0
 def test_channel_sum(self):
     dummyData = np.r_[1:6]  /10  +1
     dummyData2ch = np.vstack((dummyData, dummyData+1))
     s_2ch =  pyspt.Signal(dummyData2ch, 1, comment="two channels")
     s_2ch.sum()
Example #8
0
 def test_signal_class_init(self):
     sr = 10000
     phi = [ 2*np.pi*30*t / sr for t in range(3002) ]
     vec = np.sin(phi)
     r = pyspt.Signal(vec, sr, comment='sine test signal')
     self.assertIsInstance(r, pyspt.Signal)