% This program reads in ascii data files (ERP data: electrodes in columns, samples in rows), % It finds peak value for each electrode within a given time interval % and spits out this peak value as well as the latency of the peak for each % electrode % Heleen Slagter (slagter@wisc.edu), September 2005 clear all; %% ***** EDIT THIS PART BETWEEN *** ONLY ****** % User-specific input nsamples = 750; nelectrodes = 129; %specify interval to search for peak value (rowA to rowB) RowA = 2; RowB = 4; sample_rate = 2; %sample rate in ms ; corresponding to 500Hz sr %specifiy file names here cond = {... 'samplefile.1LX0',... }; %% ******************************** ncond=length(cond); % start loop in which each value is divided by 100 for condition = 1:ncond; % Open data file filename = sprintf('%s.txt', cond{condition}); dat = fopen(filename); data = fscanf(dat, '%g %g', [nelectrodes nsamples]); data = data'; fclose(dat); x = zeros(RowB-RowA,1); peak_values = zeros(1,nelectrodes); latency_peak_sample = zeros(1,nelectrodes); latency_peak_ms = zeros(1,nelectrodes); for j = 1:nelectrodes; %for each column (electrode) separately k = 1; for i = RowA:RowB; %find peak value within specified interval x(k) = data(i,j); k=k+1; end; peak_values(j)=max(x); latency_peak_sample(j)=(RowA+(find(x==peak_values(1,j))))-1; latency_peak_ms(j)=latency_peak_sample(j)*sample_rate; end; output = zeros(3,nelectrodes); output(1,:)=peak_values(1,:); output(2,:)=latency_peak_sample(1,:); output(3,:)=latency_peak_ms(1,:); % Save in output file (asci tab delimited) newfilename = sprintf('%s_%d-%d.txt', cond{condition}, RowA, RowB); dlmwrite(newfilename,output,'\t'); end; % end condition loop