extract_data.m 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. function dataOut = extract_data(file_nums, filter_choice)
  2. %% Extract and filter data
  3. % The function extracts all data from one or more ".mat" dataset file(s)
  4. % and returns them as one structure per file wrapped in a cell array. If
  5. % requested a filter can be applied to the recording data.
  6. % ------------------------------------------------------------------------
  7. % Input
  8. % file_num: number of the required file in the directory
  9. % filter_choice: selction between two filter options:
  10. % 'hn' applys a hum-noise-remove filter
  11. % 'hnhfn' additonally applys a low pass filter to
  12. % remove high frequency noise
  13. % 'no' no filter will be applyed
  14. % ------
  15. % Output
  16. % ------
  17. % rec_data: a cell array containing one structure per requested file
  18. % Each structure contains the following data:
  19. % - recordingT (matrix, containing the recorded membrane
  20. % potentials for the T cell for all trials,
  21. % data in mV)
  22. % - recordingINT (matrix, containing the recorded membrane
  23. % potentials for the interneuron for all
  24. % trials, data in mV)
  25. % - stimulus (vector, containing the stimulation protocol
  26. % of the experiment, data in nA)
  27. % - timeVector (vector, suitable vector with time values
  28. % for the recorded data, data in s)
  29. % - stimulatedT (vector, giving the numbers of the trials
  30. % with a stimulated T cell)
  31. % ------------------------------------------------------------------------
  32. % Program by Bjarne Schultze [last modified 09.12.2021]
  33. % ------------------------------------------------------------------------
  34. %% Directory preparations
  35. % get the current directory
  36. old_cd = cd;
  37. % change into the directory with the datasets and add directory with
  38. % program files
  39. cd ../CleanDatasets
  40. addpath ../'DataAnalysisToolbox'/
  41. %% Preperations for data extraction
  42. % list all '.mat' files in the directory
  43. mat_directory = dir('*.mat');
  44. % preallocate a cell array for data collection
  45. dataOut = cell(length(file_nums),1);
  46. for fileIndex = 1:length(file_nums)
  47. % check whether all file indices are in the valid range
  48. if max(file_nums) > length(mat_directory)
  49. warning("Index out of range! Check the requested file " + ...
  50. "index/indices.");
  51. break
  52. end
  53. % load the requested file
  54. load(mat_directory(file_nums(fileIndex)).name, "RecordingData");
  55. %% Getting the recorded data and application of filters
  56. % optional application of a filter
  57. if isequal(filter_choice, 'hn')
  58. % filter the hum noise
  59. [~, RecordingData.recordingT] = ...
  60. removehumnoise(RecordingData.recordingT, 10000);
  61. [~, RecordingData.recordingINT] = ...
  62. removehumnoise(RecordingData.recordingINT, 10000);
  63. elseif isequal(filter_choice, 'hnhfn')
  64. % filter the hum noise plus high frequency noise
  65. [RecordingData.recordingT, ~] = ...
  66. removehumnoise(RecordingData.recordingT, 10000);
  67. [RecordingData.recordingINT, ~] = ...
  68. removehumnoise(RecordingData.recordingINT, 10000);
  69. end
  70. % collect the output data in the preallocated cell array
  71. dataOut{fileIndex, 1} = RecordingData;
  72. end
  73. % reset the current directory to the one from before the function call
  74. cd(old_cd);
  75. % end of function definition
  76. end