Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

lfp_analysis1.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. clear all;
  2. file_name1 = '/home/vlachos/data_kiap/20190321-140130/20190321-140130-002.ns2';
  3. file_name2 = '/home/vlachos/data_kiap/20190321-140130/20190321-140130-002.nev';
  4. %% defining parameters
  5. pars.ch_nr = 2;
  6. pars.lfp.filter_order = 4;
  7. pars.lfp.filter_fc_low = 30;
  8. pars.lfp.filter_fc_high = 60;
  9. pars.lfp.fs = 1000; % sampling rate
  10. pars.artifact_thr = 1000;
  11. % psth parameters
  12. pars.psth_win =[-1000, 4999];
  13. %% LOAD FILES
  14. ns2 = openNSx('read', 'report',file_name1, 'p:int16');
  15. nev = openNEV('read', 'report',file_name2);
  16. %% CAR
  17. lfp = double(ns2.Data)';
  18. lfp = lfp - mean(lfp,2);
  19. disp(size(lfp))
  20. %% FILTER
  21. [b, a] = butter(pars.lfp.filter_order, [pars.lfp.filter_fc_low, pars.lfp.filter_fc_high] / (pars.lfp.fs / 2));
  22. % [b, a] = butter(pars.lfp.filter_order, [100] / (pars.lfp.fs / 2),'low');
  23. % lfp_filt = filtfilt(b, a, lfp(:,1:pars.ch_nr));
  24. lfp_filt = filtfilt(b, a, lfp(:,30:31));
  25. disp(size(lfp_filt))
  26. %% COMPUTE FFT
  27. Y_lfp = fft(lfp_filt);
  28. L = length(Y_lfp);
  29. P2 = abs(Y_lfp/L);
  30. P1 = P2(1:L/2+1,:);
  31. P1(2:end-1,:) = 2*P1(2:end-1,:);
  32. ff = pars.lfp.fs*(0:(L/2))/L;
  33. % clf
  34. % for ii=1:128
  35. % plot(ff,P1(:,ii))
  36. % disp(ii)
  37. % input('press enter')
  38. % end
  39. %% GET YES/NO TRIGGERS FROM NEV FILE
  40. triggers_ts = nev.Data.Comments.TimeStamp;
  41. triggers_txt = nev.Data.Comments.Text;
  42. triggers_yes = [];
  43. triggers_no = [];
  44. for ii=1:length(triggers_txt)
  45. if contains(triggers_txt(ii,:), 'no, response, start')
  46. triggers_no = [triggers_no, triggers_ts(ii)];
  47. elseif contains(triggers_txt(ii,:), 'yes, response, start')
  48. triggers_yes = [triggers_yes, triggers_ts(ii)];
  49. end
  50. end
  51. % get timestamps for ns2
  52. triggers_yes_ns2 = triggers_yes / 30;
  53. triggers_no_ns2 = triggers_no / 30;
  54. %% COMPUTE PSTH
  55. psth_win = pars.psth_win;
  56. psth_len = diff(psth_win)+1;
  57. psth_yes = zeros(length(triggers_yes_ns2), psth_len, pars.ch_nr);
  58. psth_no = zeros(length(triggers_no_ns2), psth_len, pars.ch_nr);
  59. for ii=1:length(triggers_yes_ns2)
  60. if triggers_yes_ns2(ii)+psth_win(1)>0 && triggers_yes_ns2(ii)+psth_win(2)<length(lfp_filt)
  61. tmp = lfp_filt((triggers_yes_ns2(ii)+psth_win(1)):(triggers_yes_ns2(ii)+psth_win(2)),:);
  62. if ~any(any(tmp>pars.artifact_thr))
  63. psth_yes(ii,:,:) = tmp;
  64. else
  65. disp(['Trial excluded: ',num2str(ii)])
  66. end
  67. end
  68. end
  69. for ii=1:length(triggers_no_ns2)
  70. if triggers_no_ns2(ii)-psth_win(1)>0 && triggers_no_ns2(ii)+psth_win(2)<length(lfp_filt)
  71. tmp = lfp_filt((triggers_no_ns2(ii)+psth_win(1)):(triggers_no_ns2(ii)+psth_win(2)),:);
  72. if ~any(any(tmp>pars.artifact_thr))
  73. psth_no(ii,:,:) = tmp;
  74. else
  75. disp(['Trial excluded: ',num2str(ii)])
  76. end
  77. end
  78. end
  79. %% FFT OF PSTH
  80. Y_psth_yes = fft(psth_yes,[],2);
  81. L = length(Y_psth_yes);
  82. P2 = abs(Y_psth_yes/L);
  83. P1 = P2(:,1:L/2+1,:);
  84. P1(:,2:end-1,:) = 2*P1(:,2:end-1,:);
  85. ff = pars.lfp.fs*(0:(L/2))/L;
  86. %% PLOT RESULTS
  87. subplot(2,2,1)
  88. plot(squeeze(mean(psth_no,1)));
  89. subplot(2,2,3)
  90. plot(squeeze(mean(psth_yes,1)),'b');
  91. subplot(2,2,2)
  92. plot(ff, squeeze(mean(P1,1)),'r');
  93. xlim([0,100])
  94. subplot(2,2,4)
  95. plot(ff, squeeze(mean(P1,1)),'b');
  96. xlim([0,100])