% Script to test hdedop.m and fmt.m
%
% 22May2000 initial version...K.Metzger

clear all;
fig = 1; clf;

VonC = 10/1500;  % Sets the Doppler ratio
%VonC = 0;        % Doppler amount to use
FConFS = 57/228; % carrier to sample rate ratio
law = 2033;      % sequence law to test with
sam_cyc = 4;     % samples per carrier cycle
cyc_dig = 2;     % number of carrier cycles per sequence bit
angle = 181;     % modulation angle
N_periods = 11;  % number of periods to simulate (approx)

perm = fmstset(law);        % permutation information for fmt
L = 2^perm.layers-1;        % number of sequence bits per period
sam_dig = sam_cyc*cyc_dig;  % samples per sequence bit (digit)

% generate number of samples...pre doppler correction

sam_cnt = L*sam_dig*N_periods;
samples = seqgen(law, cyc_dig, angle, sam_cyc, VonC, sam_cnt, 1);

start_scan = 8184*5;
n_scans = L*sam_dig;

[demods, Eflag] = hdedop(samples, VonC, FConFS, start_scan, n_scans);

if Eflag
  error(sprintf('error %d forming scan\n', Eflag));
end

% apply sinc filter wrapping around full period

temp = zeros(size(demods));
N = length(demods);
Qfilter = 8;    % number of samples in periodic sliding summation
for count = 0:Qfilter-1
  temp = temp+demods(mod([0:N-1]+count, N)+1);
end
demods = temp/Qfilter; temp=[];  % and normalize 

% plot spectrum of result

spectrum = fft(demods);
spectrum = spectrum.*conj(spectrum);
spectrum = spectrum/max(spectrum);
figure(fig); clf; fig = fig+1;
plot(20*log10(fftshift(spectrum)));
axis([1 length(spectrum) -100 5]);

% do sequence removal

tseries = fmst(demods, perm, angle);

% plot full period of time processing result

tsplot = abs(fftshift(tseries));
tsplot = 20*log10(tsplot/max(tsplot));
figure(fig); clf; fig = fig+1;
plot(tsplot);
axis([0 length(tseries)-1 -70 10]);

% plot region around peak of time processing result

figure(fig); clf; fig = fig+1;
plot(tsplot);
axis([length(tseries)/2-100 length(tseries)/2+100 -70 10]);

