disp('mot_spc')

rol=sonraw_dep(2,:);
pit=sonraw_dep(3,:);
yaw=sonraw_dep(4,:);

%clear w vul v uul u tzilch tzero sul st3 speedson prtit prt_it plotit nr1 npz np nl1 jl jk jj jhold jd jazx jaxx jax jam jadson jade j_st j_en j hul hr hll flist
%clear f e dmp2 dmp dir backchk ans V U Tul Tsonic Tll S Rtul Rtll Rsul Rsll Rlul Rlll

if 1   %hhh==0 | hhh==01 | hhh==12 || hhh==13 | hhh==15 | hhh==18 | hhh==22,
    disp(['Calculating spectra for ',num2str(jam)])
    % roll spectra
    [Sw,F]=psd2(detrend(rol),length(rol),20.);
    [Sws,Fsw]=specsmoo(Sw,20.);
    % pitch spectra
    [Su,F]=psd2(detrend(pit),length(pit),20.);
    [Sus,Fsu]=specsmoo(Su,20.);
    % yaw spectra
    [Sv,F]=psd2(detrend(yaw),length(yaw),20.);
    [Svs,Fsv]=specsmoo(Sv,20.);


    figure;
    % 5/3 line
    loglog(Fsu(length(Fsu)-31:length(Fsu)),((Fsu(length(Fsu)-31:length(Fsu))).^(-2/3))./(Fsu(length(Fsu)-18).^(-2/3)).*Sus(length(Fsu)-18).*Fsu(length(Fsu)-18),'k');
    hold
    % roll
    loglog(Fsw,Sws.*Fsw,'r');
     %pitch
    loglog(Fsu,Sus.*Fsu,'b');
    % yaw
    loglog(Fsv,Svs.*Fsv,'g');
    
    ss = length(sonraw_dep);
    npts = num2str(ss);
    way_spec_data= 'c:\data\icealot\data\motion\Raw_Images\';
    title(['ICEALOT Motion Spectra:   Day ',num2str(jd),'   Hour ',num2str(jam),'  Npts ',npts,]);
    legend('5/3','Roll','Pitch','Yaw','Location','Northwest' );
    xlabel('Frequency in Hz');
    ylabel('Spectrum * Frequency');
    
    print_buffer = [way_spec_data ,'Motion_' jd  '_' hr , '_spc.png'];
    print('-dpng ', print_buffer);
    if 0 hhh==12,  % Print out spectra file for hr 12
        specfile=[way_spec_data, '\w_sp',jd,hr,'.txt'];
        fspec=fopen(specfile,'w');
        specs=[Fsu
            Sus
            Fsw
            Sws];
        fprintf(fspec,'%11.5f %11.5f %11.5f %11.5f \r\n',specs);
        fclose(fspec);
        clear fspec specs specfile
    end;%end hhh=12
    clear SS UU VV Su F Sus Fsu Sw F Sws Fsw Svs Sv 
end;%end hhh=0 or 12 or 18
