Skip to content

Commit 6a2b527

Browse files
committed
FreqAnalysis now normalizes the whole sweep to on1 peak if normalizeFlag is on instead of just the mean stats, SinePowerSpec script added section to exclude sweeps based on PD trace and combine that info, selectSweeps simplified tVec calc
1 parent c395b51 commit 6a2b527

3 files changed

Lines changed: 63 additions & 8 deletions

File tree

Analysis/SK/GUIs/selectSweepsGUI.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
case 'A'
6565
for iSweep = 1:nSweeps
6666
% Plot the sweep in its proper subplot against time
67-
tVec = 0:1/sf:length(data(:,iSweep,1))/sf-(1/sf);
67+
tVec = (0:length(data(:,iSweep,1))-1)/sf;
6868
handles.plt(iSweep) = subplot(nRows,nCols,iSweep,...
6969
'Parent', handles.uip);
7070
plot(tVec,data(:,iSweep,1)*1E12);
@@ -92,7 +92,7 @@
9292
if isempty(strfind(protName,'Calib')) && channel == 1 % for non-PD calib traces, current clamp traces
9393
for iSweep = 1:nSweeps
9494
% Plot the sweep in its proper subplot against time
95-
tVec = 0:1/sf:length(data(:,iSweep,1))/sf-1/sf;
95+
tVec = (0:length(data(:,iSweep,1))-1)/sf;
9696
handles.plt(iSweep) = subplot(nRows,nCols,iSweep,...
9797
'Parent', handles.uip);
9898
plot(tVec,data(:,iSweep,1)*1E3);
@@ -112,7 +112,7 @@
112112
elseif isempty(strfind(protName,'Calib')) && channel == 3 % for PD signal for non-calib traces
113113
for iSweep = 1:nSweeps
114114
% Plot the sweep in its proper subplot against time
115-
tVec = 0:1/sf:length(data(:,iSweep,1))/sf-1/sf;
115+
tVec = (0:length(data(:,iSweep,1))-1)/sf;
116116
handles.plt(iSweep) = subplot(nRows,nCols,iSweep,...
117117
'Parent', handles.uip);
118118
plot(tVec,data(:,iSweep,2)); %leak-subtracted trace
@@ -132,7 +132,7 @@
132132
else % for PD calib traces
133133
for iSweep = 1:nSweeps
134134
% Plot the sweep in its proper subplot against time
135-
tVec = 0:1/sf:length(data(:,iSweep,1))/sf-1/sf;
135+
tVec = (0:length(data(:,iSweep,1))-1)/sf;
136136
handles.plt(iSweep) = subplot(nRows,nCols,iSweep,...
137137
'Parent', handles.uip);
138138
plot(tVec,data(:,iSweep,1));

Analysis/SK/Scripts-in-progress/FrequencyAnalysis.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
%
44
% parameters in SinePeaks{:,3}:
55
% [sineStart sineEnd sineFreq nReps steadyI sqOn1 sqOff1 sqOn2 sqOff2 sqOnRatio sqOffRatio]
6+
%
7+
% normalize flag also normalizes the individual saved sweeps
8+
69

710
function sinePeaks = FrequencyAnalysis(ephysData, ephysMetaData, protList, varargin)
811

@@ -319,7 +322,8 @@
319322

320323
stimMetaData(:,1:2) = sortedStim{1,iStim}(profileStartIdx,1:2);
321324
stimMetaData(:,3) = eachStimProfile(:,iStim);
322-
stimMetaData(:,4) = nReps;
325+
stimMetaData(:,4) = repmat(extFilterFreq{iCell},size(stimMetaData,1),1);
326+
stimMetaData(:,5) = nReps;
323327

324328
% Find mechanoreceptor current peaks and append to sinePeaks for
325329
% that stimulus number.
@@ -341,6 +345,8 @@
341345

