function peak_list_inc = ppm2inc(peak_list_ppm, header_data)
% peak_list_inc = ppm2inc(peak_list_ppm, header_data)
%    map a peak list in ppm to one in incriments indexing the spectrum as a
%    matrix/tensor

Ni_row = header_data(26,:);
num_dims = min(size(peak_list_ppm,2),sum(Ni_row > 1));
num_peaks = size(peak_list_ppm,1);
Ni_row = Ni_row(1:num_dims);

right_ppm = header_data(16,1:num_dims)./header_data(14,1:num_dims);
sw = header_data(20,1:num_dims)./header_data(14,1:num_dims);
left_ppm = right_ppm + sw;

peak_list_inc = repmat(-Ni_row./sw,num_peaks,1).*peak_list_ppm(:,1:num_dims) + repmat(Ni_row.*left_ppm./sw,num_peaks,1);
peak_list_inc = mod(round(peak_list_inc)-1,repmat(Ni_row,num_peaks,1))+1;