Unformatted Attachment Preview
BME 526 Introduction to Neural Engineering
Homework #1
1) Chose a data file and import it into Matlab. (1 point)
a. Each .mat file contains 60 seconds of neural data sampled at 30kHz.
b. The data has been highpassed filtered.
c. There are two vectors “time” and “wave” in each file. The “time” vector contains the
time of each sample taken in seconds, while the “wave” vector contains the value of
each sample taken in µVolts.
2) Determine a quantitative threshold for identifying action potentials as multiple of the
variance in your signal. (2 points)
a. Write code to calculate the magnitude of the “signal”.
b. In a few sentences explain the rational for the measure of signal you chose in the
written document.
c. Write code to calculate a metric of variance (“noise”) in the signal.
d. In a few sentences explain the rational for the measure of variance you chose in the
written document.
e. Write code to calculate the signaltonoise ratio (SNR).
f. Report the SNR in the written document.
g. Inspect your data to determine how many times variance to use for the threshold of
detecting action potentials.
h. Write code to plot the raw (time x wave) data and a line indicating the threshold used
and place the plot in your written document.
i. Write code to build a matrix of action potential data and a matrix of noise data.
i. You are building a matrix of snippets of data around each threshold crossing
(hint: findpeaks() is a very useful function).
ii. Action potentials are typically 1 – 2 ms in duration.
iii. Set your threshold just low enough that you capture some “noise” along with
the action potentials. Don’t go too low or your matrix will be very large.
iv. Come up with another way to calculate a metric of variance (“noise”) in the
signal other than using a threshold. Write code to use the method and briefly
explain your method in the written document.
j. Briefly describe your results in the written document.
3) Sort you action potentials. (2 points)
a. Use principle components analysis (PCA) to cluster your spikes and noise data.
i. Removing any consistent offset in the data will help with clustering.
ii. Aligning the action potentials will also help with clustering.
iii. Matlab has several builtin principle components functions with nice features
that you can use.
b. In your written document briefly describe how you differentiate signal from noise in
the output of the PCA.
4) Plot your PCA results. (2 points)
a. Write code to plot all the individual action potential snippets, the mean action
potential, and the standard error for all neurons in the data file you choose, using a
different color (e.g. red, blue, green) for each neuron. On the same figure plot the
individual noise snippets, the mean noise snippet, and the standard error of all noise
snippets in black.
b. Write code to plot the first three principle components of your clustered action
potential and noise data as a single 3D plot. Use the same colors for action potentials
and noise as used in part 4a.
c. Place these figures and briefly discuss the results it in the written document.
5) Repeat this process for a different data file. (2 points)
a. Rerun your code on a different data file.
b. Write a brief discussion in the written document comparing the results and any
problems you encountered.
6) Upload the code (.m file) and the written document (.doc, .docx, or .pdf file) to the class
website. (1 point)
a. In the comments of your Matlab code, indicate what data files, e.g. “17.mat”, you
analyzed.
b. Comment your code so that I can easily understand what it is doing.
c. Use proper titles, axis labels, and legends for all figures.
d. Name files with this format “lastname_firstname_HW1.m” and
“lastname_firstname_HW1.docx”.
y Greger's screen
View Options
PUBLISH
VIEW
Run Section
Breakpoints
Run
Run and Advance
Run and
Time
Advance
EDIT
BREAKPOINTS
RUN
es BME 526 homework HW1 data
Command Window
Editor  HW1 solution.m
intracellular_AP_analysis.mx•HW1_solution.m
ga
TDT2Matlab_script_2020.m2 DBS_basic_analysis.m XHHparameters.m
1
8% load data
2 
clear;
3 
clc;
4 – close all;
I
5
6

load('t052098_120_seconds.mat');
7
8
9 
10 
figure;
plot (time, wave);
ylabel ('Volts');
xlabel('Seconds');
11 
12
I
13
1
4
% Threashold
15
16 
clc;
17
18 
signal_wave = max (wave)

min (wave);
19
20 
21
tic;
rms wave norm = norm (wave) /sqrt(length (wave));
toc
22
23
24

tic;
rms wave
25 
26 
= rms (wave);
toc
27
28 
29 
tic;
std wave = std (wave) ;
toc
30 
31
ve));
32
snr wave =
signal_wave/cms_wave;
33
34
threshold = 6.0*rms_wave;
35
31
Participants
Chat
Share Screen
Record
Reactions
Run Section
Breakpoints
Run
Run and
Advance
Advance
Run and
Time
BREAKPOINTS
RUN
 homework HW1 data
Command Window
Editor  HW1 solut
TDT2Matlab_script_2020.m * DBS_basic_analysis.m X HHparameters.ms intracellular_AP_analysis.mx
load('t052098 120 seconds.mat');
M

7
8
9 
10 
$$
figure;
plot (time, wave) ;
ylabel('Volts');
xlabel('Seconds');
11
12

13
1
$$ Threashold
15
16 
clc;
17
18
signal_wave = max (wave)
min (wave) ;
19
20

tic;
Ims_wave_norm = norm (wave) /sqrt(length (wave));
21

22

toc
23
24
tic;
25
rms_wave =
rms (wave);
26 
toc
27
28
  
tic;
std wave
29
std (wave);
30
toc
<
31
32
Snr Wave
signal wave/rms wave;

>
33
34

threshold = 6.0*rms wave;
35
36
37
38
39
Plot time vesus voltage data
plot(time, wave) ;
hold on

<
4
31
Participants
Chat
Share Screen
Record
Reactions
56
fe
g
fio
fu
+
11
ادا
BREAKPOINTS
cuments classes BME 526 homework HW1 data
RUN
насе
Size
Bytes
1x1
1x1
1x1
1x1
1x1
1x1
1x1
1x240...
24000...
@Command
Window
Editor  HW1 solutionm
TDT2Matlab_script_2020.m DBS_basic_analysis.m.HHparameters.mx  intracellular_AP_analysis.mx "HW1_solution.mx gaussing_2D.m
8
rms wave norm = norm (wave) /sqrt (length (wave));
8
toc
8
23
8
tic;
8
25  Ins wave = rms (wave) ;
8
26  toc
8
19200008
19200008
28  tic:
29 
std wave std (wave);
toc
Snr Wave
signal wave/rms wave;
33
Bradle
threshold = = 6,0* rms wave;
36
o
38
39 —
Bryo
% Plot time vesus voltage data
plot (time, wave); I
hold on
% Plot black line at threshold
line ([O time (end)], [threshold threshold], 'Linewidth",2, 'Color', 'k');
41
42 
43
Ad
45 
% plot green line at rootmeansquared
line ([O time (end)], [rms_wave rms_wave], 'LineWidth', 2, 'color','g', 'LineStyle',':');
Plot red line at STD
line ([O time (end)], [std wave std wave], 'LineWidth', 2, 'Color', 'r', 'LineStyle','');
46
47 
48
n (wave) :
50 
n (wave)
ylabel('Volts');
xlabel('Seconds');
51 –
52
ength (wave));
53
8% Find action potential peaks NEW
55
% Set the parameters for the wave input (sample rate)
4
OS 31
Record
Reactions
Darticinants
Chat
Share Screen