342346
if normalizeFlag
343347
steadyMeans = steadyMeans./squareMeans(:,1);
348+
normMeans = num2cell(squareMeans(:,1)*1e-12);
349+
theseSweeps = cellfun(@(x,y) x/y, theseSweeps,normMeans','un',0);
344350
end
345351

346352
sinePeaks{iCell,1} = cellName;

Analysis/SK/Scripts-in-progress/SinePowerSpec.m

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
stimPosition = {'anterior'};
66
wormPrep = {'dissected'};
77
cellDist = [40 150];
8-
extFilterFreq = 5;
8+
extFilterFreq = [2.5 5];
99
includeFlag = 1;
1010

1111
antSineCells = FilterRecordings(ephysData, ephysMetaData,...
@@ -16,14 +16,61 @@
1616

1717
clear cellDist strainList internalList cellTypeList stimPosition resistCutoff ans wormPrep;
1818

19+
%NEXT: check to see if there's a difference in the power spectrum (and
20+
%amplitude attenuation where applicable) for 2.5 vs. 5kHz photodiode
21+
%signals. If they look the same, combine the data.
22+
1923
%%
24+
2025
ExcludeSweeps(ephysData, protList, antSineCells, 'matchType', matchType, 'channel', 1);
2126

2227
clear protList matchType;
2328

29+
%% Check if the PD signal is useful/shows abnormalities
30+
% Make list of only sweeps with stable current AND good PD signal (lower
31+
% noise, high enough voltage for SNR, no weird movements during sine)
32+
33+
% selectedSweeps_I = ExcludeSweeps(ephysData, protList, antSineCells, 'matchType', matchType, 'channel', 1);
34+
% selectedSweeps_PD = ExcludeSweeps(ephysData, protList, antSineCells, 'matchType', matchType, 'channel', 3);
35+
36+
selectedSweeps_I = ImportMetaData();
37+
selectedSweeps_PD = ImportMetaData();
38+
39+
40+
% This method of comparing the two lists only works if there's only one
41+
% series/sweep per row. It simply concatenates cell ID, series, and sweep
42+
% number into a char row. For more sweeps per series, you will need to loop
43+
% (find matching cell/series combo, then check which sweeps are matching).
44+
a = selectedSweeps_I;
45+
b = selectedSweeps_PD;
46+
a(:,2) = cellfun(@num2str, a(:,2),'un',0);
47+
b(:,2) = cellfun(@num2str, b(:,2),'un',0);
48+
49+
a = cellfun(@(x,y,z) [x y z], a(:,1),a(:,2),a(:,3),'un',0);
50+
b = cellfun(@(x,y,z) [x y z], b(:,1),b(:,2),b(:,3),'un',0);
51+
a = vertcat(a{:});
52+
b = vertcat(b{:});
53+
54+
selectIdx = ismember(a,b,'rows');
55+
56+
selectedSweeps = selectedSweeps_I(selectIdx,:);
57+
selectedSweeps(:,3) = cellfun(@(x) ['' x],selectedSweeps(:,3));
58+
59+
% save the new selectedSweeps list to file
60+
[filename, pathname] = uiputfile(...
61+
{'*.xls;*.xlsx', 'Excel files';
62+
'*.*', 'All files'}, ...
63+
'Save sweep list to .xls file:');
64+
fName = fullfile(pathname,filename);
65+
xlswrite(fName, selectedSweeps);
66+
67+
clear fName filename pathname a b selectedSweeps_I selectedSweeps_PD selectedSweeps selectIdx
68+
69+
2470
%%
2571
sinePeaksNorm = FrequencyAnalysis(ephysData, ephysMetaData, protList, 'matchType', matchType, 'norm', 1);
2672

73+
sinePeaks = FrequencyAnalysis(ephysData, ephysMetaData, protList, 'matchType', matchType, 'norm', 0);
2774
% okay we're just going to plot the power spectrum in the morning and
2875
% ignore the bode plot because I don't know what a "system" object really
2976
% is in matlab or if my data can be one, or what a linear time-invariant
@@ -97,13 +144,15 @@
97144

98145
%% Plot steady state sine comparison
99146

147+
whichPeaks = sinePeaksNorm;
148+
100149
eachFreq = [0 10 30 100 200 500 1000];
101150
sf = 10000; %Hz
102151
allSteady = [];
103152
allSize = [];
104153

105-
for iRec = 1:size(sinePeaksNorm,1)
106-
theseSizes = sinePeaksNorm{iRec,3}(:,[1:3,5]);
154+
for iRec = 1:size(whichPeaks,1)
155+
theseSizes = whichPeaks{iRec,3}(:,[1:3,6]);
107156

108157
for iFreq = 1:size(theseSizes,1)
109158
allSteady = [allSteady; theseSizes(iFreq,4)];

0 commit comments

Comments
 (0)