ソースを参照

debugging the aSIT

dianamaro 2 年 前
コミット
ec67070df0
4 ファイル変更191 行追加58 行削除
  1. 29 23
      aSIT.ipynb
  2. 139 27
      controllers/sound.ipynb
  3. 15 0
      controllers/sound.py
  4. 8 8
      postprocessing.ipynb

ファイルの差分が大きいため隠しています
+ 29 - 23
aSIT.ipynb


ファイルの差分が大きいため隠しています
+ 139 - 27
controllers/sound.ipynb


+ 15 - 0
controllers/sound.py

@@ -1,5 +1,7 @@
 import numpy as np
 import time
+from scipy.signal import lfilter
+
 
 class SoundController:
     # https://python-sounddevice.readthedocs.io/en/0.3.15/api/streams.html#sounddevice.OutputStream
@@ -38,9 +40,21 @@ class SoundController:
 
     @classmethod
     def get_tone_stack(cls, cfg):
+        # silence
         silence = np.zeros(2, dtype='float32')
         sounds = {0: np.column_stack([silence for x in range(cfg['n_channels'])])}
 
+        # noise
+        filter_a = np.array([0.0075, 0.0225, 0.0225, 0.0075])
+        filter_b = np.array([1.0000,-2.1114, 1.5768,-0.4053])
+
+        noise = np.random.randn(int(0.25 * cfg['sample_rate']))  # 250ms of noise
+        noise = lfilter(filter_a, filter_b, noise)
+        noise = noise / np.abs(noise).max() * 0.5
+        noise = noise.astype(np.float32)
+        sounds[-1] = np.column_stack([noise for x in range(cfg['n_channels'])])
+        
+        # all other sounds
         for i, snd in enumerate(cfg['sounds']):
             tone = cls.get_pure_tone(snd['freq'], cfg['pulse_duration'], cfg['sample_rate']) * cfg['volume']
             tone = tone * cls.get_cos_window(tone, 0.01, cfg['sample_rate'])  # onset / offset
@@ -86,6 +100,7 @@ class SoundController:
                     continue
 
                 roving = 10**((np.random.rand() * cfg['roving'] - cfg['roving']/2.0)/20.)
+                roving = roving if int(selector.value) > -1 else 1  # no roving for noise
                 stream.write(sounds[int(selector.value)] * roving)
                 with open(cfg['file_path'], 'a') as f:
                     f.write(",".join([str(x) for x in (t0, selector.value)]) + "\n")

+ 8 - 8
postprocessing.ipynb

@@ -23,7 +23,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": 1,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -112,8 +112,8 @@
     "        dt = np.diff(pos_at_freq[:, 0])\n",
     "        speed = np.concatenate([dx/dt, [dx[-1]/dt[-1]]])\n",
     "\n",
-    "        proc.create_dataset('timeline', data=np.column_stack([pos_at_freq[:, 0], x_smooth, y_smooth, speed]))\n",
-    "        proc.attrs['headers'] = 'time, x, y, speed'\n",
+    "        timeline = proc.create_dataset('timeline', data=np.column_stack([pos_at_freq[:, 0], x_smooth, y_smooth, speed]))\n",
+    "        timeline.attrs['headers'] = 'time, x, y, speed'\n",
     "\n",
     "        # save trials\n",
     "        events = np.array(f['raw']['events'])\n",
@@ -131,8 +131,8 @@
     "\n",
     "            trials[i] = (t_start_idx, t_end_idx, x_in_m, y_in_m, r_in_m, state)\n",
     "\n",
-    "        proc.create_dataset('trial_idxs', data=trials)\n",
-    "        proc.attrs['headers'] = 't_start_idx, t_end_idx, target_x, target_y, target_r, fail_or_success'\n",
+    "        trial_idxs = proc.create_dataset('trial_idxs', data=trials)\n",
+    "        trial_idxs.attrs['headers'] = 't_start_idx, t_end_idx, target_x, target_y, target_r, fail_or_success'\n",
     "\n",
     "        # save sounds\n",
     "        sounds = np.array(f['raw']['sounds'])\n",
@@ -150,8 +150,8 @@
     "            sound_idxs[i] = (left_idx, sounds[i][1])\n",
     "            delta = 10**5\n",
     "\n",
-    "        proc.create_dataset('sound_idxs', data=sound_idxs)\n",
-    "        proc.attrs['headers'] = 'timeline_idx, sound_id'\n",
+    "        sound_idxs = proc.create_dataset('sound_idxs', data=sound_idxs)\n",
+    "        sound_idxs.attrs['headers'] = 'timeline_idx, sound_id'\n",
     "        \n",
     "    return h5name"
    ]
@@ -180,7 +180,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.8.10"
+   "version": "3.8.8"
   }
  },
  "nbformat": 4,