function OI = OrganizationIndex(signal,fs,npeaks)

% compute spectrum
nfft = 1024;

[PSD,FF] = pwelch(signal,[],[],nfft,fs);
Istart = find(FF<4,1,'last');
I = find((FF >= 4) & (FF <= 12));
[pks,locs]= findpeaks(PSD(I));
[~,Ipks] = sort(pks,1,'descend');
locsmax = locs(Ipks)+Istart;

relativepower = 0;
if length(locsmax) < npeaks
    npeaks = length(locsmax);
end
for i = 1:npeaks
    clear intFF
    intFF = find(FF >= FF(locsmax(i))-1 & FF <= FF(locsmax(i))+1);
    relativepower = relativepower+sum(PSD(intFF));
end

OI = relativepower/sum(PSD);
