-
Notifications
You must be signed in to change notification settings - Fork 2
/
fftavg
82 lines (72 loc) · 3.57 KB
/
fftavg
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function [] = fftavg( start_directory )
%UNTITLED3 wiggle wiggle
% Is she wiggling?
% function [fold_detect,file_detect] = detector(path)
% cd(path)
% b = dir();
% files = dir('*.mat');
% isub = [b(:).isdir];
% nameFolds = {b(isub).name}';
% nameFolds(ismember(nameFolds,{'.','..'})) = [];
% fold_detect = size(nameFolds, 1);
% file_detect = size(files, 1);
% fprintf('Detecting\n');
% end %detector function
function [P1] = fourier(F)
Y = fft(F); %fft
P2 = abs(Y/400); %not a clue
P1 = P2(1:400/2,:); %fughetaboutit
P1(2:end-1,:) = 2*P1(2:end-1,:); %now you're just fucking with me
end
function[] = plotsave(avg)
% avgData = average(rawData);
Fs = 500; %sampling frequency
%f = Fs*(1:400/2)/400; %stuff
f = Fs*(1:400)/400;
plot(f,avg) %plotting the fft analysis for each whisker
axis([0 75 0 2]); %[xmin xmax ymin ymax]
title('Single-Sided Amplitude Spectrum of F(t)')
xlabel('Frequency (Hz)')
ylabel('|Power|')
fprintf('Data spans %.2f seconds\n', T);
tt = sprintf('%s',x(1).folder(end-2:end));
jj = sprintf('%s',x(1).folder(end-12:end-4));
figname = sprintf('%s-%s',jj,tt);
saveas(gcf, figname, 'fig'); %ERROR in saving due to lines 43 - 51 changing size of name
saveas(gcf, figname, 'png');
close all;
end %the fft function
cd (start_directory);
p = dir('jit*.mat'); %directory of jit mat files
jitlength = length(p); %length of directory of jit files
x = dir('*.mat'); %directory of all .mat files including jit
if jitlength > 0 %if there are jit files present
x = x(1:jitlength); %returns just .mat files w/o jit
end
fil = length(x); %length of directory of .mat files w/o jit files
T = fil*(0.8); %time interval graphed
if fil < 1
fprintf('error: no files found.\n');
else
data_array = load(x(1).name);
data_array = struct2array(data_array);
c = nanmean(data_array(1:400,:)); %select first 400 points from each column and finds average of each column
t = data_array(1:400,:); %first 400 points for each column
rawData = bsxfun(@minus,t,c); %function to subtract vector average from array
if fil > 1
for ii=2:fil
data_array = load(x(ii).name);
data_array = struct2array(data_array);
c = nanmean(data_array(1:400,:)); %select first 400 points from each column and finds average of each column
t = data_array(1:400,:); %first 400 points for each column
F = bsxfun(@minus,t,c); %function to subtract vector average from array
rawData = [rawData,F]; %append new data to original data matrix
end
avg = mean(rawData,2);
avgData = fourier(avg);
else
avgData = fourier(rawData);
end
plotsave(avgData);
end
end