Simple signal
% My EEG data are usually downsampled to 256 Hz. Then i do peak detection to detect the peak of ERPs. I made this program to make the check that my programs work % correctly.
% Can be used freely!
clear all
close all
Fs=256; % Hertz
timeVec_sec=-0.2:1/Fs:(0.8-(1/Fs)); % In seconds 1 second = 256 dp
timeVec_msec=timeVec_sec.*1000;
% Out of curiosity, what is the frequency resolution we have?
freqRes=Fs/length(timeVec_msec);
% Frequency of the signal
F1=5;
%% Define time interval with signaL
% timestart=250 msec
% timeend=300 msec
timestart_indexes=find(timeVec_msec>250);
timestart_index=min(timestart_indexes); %117
clear timestart_indexes
timeend_indexes=find(timeVec_msec<350);
timeend_index=max(timeend_indexes); % 141
clear timeend_indexes
timeVec_msec_signal_in=timeVec_msec(1, timestart_index:timeend_index);
%
tspecial=[1:length(timestart_index:timeend_index)];
signal=10*sin(2*pi*tspecial*F1/Fs);
figure(3); plot(signal)
%% First we want a period of zeros, from -200 to 250 msec.
t1_temp=-200;
t1_temp_index=1;
clear t1_temp_indexes
t2_temp=249;
t2_temp_indexes=find(timeVec_msec>249);
t2_temp_index=min(t2_temp_indexes);
disp(['index of 249msec is found ' t2_temp_index 'corresponding to:' num2str(timeVec_msec(t2_temp_index))])
clear t2_temp_indexes
t_period1_ofzeros=t1_temp_index:t2_temp_index;
t_period1=zeros(1,length(t_period1_ofzeros));
% Then we want a period of zeros, from 350 to 1000 msec.
t3_temp=351
t3_temp_indexes=find(timeVec_msec>351);
t3_temp_index=min(t3_temp_indexes);
disp(['index of 351 msec is found ' t3_temp_index 'corresponding to:' num2str(timeVec_msec(t3_temp_index))])
clear t3_temp_indexes
t4_temp=800;
t4_temp_index=length(timeVec_msec); % the last index of our timeVec_msec
t_period2_ofzeros=t3_temp_index:t4_temp_index;
t_period2=zeros(1, length(t_period2_ofzeros));
x=[ t_period1 signal t_period2 [0 0]];
figure(1); plot(x);
figure(2); plot(timeVec_msec,x);