<jupyter_start><jupyter_text>Test the bnk module with a PCB accelerometer Here we test the amplitude and frequency calibration of the BnK device using a [PCB accelerometer](https://www.pcb.com/spec_sheet.asp?model=352C650) attached to a [PCB calibrated shaker](https://www.pcb.com/spec_sheet.asp?model=394C06&item_id=2198).<jupyter_code>import time

from bnk.bnk import  OpenWav, WavHeader, Instrument<jupyter_output><empty_output><jupyter_text>Gather some data from a PCB accelerometer The accelerometer is screwed onto the top of the shaker, and is connected to channel 4 of the BnK device.<jupyter_code>bnk_ip = "10.1.1.66"
ADAC = Instrument(bnk_ip)
ADAC.disable_all()
ADAC.set_samplerate(16384)
ADAC.set_name("PCB calibrated shaker")
ADAC.set_channel(    
                channel=4,
                name='PCB 394C06 SN 2706 1 g at 159.2 Hz',
                c_filter='7.0 Hz',
                c_range='10 Vpeak',
                sensitivity=0.0991,
                unit='g',
                powered=True,
                serialNumber='LW207441',
                transducerType='PCB352C65',
                )
ADAC.powerup()
print("Waiting for amplifier in PCB to stabilise ...")
time.sleep(20)
print("Recording")
recording_id = ADAC.record(2)
ADAC.powerdown()
ADAC.list_recordings(start = -5)
WAV_file = ADAC.get_wav(directory='../samples', recording_id=recording_id)
print(WAV_file)
ADAC.delete_recording(recording_id=recording_id)<jupyter_output><empty_output><jupyter_text>Load and display the data<jupyter_code>WAV_file = '../samples/PCB_calibrated_shaker_20190805205924.wav'
wav_data, metadata, json_data = OpenWav(WAV_file)
#!conda install -c conda-forge bokeh -y
from ipywidgets import interact
import numpy as np

from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
output_notebook()
plt = figure(
    title = metadata['Label'],
    width = 800,
    height = 400,
    tools = ['xwheel_zoom','xpan','save','reset']
    
    )

sr = metadata['SampleRate']
N = len(wav_data)
delta_t = 1.0/sr
t = np.arange(0,N*delta_t,delta_t)

phase = 4.4
amp = 1
freq = 159.2
n = 1000

c = 0 # Channel
plt.line(t[:n], 
         wav_data[:n,c], 
         line_color='blue',
         legend=metadata['ChannelNames'][c]
        )
r = plt.line(t[:n],
             amp*np.sin(2*np.pi*freq*t[:n] + phase),
             line_color='red', 
             legend=f"{amp}  sin({freq} * 2πt + {phase})",
            )

plt.legend.click_policy="hide"

def update(phase=0):
    r.data_source.data['y'] = amp*np.sin(2*np.pi*freq*t[:n] + phase)
    push_notebook()

show(plt, notebook_handle=True)
interact(update, phase=(0, 2*np.pi, 0.1))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1292364990689013, 'fraction_numerical': 0.04059590316573557, 'mean_word_length': 3.5142857142857142, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '499604', 'license': 'MIT', 'n_tokens_mistral': 1074, 'n_tokens_neox': 967, 'n_words': 200, 'path': 'examples/PCB_Test.ipynb', 'repo_name': 'uwasystemhealth/PyBnK', 'size': '2685'}