Lab 8:
Recording from neurons sensing roach blaberus leg spine deflection
(try to complete before Thanksgiving!)

Background:  An electrode near nerve cell processes can record what physiologists call action potentials (APs): transient changes in voltage due to the opening and closing of membrane channels that allow passage of ions such as sodium, potassium, calcium or chloride. Even removed from the body of a roach, the sensory fibers in a leg can can function for more than 3 hours. In this lab you will use needle electrodes to record extracellular AP "spikes" that are spontaneous and/or correlated with joint flexion or leg "spine/spur" stimulation. You will collect data with a multipoint Analog IN icon feeding a Matlab script that will compute total spike count and maximum rate.

In Lab 8 the sensors of joint angle or spur stimulation are live nerve cell endings that change internal voltage due to mechanical stress. They convert voltage changes into pulse frequency, acting as voltage controlled oscillators.

Lab 8 subject, Blaberus. "Adult size, 5 to 6 cm. Common to tropical America. Also known as the palmetto bug or the death's head bug, the Blaberus is the largest cockroach in the US." from www.blaberus.com. And Greg's Exotics in Yucca Valley CA http://www.gregsexoticinverts.com/ (our current supplier). We have blaberus craniifer and blaberus discoidalis http://www.gregsexoticinverts.com/bdiscoidalis.htm .
2013: Kyle Kandlilian, raptorandclawz.com; 2014: http://www.aaronpauling.com/

Requirements:
As you will see in the Lab 8 class demo, you (or we) will (1) anaesthetize a blaberus with cold (2) amputate one of its larger caudal legs and place the leg on silastic block in the copper pocket on an adjustable vise pivot. We'll pin the leg with a dissecting pin at the proximal joint to the silastic block. We'll insert a 3 tungsten electrode array into the exoskeleton at the segment of the leg above the spurs / spines (smooth exoskeleton, thigh. "femur"), with 2 mm distance between electrodes. Make sure not to pierce the needles into the joints themselves.

(1) Before you start, create a VI that can detect total spike count and peak rate (1/t-min) of response during a 1 second interval.

Matlab Help: Below is the screen shot of a VI that acquires 1 second of a waveform at 10000 Hz sampling rate, then passes the waveform on to a Matlab script that, in a loop, threshold discriminates, counts pulses, and finds a peak rate. Note that the VI also reports the total count!


The DAQ Assistant can have external sample rate and sample number override the internal sets of those parameters.

The Matlab script above looks for threshold, not window discrimination, but entered correctly, it does work. You will want to add a waveform graph to your front panel that takes as input the output of the AI Mult Pt read icon, so you can what to set your your threshold thet to, after acquiring spike data.

If you make your script a *.m file in Matlab you can single step through and watch what it does. Be sure to add to the start of the code thet, dt and a short D_A row vector.

Read about how to use the Matlab Function icon in LabVIEW: (Math Function menu choice). Understand how to add INPUT and OUTPUT to the script icon. Study the script above: try to see what the for loop is doing, and how the max_rate is computed. Note that the script as written uses one threshold only, not two as required by a window discriminator, thus designing a window discriminator may become your FTQ...

Your Matlab script problem may be debugging without the full Matlab support of breakpoints. You can help yourself by sending variables to the front panel. See the "debug" output on the diagram above. Use JD as a debugging tool if you like, or copy all the text to a Matlab script file, add at the top of the file thet, dt and D_A inputs, and single-step in Matlab.

As you build up your script, try running it. Make sure you attach the error message in the bottom right hand corner. In the script above ordinary words are deliberately misspelled: flag is a function in Matlab... The size function can have 2 or more outputs, making it a vector. On the Inputs and Outputs designated on the edges of the icon you need to declare them as real vectors.

You should add hysteresis to the threshold detector:
if flg2 == 1 & D_A(ii) < 0.95*thet
to avoid extra counts due to signal noise as the threshold is crossed (debouncing...).

