function detrate = detspike(data,D,name,rank,DCTthresh,spike)

numdays = 3;
spike = (0:1/numdays:1)';
ld = length(data);
datarange = (max(data)-min(data))
height = datarange*2;
initpoint = 30;
n = 1;
fid = fopen('cough.spikedetection.data.pw.ar7','w');
outlist = [];
detrate = [];
rank = 7;
pdlist = predictions(data,n,rank,[]);   %get the original predictions for all of the data (not including spikes)
while height  >= 0.00005
    fprintf('Considering height of %f\n',height);
    fprintf(fid,'Considering height of %f\n',height);
    fprintf(fid,'Period             Points in the model   Number of outliers\n');
    out1 = [];
day(1:3) = 0;
    for i = initpoint:ld-numdays
        data_spike = data;
        dsl=i+numdays;
        fprintf(fid,'%s-%s  ',num2str(D(1,1:8)),num2str(D(dsl,1:8)));
        data_spike(i:dsl) = data(i:dsl)+spike*height;
        [outliers,outdates,sigmas]=spikedetsystem(fid,data_spike(1:dsl),i,pdlist,n,rank,D,[]);
        fprintf(fid,'%d                      %d\n',dsl,(size(outliers,1)));
        fprintf(fid,'Detected outliers: %s \n',num2str(outdates(:,1:8)'));
        fprintf(fid,'Sigmas: %d %f \n',sigmas');
        out1 = [out1;size(outliers,1)];
        if ~isempty(outliers)
            for j = 1:numdays            
                if  find(outliers<=i+j)   %including the previous day
                   day(j) = day(j) + 1;
                end;
            end;
        end;
    end;
    day
    detrate = [detrate; height day/(ld-numdays-initpoint)];

    height = height - height/4;
    outlist = [outlist out1];
end;
fclose(fid);

figure;
plot(detrate(:,1),detrate(:,2:size(detrate,2)));