| 
Functions | 
| Check if fileName is a path or a simple file name if
 | isempty (strfind(fileName,'\'))%only filename if exist(fullfile(dirs.DataIn | 
| else | warning ('File%s does not exist in the specified path', fileName) | 
| end else complete path if | exist (fullfile(fileName),'file') diodeData | 
| else | warning ('File%s does not exist in the%s folder', fileName, dirs.DataIn)%end end%Checking rows are for channels and create[d1 | 
| else end Getting the stim frequencies if
 | strfind (fileName,'DiodeData_15') stimFreq | 
| elseif | strfind (fileName,'DiodeData_sweep') stimFreq | 
|  | title (fileName,'FontWeight','Bold') xlabel('Sec' | 
|  | ylabel ('PhotoDiode State','FontWeight','Bold') xRange | 
| Get start of | stimulation (flickering) fprintf('Get ''start''of stimulation for freq.%i\n' | 
| Get start of | stimFreq (1))[xRange(1) | 
| Get start of Extract sections for each
 | freq (time boundaries) if strfind(fileName | 
|  | SweepTimes (iFreq-1,:) | 
| end else | fprintf ('Get ''end''of stimulation/flickering for freq.%i\n', stimFreq(1))[xRange(1 | 
|  | plot (f, 10 *log10(pxx)) plot(f | 
| pxx | xlabel ('Frequency') | 
|  | ylabel ('dB') | 
|  | title (sprintf('Periodogram of photodiode%s', titleStr)) | 
| end Matlab | save (sprintf('%s.mat', fullfile(dirs.DataOut, saveFilename)),'ptData','ptTime','ptInfo') | 
| Comma Separated | Values (CSV) photoDiode | 
| Putting files in one for time another for
 | photodiode (so Excel can open it) csvwrite(sprintf('%s.csv' | 
| Putting files in one for time another for
 | fullfile (dirs.DataOut, saveFilename)) | 
| Putting files in one for time another for photoDiode
 | fprintf ('\nSuccessfully saved all the files to%s as%s\n', dirs.DataOut, saveFilename) end function dirs | 
| id | C: (id Unlock) | 
| Add path to chronux toolbox otherwise
 | disp ('No paths have been estalished') end%Set up path so code is accessible to Matlab addpath(dirs.helpers) | 
| Add dir w my helpers | addpath (dirs.DataIn) | 
| Add dir w your Data path | addpath (genpath(dirs.Code)) | 
| Add dir w your code path | addpath (genpath(dirs.PTB)) | 
| Add dir w PsychToolbox code | addpath (genpath(dirs.chronux)) | 
| 
Variables | 
|  | function [ptData, ptTime, ptInfo] | 
| creates photo diode and time vector0 Also a structure with
 info regarding smapling
 | frequency | 
| creates photo diode and time vector0 Also a structure with
 info regarding smapling
 flickering stimulation freq
 and times for sweep analysis
 INPUT
 | fileName = 'C:\Users\Administrator\Documents\BU\Speechlab\Unlock\Data\raw\20131211-photodiode\DiodeData_15.mat' | 
| Check if fileName is a path or a simple file name if file
 | diodeData = load(fullfile(dirs.DataIn,fileName)) | 
| else | d2 = size(diodeData.y) | 
| if d1 d2 diodeData | y = diodeData.y' | 
|  | titleStr = '15' | 
| Get name of file to save it | strIndx = strfind(fileName,'DiodeData_15') | 
| end | saveStr = fileName(strIndx(end)+10:end-4) | 
|  | ptTime = diodeData.y(1,:) | 
| Sampling frequency | Fs = 1/(ptTime(3) - ptTime(2)) | 
| Extra analysis Plot data | hFig = plot(ptTime, ptData) | 
|  | FontWeight | 
|  | Bold | 
|  | SweepTimes = zeros(length(stimFreq),2) | 
| Get start of Extract sections for each DiodeData_sweep Get
 right most boundary for
 | iFreq | 
| end Filter the data Filter params | smpRate = Fs | 
|  | freqBand = [1 Fs/2] | 
|  | filterOrder = 2 | 
|  | filterType = 'butter' | 
| Filtering | dataFiltered = setFilterParams(freqBand, filterType, filterOrder, smpRate) true | 
|  | ptData = filtfilt(filtParams.b,filtParams.a,ptData) | 
| Running | periodogram [pxx, f] = periodogram(ptData,[],[],Fs) | 
| Info structure with info required for analysis
 | ptInfo = struct('nameFile',fileName,'HighStates',8,'LowStates',0,'sampFreq',Fs,'StimTimeSec',3,'StimRestTimeSec',3','StimFreq',stimFreq,'SweepTimes',SweepTimes) | 
| Saving files if~dataFiltered | saveFilename = ['PhotoDiodeDataAndTimes-',saveStr] | 
| Putting files in | column | 
| Putting files in one for time | vector | 
| Putting files in one for time another for photoDiode data
 input and
 | output | 
| Putting files in one for time another for photoDiode data
 input and based on system
 | hostname [~, host] = system('hostname') | 
|  | host = deblank(host) | 
| Dir w data analysis Code dirs | helpers = 'C:\Users\salacho\Documents\Code\helpers' | 
| Dir w helpers analysis Code dirs | DataIn = 'C:\Users\salacho\Documents\Analysis\unlock' | 
| Local Dir to output analyzed datafiles and figures too dirs
 | BCIparams = '' | 
| Add path where all BCIparams are located dirs
 | PTB = 'C:\Users\salacho\Documents\MATLAB\toolbox\Psychtoolbox' | 
| Add path to PsychToolbox dirs | chronux = 'C:\Users\salacho\Documents\MATLAB\toolbox\chronux' |