If you see an error message in the front panel, start removing code or inputs or outputs until you return to an error-free condition...

In the MAX utility you can with Analog In see the approximate size of your signal, to know where to set thet, the threshold.

Create and test your Matlab script VI before setting up blaberus: Use a 100 Hz 0-2v amplitude "cardiac" waveform as your test input.

(1b) Since the B&H Lab 8 setup sends unfiltered signal to the 6024E card (normally on ACh 5, pins 60, 67) you need to add a digital bandpass filter after the "multipoint scan" and before display or input to Matlab script. Suggestion: Choose a Butterworth filter and send its output directly to A_D input; find input "dt" from a breakout of the unfiltered waveform. Have front panel controls for HIGH PASS and LOW PASS cutoff frequencies...normally about 200 Hz and 3000 Hz.

NOTE ABOUT LABVIEW RUNNING MATLAB: IF YOUR VI CONTINUALLY GIVES MATLAB ERRORS AND THERE IS NO OBVIOUS FAULT IN THE CODE, TRY QUITTING BOTH LABVIEW AND MATLAB, THEN RESTARTING ONLY LABVIEW, AND YOUR VI, AND LETTING LABVIEW OPEN AN INSTANCE OF MATLAB THAT WILL BE PROPERLY "ATTACHED" TO LABVIEW. IT IS POSSIBLE TO BE RUNNING AN INSTANCE OF MATLAB THAT HAS NO LINK TO LABVIEW RUNNING AT THE TIME.

What about using Lab 0.5 window discriminator for this Lab? In principal that would be good, and all you need...The practical problem turns out to be that Lab 0.5 did a single point read of input so it could evaluate in "real time" any threshold crossings. If you count the number of single point reads that can be done in one second in LabVIEW the answer turns out to be about 1600. 1600Hz then would be your SAMPLE RATE, resulting in Nyquist rate of 800 Hz. The action potential contains information up to the 3KHz range, so the sample rate of a single point read in a while loop is a little low.

But if you set the TEAC LP filter to 1000 Hz cutoff, you can try your Lab 0.5 without "too much" aliasing... One improvement is needed (assuming your window discriminator already counts valid events): Design a "rate meter" so you can look for the maximum rate (minimum time between events).

Below is a suggestion for how to implement that feature, and a timer. The clock icon keeps time in msec. Note the rate meter does NOT pick off the maximum rate: How can that be done?

Annoyingly, because the timer icon is good to the nearest msec only, the rate meter is rather crude for higher rates: 1000Hz, 500Hz, 333H, 250Hz, etc.

After verifying that you see and hear multi-unit activity, swing into position the AO dissecting microscope and observe the "spines" as you stimulate them with (say) a sharpened plastic straw: Which way does a spur bend? can you associate individual spurs with a single unit? Is the response of a single spur graded as to stimulus intensity? (spikes/sec vs amount of bending). Are responses to sudden spur bending sustained or transient?

(2) Before the amputation: set up the electronics: Attach clip leads that take the signal from the needle electrodes to a 524 preamp set for gain 1000. The 524 output goes to a TEAC equalizer (filter bank) and thence to a Altec-Lansing audio amplifier. A second wire off the 524 output ends up as an Analog in on your green LabVIEW connector card. A scope probe also monitors the 524 output.

(3) You may be able to measure the impedance of the electrode pair by inserting the electrodes into saline-soaked paper and running the scope "probe comp" through a 10M-ohm resistor to the non-ground of the electrode set.

Establish a low noise recording you can listen to. Minimize the the 60Hz sound and high frequency hiss by adjusting the equalizer.

(4) Blaberus can be anaesthetized in a cold atmosphere. I will use sharp surgical scissors for amputation. Place the leg on the silastic block. Use a dissecting needle to hold the leg in position on the proximal side. Pierce the "thigh" exoskeleton with the needle electrodes, at about 2-4mm spacing. Turn up the audio sound and listen for multiunit nerve activity. See how the sound changes if you turn to different HP filter settings. Make sure you have good visuals through the binocular dissecting microscope.

