1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- function dataOut = extract_data(file_nums, filter_choice)
- %% Extract and filter data
- % The function extracts all data from one or more ".mat" dataset file(s)
- % and returns them as one structure per file wrapped in a cell array. If
- % requested a filter can be applied to the recording data.
- % ------------------------------------------------------------------------
- % Input
- % file_num: number of the required file in the directory
- % filter_choice: selction between two filter options:
- % 'hn' applys a hum-noise-remove filter
- % 'hnhfn' additonally applys a low pass filter to
- % remove high frequency noise
- % 'no' no filter will be applyed
- % ------
- % Output
- % ------
- % rec_data: a cell array containing one structure per requested file
- % Each structure contains the following data:
- % - recordingT (matrix, containing the recorded membrane
- % potentials for the T cell for all trials,
- % data in mV)
- % - recordingINT (matrix, containing the recorded membrane
- % potentials for the interneuron for all
- % trials, data in mV)
- % - stimulus (vector, containing the stimulation protocol
- % of the experiment, data in nA)
- % - timeVector (vector, suitable vector with time values
- % for the recorded data, data in s)
- % - stimulatedT (vector, giving the numbers of the trials
- % with a stimulated T cell)
- % ------------------------------------------------------------------------
- % Program by Bjarne Schultze [last modified 09.12.2021]
- % ------------------------------------------------------------------------
- %% Directory preparations
- % get the current directory
- old_cd = cd;
- % change into the directory with the datasets and add directory with
- % program files
- cd ../CleanDatasets
- addpath ../'DataAnalysisToolbox'/
- %% Preperations for data extraction
- % list all '.mat' files in the directory
- mat_directory = dir('*.mat');
- % preallocate a cell array for data collection
- dataOut = cell(length(file_nums),1);
- for fileIndex = 1:length(file_nums)
- % check whether all file indices are in the valid range
- if max(file_nums) > length(mat_directory)
- warning("Index out of range! Check the requested file " + ...
- "index/indices.");
- break
- end
- % load the requested file
- load(mat_directory(file_nums(fileIndex)).name, "RecordingData");
-
- %% Getting the recorded data and application of filters
- % optional application of a filter
- if isequal(filter_choice, 'hn')
- % filter the hum noise
- [~, RecordingData.recordingT] = ...
- removehumnoise(RecordingData.recordingT, 10000);
- [~, RecordingData.recordingINT] = ...
- removehumnoise(RecordingData.recordingINT, 10000);
- elseif isequal(filter_choice, 'hnhfn')
- % filter the hum noise plus high frequency noise
- [RecordingData.recordingT, ~] = ...
- removehumnoise(RecordingData.recordingT, 10000);
- [RecordingData.recordingINT, ~] = ...
- removehumnoise(RecordingData.recordingINT, 10000);
- end
- % collect the output data in the preallocated cell array
- dataOut{fileIndex, 1} = RecordingData;
- end
- % reset the current directory to the one from before the function call
- cd(old_cd);
- % end of function definition
- end
|