how my code get the bit modification?
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
this stops on 90,180,270,360 now i want certain changes to stops at 45,115,225,315 what changes are required?
%load excel data
trials_1 = xlsread('Block1_3');
%general
subject = 'final';      % enter subject code
IBF = 20;               % individual beta frequency
protlength = 750;       % in seconds length of final output
ramptime = 10;          % in seconds length of ramp time
fsample = 10000;        % sampling rate of data
saveloc = '/Users/tinahocher/Desktop/MATLAB_EEGLAB_DATA /Phase_stop/';
% time vector
t = [1/fsample:1/fsample:protlength];
%---------------------------
% create sine wave
beta{1} = sin(IBF*2*pi*[1/fsample:1/fsample:protlength]);
%create mat file
stimuli = zeros(5,protlength.*fsample);
%add beta wave
for it = 1:length(beta)
    stimuli(3,:) = beta{it};
    % ramp up
    in = 1:ramptime*fsample;
    stimuli(3,in) = beta{it}(in).*linspace(0,1, length(in));
end
save([saveloc 'try_stim_' subject], 'stimuli');
%add trigger at start of each trial
x = trials_1;
for i = 1:length(x)
    start_trial(i) = x(i,4);
    start_trial(i) = ((start_trial(i))*fsample) +(ramptime*fsample);
end
for j = 1:length(start_trial)
    stimuli(5,round(start_trial(j)-5):round(start_trial(j)+5)) = 16;
end
%add trigger at eacht stop
for i = 1:length(x)
    stop_time(i) = x(i,2);
    stop_time(i) = ((stop_time(i))*fsample);
    if ~isnan(stop_time(i))
        stop_trigger(i) = stop_time(i) + start_trial(i);
    else stop_trigger(i) = NaN;
    end
end
stop_trigger_final = stop_trigger(~isnan(stop_trigger));
% %---------------------------------
% %turn off just for testing purpose
% for j = 1:length(stop_trigger_final)
%     stimuli(5,round(stop_trigger_final(j))) = 8;
% end
% %---------------------------------
stop_phase = x(~isnan(stop_trigger),3);
for j = 1:length(stop_trigger_final)
    beta_stop(j) = stimuli(3,round(stop_trigger_final(j)));
    if stop_phase(j) == 1 %90deg
        loc_phase = stimuli(3,[round(stop_trigger_final(j)-250):round(stop_trigger_final(j)+250)])==1;
        loc_phase = find(loc_phase==1);
        sample_loc_phase(j) = (round(stop_trigger_final(j)-[250-loc_phase]));
        % 2 = zero coming from positive  going into negative
    elseif stop_phase(j) == 2 %180deg
       data = stimuli(3,[round(stop_trigger_final(j)-250):round(stop_trigger_final(j)+250)]);
        zerocross = find(diff(sign(data)));
        if length(zerocross)>1
           for z = 1:length(zerocross)
               if data(zerocross(z)+1) < 0
                  sample_loc_phase(j) = (round(stop_trigger_final(j)-[250-zerocross(z)]));
               end
           end
        else sample_loc_phase(j) = (round(stop_trigger_final(j)-[250-zerocross]));
        end
    elseif stop_phase(j) == 3 %270deg
        loc_phase = stimuli(3,[round(stop_trigger_final(j)-250):round(stop_trigger_final(j)+250)])==-1;
        loc_phase = find(loc_phase==1);
         sample_loc_phase(j) = (round(stop_trigger_final(j)-[250-loc_phase]));
        % 4 = zero coming from negative  going into positive
    elseif stop_phase(j) == 4 %360deg
        data = stimuli(3,[round(stop_trigger_final(j)-250):round(stop_trigger_final(j)+250)]);
        zerocross = find(diff(sign(data)));
        if length(zerocross)>1
           for z = 1:length(zerocross)
               if data(zerocross(z)+1) > 0
                  sample_loc_phase(j) = (round(stop_trigger_final(j)-[250-zerocross(z)]));
               end
           end
        else sample_loc_phase(j) = (round(stop_trigger_final(j)-[250-zerocross]));
        end
    else sample_loc_phase(j) = 0;
    end
end
for j = 1:length(sample_loc_phase)
    stimuli(5,round(sample_loc_phase(j)-5):round(sample_loc_phase(j)+5)) = 32;
end
save([saveloc 'stop_phase_2_4_' subject], 'stimuli');
%plotting
for j = 1:length(sample_loc_phase)
figure
plot(t(sample_loc_phase(j)-8000:sample_loc_phase(j)+1000), stimuli(3,sample_loc_phase(j)-8000:sample_loc_phase(j)+1000))
hold on
plot(t(sample_loc_phase(j)-8000:sample_loc_phase(j)+1000), stimuli(5,sample_loc_phase(j)-8000:sample_loc_phase(j)+1000)/10)
end
1 Kommentar
  Geoff Hayes
      
      
 am 8 Okt. 2021
				@Muhammad - in your code, you have
    if stop_phase(j) == 1 %90deg
        % ...
        % 2 = zero coming from positive  going into negative
    elseif stop_phase(j) == 2 %180deg
        % ...
    elseif stop_phase(j) == 3 %270deg
        % ...
        % 4 = zero coming from negative  going into positive
    elseif stop_phase(j) == 4 %360deg
If 1, 2, 3 and 4 correspond to 90, 180, 270, and 360 degrees, then what should correspond to 45,115,225,315?
Antworten (0)
Siehe auch
Kategorien
				Mehr zu Entering Commands finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!