function [loc, pks]=achieve_min_peak_distance(peak_location,peak_height,min_peak_distance)


[sorted_peaks, sorted_peak_idx] = sort(peak_height, 'descend');
sorted_peak_locs = reshape(peak_location(sorted_peak_idx), [], 1);

removed_peaks = false(length(peak_location), 1);

for ii = 1:length(sorted_peak_locs)
    if ~removed_peaks(ii)
        removed_peaks = removed_peaks | ...
                        (  (sorted_peak_locs > (sorted_peak_locs(ii) - min_peak_distance)) ...
                         & (sorted_peak_locs < (sorted_peak_locs(ii) + min_peak_distance)));
        removed_peaks(ii) = false;
    end
end
sorted_peaks(removed_peaks) = [];
sorted_peak_locs(removed_peaks) = [];

[loc, loc_idx] = sort(sorted_peak_locs, 'ascend');
pks = sorted_peaks(loc_idx);
end


