filt_signalsWAV_several_CutGlue_segs.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. function [ph_filt_signals, amp_filt_signals] = filt_signalsWAV_several_CutGlue_segs(sig1,sig2,...
  2. Fs, ph_freq_vec, amp_freq_vec, measure, width)
  3. % function [ph_filt_signals, amp_filt_signals] = filt_signalsWAV(sig1,sig2,...
  4. % Fs, ph_freq_vec, amp_freq_vec, measure, width)
  5. %
  6. % Returns cell arrays 'ph_filt_signals' and 'amp_filt_signals'. These
  7. % contain 'sig1' and 'sig2' correctly filtered in order to calculate the
  8. % PAC measure, either ESC or MI given by 'measure'. The frequencies
  9. % to filter at are determined by the vectors 'ph_freq_vec' and
  10. % 'amp_freq_vec'. The frequency range is defined by the minimum and the
  11. % maximum value and the interval, or bandwith, between values. For example
  12. % if 'ph_freq_vec' is defined as 1:5:101 ([1, 6, 11, 16, 21...101]) then
  13. % the centre frequencies that will be filtered for are [3, 8, 13, 18...98]
  14. % i.e. the centre of the 5 Hz bins from 1 Hz to 101 Hz. Filtering is
  15. % achieved via convolution with a complex Morlet wavelet (number of cycles
  16. % defined by 'width' parameter).
  17. %
  18. % INPUTS:
  19. % sig1 - signal which will be analysed as containing the higher frequency,
  20. % modulated PAC signal
  21. % sig2 - signal which will be analysed as containing the lower frequency,
  22. % modulating signal
  23. % Fs - sampling frequency, in Hz
  24. % ph_freq_vec - vector of frequencies to filter sig2 for, in Hz
  25. % amp_freq_vec - vector of frequencies to filter sig1 for, in Hz
  26. % measure - PAC measure which will be calculated using these filtered
  27. % signals
  28. % width - number of cycles which will define the mother Morlet wavelet
  29. %
  30. % OUTPUTS:
  31. % ph_filt_signals - 1 x (number of bins determined by ph_freq_vec) cell
  32. % array, each element has the same dimensions as the original signals
  33. % amp_filt_signals - 1 x (number of bins determined by amp_freq_vec) cell
  34. % array, each element has the same dimensions as the original signals
  35. %
  36. % Author: Angela Onslow, May 2010
  37. total_num_dp = size(sig1,1); % length of data
  38. num_trials = 1:size(sig1,2); % 1:sample numbers
  39. phfreq_low = min(ph_freq_vec);
  40. phfreq_high = max(ph_freq_vec);
  41. phfreq_bw = diff(ph_freq_vec(1:2));
  42. ampfreq_low = min(amp_freq_vec);
  43. ampfreq_high = max(amp_freq_vec);
  44. ampfreq_bw = diff(amp_freq_vec(1:2));
  45. xbins = ceil((phfreq_high - phfreq_low)/phfreq_bw); % number of frequency bands of sig2
  46. ybins = ceil((ampfreq_high - ampfreq_low)/ampfreq_bw); % number of frequency bands of sig1
  47. % Create structures to store filtered signals
  48. ph_filt_signals = cell(1,xbins);
  49. amp_filt_signals = cell(1,ybins);
  50. for i2=1:xbins
  51. ph_filt_signals{1,i2} = zeros(total_num_dp*max(num_trials),1);
  52. end
  53. for i2=1:ybins
  54. amp_filt_signals{1,i2} = zeros(total_num_dp*max(num_trials),1);
  55. end
  56. % Filter and store filtered signals %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  57. % ==== Filter sig2 for phase freq ====
  58. for i2=1:xbins
  59. upper_bin = phfreq_low+(i2*phfreq_bw);
  60. lower_bin = upper_bin-phfreq_bw;
  61. if strcmp(measure, 'esc')
  62. for i3=1:max(num_trials)
  63. tem=(i3-1)*total_num_dp+1:(i3)*total_num_dp;
  64. ph_filt_signals{1,i2}(tem,1) = bpvec((lower_bin + floor((upper_bin- lower_bin)/2)), sig2(:,i3), Fs, width);
  65. end
  66. else
  67. for i3=1:max(num_trials)
  68. tem=(i3-1)*total_num_dp+1:(i3)*total_num_dp;
  69. aa=lower_bin + floor((upper_bin- lower_bin)/2);
  70. ph_filt_signals{1,i2}(tem,1) = phasevec((lower_bin + floor((upper_bin- lower_bin)/2)),sig2(:,i3), Fs,width);
  71. end
  72. end
  73. end
  74. % ==== Filter sig1 for amplitude freq ====
  75. for i2=1:ybins
  76. upper_bin = ampfreq_low+(i2*ampfreq_bw);
  77. lower_bin = upper_bin-ampfreq_bw;
  78. for i3=1:max(num_trials)
  79. tem=(i3-1)*total_num_dp+1:(i3)*total_num_dp;
  80. amp_filt_signals{1,i2}(tem,1) = ampvec((lower_bin + floor((upper_bin- lower_bin)/2)),sig1(:,i3), Fs, width);
  81. end
  82. end