forked from MaheshKarnani/insect_leg_practical_BYB_matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjointangle_BYB.m
54 lines (47 loc) · 1.41 KB
/
jointangle_BYB.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
%open data
clear all
close all
filenames=table(['00.wav';'45.wav';'90.wav']); %input the filenames you recorded here
figure;
n_recordings=3;%input the number of recordings here
for i=1:n_recordings
temp=cellstr(table2cell(filenames(i,1)));
filename=temp{1, 1};
importdata(filename);
data=ans.data;
clear ans;
srate=10000; %sample rate 10kHz
data=data(1:floor(size(data,1)/srate)*srate,:); %cut to nearest full second
%plot
trace1=-data(:,1);%reverse polarity
trace2=-data(:,2);%reverse polarity
x=(1:size(data,1))/srate;
ax(1)=subplot(2,n_recordings,i),plot(x,trace1);
hold on;
ylabel('V,mV');
title(filename);
%find peaks
trace=trace1;
clear locs
[~,locs]=findpeaks(trace,'MinPeakHeight',0.05,'MinPeakDistance',3);%change amplitude threshold here!
plot(x(locs),trace(locs),'rv');
ax(2)=subplot(2,n_recordings,i+n_recordings),histogram(x(locs),size(trace,1)/(1*srate));
ylabel('spike freq, Hz');
xlabel('time, s');
linkaxes(ax,'x');
mean_freq(i)=size(locs,1)/max(x);
end
%average waveform from last rec
wave=[];
window=20;%how many samples either side of spike
for i=5:size(locs,1)-5
wave(i,:)=trace([locs(i)-window:locs(i)+window]);
end
%Joint angle / firing rate plot
clear x
figure;
x=[0,45,90]; %input the joint angles you recorded here in degrees
plot(x,mean_freq,'ko-','LineWidth',3);
xlabel('joint angle, degrees');
ylabel('spike freq, Hz');
title('joint angle encoding');