Evaluate spontaneous and evoked activity. Stimulate the leg by extending and flexing the "knee" joint. Touch the leg spines with a camel's hair brush, or blow air on the feeler at the end of the leg. Make sure you ground yourself, to minimize noise.

Notice through the dissection microscope that a spine seems to be a torsional spring, and has a preferred direction to be active. There is one special spine at the joint that is there to sense joint angle. Flex one spine and record the response.

(5) Use LabVIEW utility MAX to look at the analog channel. Try to select a good threshold while watching evoked activity on the Test Panel analog IN channel strip chart. It will be useful on your VI to have a waveform graph as a function of time (2 sec) to see reasonable threshold levels...

(6) What to show us:
Measure spontaneous and evoked counts. Try to assess variability to repeated stimulations. See if you can hear more than one distinct unit contributing to the response. Listen for transient and sustained responses to stimuli.

Run the signal from the roach leg, to the needle electrodes, through the amplifier and filters, to the scope, the audio monitor and into LabVIEW. Collect 1 second worth of data, with evoked and spontaneous trials. Adjust for best threshold. Have a VI process the signal to count events that exceed the threshold, and report peak rate. See if you can demonstrate direction selectivity in knee joint rotation, or direction of stroking leg bristles.

About peak rate: If you were recording from one nerve cell only, you'd expect the peak rate to be less than 1000Hz. But your electrodes are recording from several units simultaneously. Depending on the threshold you set, you may see something like a half-dozen units. So if two different units fire v. near each other in time, your recorded peak rate may be greater than 1000Hz. If you set a high enough threshold (or narrow enough window) so that you are recording from only the unit with the greatest amplitude, your peak rate should be less than 1000Hz.

See what happens to unit activity if you extend the joint to near its limit, or flex to "jack-knife" closure. Can you hear one unit firing for extension, and a different one for flex?

Calibration: You should show us that your counting and max_rate report the correct numbers for a calibrating pulse train from the waveform generator.

FTQ: You will likely be asked to add to the code to the Matlab script for window discrimination capability. If so, you will need another threshold, thet_up, and another flag, say flg3.
If D_A(ii) > thet_up,
   flg3 = 1;
end

Later when the test
D_A(ii) < thet_down & flg2 == 1
is encountered you will also test flg3; if flg3 == 1 then skip incrementing cnt. Should you also reset flg2 to 0 if flg3 == 1 ?

When to reset flg3? One way: reset flg3 at the beginning of ii loop:
if flg2 == 0
   flg3 = 0;
end

... flg2 will be "1" after thet is crossed, and will be reset on successful cnt increment or detection of flg3 itself. You can add the window discrimination in the lab, and use "cardiac" waveform to move your window over a lower level part of the cardiac waveform...

With blaberus, we will test your window discriminator by first setting thet_up to a large value and seeing the same result as threshold detection. Then we will lower thet_up until the spike count decreases, finally going to 0.

Once the basic results are assessed, you're welcome to try any other stimulus-response experiments you like.

convenience: Matlab code in html:
sze = size(D_A);
flg = 0;
flg2 = 0;
cnt = 0;
tim_prev = 0;
tim_min = 50;
for ii = 1:sze(2)
tim_now = dt*ii;
if D_A(ii) < thet
flg = 1;
end
if flg == 1 && D_A(ii) > thet
flg2 = 1;
end
if flg2 == 1 && D_A(ii) < thet
cnt = cnt +1;
tim_del = tim_now - tim_prev;
if tim_del < tim_min & cnt > 1
tim_min = tim_del;
end
tim_prev = tim_now;
flg = 0;
flg2 = 0;
end
end
max_rate = 1/tim_min