Skip to content

Commit 3636c91

Browse files
committed
Plot power spectrum and FreqAnalysis now properly groups sweeps
1 parent 8ba7104 commit 3636c91

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,10 @@
299299
for iProfile = 1:nStimProfiles
300300
groupIdx{iProfile} = profileStartIdx(iProfile):profileEndIdx(iProfile);
301301

302-
theseSweeps{iProfile} = sortedLeakSub(groupIdx{iProfile},:);
302+
try theseSweeps{iProfile} = vertcat(sortedLeakSub{groupIdx{iProfile},:})';
303+
catch
304+
theseSweeps{iProfile} = sortedLeakSub(groupIdx{iProfile},:)';
305+
end
303306

304307
% if length(groupIdx{iProfile})>1
305308
% meansByStimProfile(iProfile,:) = nanmean(theseSweeps,1);

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,53 @@
2323
%%
2424
sinePeaksNorm = FrequencyAnalysis(ephysData, ephysMetaData, protList, 'matchType', matchType, 'norm', 1);
2525

26+
% okay we're just going to plot the power spectrum in the morning and
27+
% ignore the bode plot because I don't know what a "system" object really
28+
% is in matlab or if my data can be one, or what a linear time-invariant
29+
% system is or why a Bode plot is useful
30+
%%
31+
eachFreq = [0 10 30 100 200 500 1000];
32+
sf = 10000; %Hz
33+
allPSD = [];
34+
allF = [];
35+
allSize = [];
36+
37+
for iRec = 1:size(sinePeaksNorm,1)
38+
theseRecs = sinePeaksNorm{iRec,2};
39+
theseSizes = sinePeaksNorm{iRec,3}(:,1:3);
40+
41+
for iFreq = 1:length(theseRecs)
42+
try thisRec = theseRecs{iFreq}(theseSizes(iFreq,1):theseSizes(iFreq,2),:);
43+
[pxx,f] = periodogram(thisRec,[],[],sf);
44+
allF = [allF mean(f,2)];
45+
allPSD = [allPSD mean(pxx,2)];
46+
allSize = [allSize theseSizes(iFreq,3)];
47+
catch
48+
end
49+
end
50+
51+
end
52+
53+
[sortedSize, sortIdx, eachStimProfile, profileStartIdx, profileEndIdx] = ...
54+
sortRowsTol(allSize', 1, 1);
55+
56+
sortedPSD = allPSD(:,sortIdx);
57+
meanF = allF(:,1);
58+
groupIdx = cell(0);
59+
meansByFreq = [];
60+
61+
for iProfile = 1:length(eachFreq)
62+
groupIdx{iProfile} = profileStartIdx(iProfile):profileEndIdx(iProfile);
63+
thesePSD = sortedPSD(:,groupIdx{iProfile});
64+
meansByFreq (:,iProfile) = mean(thesePSD,2);
65+
end
66+
67+
plot(meanF,10*log10(meansByFreq));
68+
xlabel('frequency (Hz)');
69+
ylabel('dB');
70+
legend(num2str(eachFreq'));
71+
box off;
72+
% plotfixer;
73+
74+
chH = get(gca,'children');
75+
set(gca,'children',flipud(chH));

0 commit comments

Comments
 (0)