CCCC=uvwplat;

uvwplatc=ones(3,36000);
clear correctionratiox correctionratioy correctionratioz
clear YU YV YW YUc YVc YWc lux luy luz titi ft

Fs = 10;                    % Sampling frequency
NFFT = 36000;
ft = Fs*linspace(0,1,NFFT);
NFFT = 36000; % Next power of 2 from length of y
YU = fft(AAAA(1,:),NFFT);YUc = fft(CCCC(1,:),NFFT);
YV = fft(AAAA(2,:),NFFT);YVc = fft(CCCC(2,:),NFFT);
YW = fft(AAAA(3,:),NFFT);YWc = fft(CCCC(3,:),NFFT);

% % L=36000;Fs=10;
% % NFFT = 2^nextpow2(L); % Next power of 2 from length of y
% % YU = fft(AAAA(1,:),NFFT)/L;YUc = fft(CCCC(1,:),NFFT)/L;
% % YV = fft(AAAA(2,:),NFFT)/L;YVc = fft(CCCC(2,:),NFFT)/L;
% % YW = fft(AAAA(3,:),NFFT)/L;YWc = fft(CCCC(3,:),NFFT)/L;


% f = Fs/2*linspace(0,1,NFFT/2+1);
% ft = Fs*linspace(0,1,NFFT);

titi=find(ft>5e-2 & ft<3e-1);
% titi=find(ft>1e-3 & ft<3e-1);
lux=find(abs(YUc(titi))>abs(YU(titi)));
% correctionratiox=nanmean(abs(YUc(titi(lu)))./abs(YU(titi(lu))));
correctionratiox=(abs(YUc(titi(lux)))./abs(YU(titi(lux))));
luy=find(abs(YVc(titi))>abs(YV(titi)));
% correctionratioy=nanmean(abs(YVc(titi(lu)))./abs(YV(titi(lu))));
correctionratioy=(abs(YVc(titi(luy)))./abs(YV(titi(luy))));
luz=find(abs(YWc(titi))>abs(YW(titi)));
% correctionratioz=nanmean(abs(YWc(titi(lu)))./abs(YW(titi(lu))));
correctionratioz=(abs(YWc(titi(luz)))./abs(YW(titi(luz))));

%does not allow to overcorrect spectra in [20s-3.3s] range ...
YU2=YUc;
% if correctionratiox>1
if nanmean(correctionratiox)>1
    YU2(titi(lux))=(YUc(titi(lux)))./correctionratiox;
end
YV2=YVc;
% if correctionratioy>1
if nanmean(correctionratioy)>1
    YV2(titi(luy))=(YVc(titi(luy)))./correctionratioy;
end;
YW2=YWc;
% if correctionratioz>1
if nanmean(correctionratioz)>1
    YW2(titi(luz))=(YWc(titi(luz)))./correctionratioz;
end;
uvwplatc(1,:) = real(ifft(YU2));
uvwplatc(2,:) = real(ifft(YV2));
uvwplatc(3,:) = real(ifft(YW2));

uvwplat=uvwplatc;