% Basic RTG definition file for pmseCompl64 experiment
% Note that not everything here is exactly right, particularly the
% scaling of the decoded PP!
%
% Andrew Senior, Lancaster University, 2008-06-27 (a.senior@lancaster.ac.uk)

thead={'Channel board 1 background' 'Channel board 2 background'};

% Sum the power in the slices of the decoded PPs
%dpp=dd_data(421:end);
%dpp=dpp.*conj(dpp);
%dpp=reshape(dpp,267,625)';
%dpp=sum(dpp);

%orig_len=length(dd_data);
%dd_data=[dd_data; dpp'];

%rd=real(dd_data);
%id=imag(dd_data);

% Plot spectrogram
ax=getaxes(20,1,1);
S=reshape(d_raw(1:(125*900)),900,125).';
S=fft(S);
S=fftshift(S,1);
S=S.*conj(S);
f_scale=((1:125)-63)/(125*40000e-6);
r_scale=(1500e-6+((1:900)-1)*40e-6)*1.5e8;
updateimage(20,ax,f_scale,r_scale/1e3,(S'));
set(get(ax,'xlabel'),'string','Frequency (Hz)');
set(get(ax,'ylabel'),'string','Range (km)');
set(get(ax,'title'),'string','Pulse-to-pulse (Channel board 1)');

ax=getaxes(40,1,1);
S=reshape(d_raw(125*900+(1:(125*900))),900,125).';
S=fft(S);
S=fftshift(S,1);
S=S.*conj(S);
updateimage(40,ax,f_scale,r_scale/1e3,(S'));
set(get(ax,'xlabel'),'string','Frequency (Hz)');
set(get(ax,'ylabel'),'string','Range (km)');
set(get(ax,'title'),'string','Pulse-to-pulse (Channel board 2)');
%
ax=getaxes(60,1,1);
S=reshape(d_raw(1:(125*900)),900,125);
S=S(end-255:end,:);
S=fft(S);
S=fftshift(S,1);
S=S.*conj(S);
S=sum(S,2);
f_scale=((1:256)-128)/(256*40e-6);
updateplot(60,ax,f_scale/1e3,10*log10(S),[],[]);
set(get(ax,'xlabel'),'string','Frequency (kHz)');
set(get(ax,'ylabel'),'string','Power (dB)');
set(get(ax,'title'),'string','Background Spectrum (Channel board 1)');

ax=getaxes(80,1,1);
S=reshape(d_raw(125*900+(1:(125*900))),900,125);
S=S(end-255:end,:);
S=fft(S);
S=fftshift(S,1);
S=S.*conj(S);
S=sum(S,2);
f_scale=((1:256)-128)/(256*40e-6);
updateplot(80,ax,f_scale/1e3,10*log10(S),[],[]);
set(get(ax,'xlabel'),'string','Frequency (kHz)');
set(get(ax,'ylabel'),'string','Power (dB)');
set(get(ax,'title'),'string','Background Spectrum (Channel board 2)');

% fudge some calibration

dd_data(880+(0:19))=2*dd_data(880+(0:19));
dd_data(1780+(0:19))=2*dd_data(1780+(0:19));

rd=real(dd_data);
id=imag(dd_data);

%pp/timing
%psig=[0];
%psamp=[900];
%plen=[1000e-6];
%pdt=[40e-6];
%prange0=[1500e-6];
%bfac=[0.5];
%pbac=[0]; % what is this?
%noise
%back=[860];
%bsamp=[20];
%cal=[880];
%csamp=[20];
%loopc=[125];
%bacspec=[NaN;
%         NaN];
