% plot_SpecOQPSKRectvsHS - Spectrum of OQPSK with rectangular and half-sine
% pulses

%% parameters
fsT = 20;
Ns  = 100;
M     = 500; % number of averages
Alphabet = [ 1, -1];   % BPSK
Priors   = ones( size( Alphabet) ) / length(Alphabet);

PulseR = RectPulse( fsT );
PulseR = PulseR/norm(PulseR);  % ensures proper scaling

PulseH = HalfSinePulse( fsT );
PulseH = PulseH/norm(PulseH);  % ensures proper scaling

%% Loop for accumulating periodiograms
PsBPSK = zeros( 1, Ns*fsT );
PsDQPSK = zeros( 1, (Ns+1)*fsT );

PsR = zeros(1, Ns*fsT);
PsH = zeros(1, (Ns+1)*fsT);

for kk=1:M
    % generate signals
    Symbols  = RandomSymbols(Ns, Alphabet, Priors);
    Symbols  = OQPSK(Symbols);

    SignalR   = LinearModulation(Symbols,PulseR,fsT);
    SignalH   = LinearModulation(Symbols,PulseH,fsT);

    % accumulate periodogram
    PsR = PsR  + Periodogram( SignalR );
    PsH = PsH + Periodogram( SignalH );

end

%average
PsR = PsR/M;
PsH = PsH/M;

%% plot
% frequency axis
ffT  = (-Ns*fsT/2 : Ns*fsT/2-1)/Ns;
ffT1 =(-(Ns+1)*fsT/2 : (Ns+1)*fsT/2-1)/(Ns+1);
plot( ffT, 10*log10(PsR), ffT1, 10*log10(PsH) ) 

grid
xlabel('Normalized Frequency (fT)')
ylabel('PSD (dB)')
axis( [-10 10 -70 5])
legend( 'Rectangular', 'Half-sine')


%% Store name of script for automated figure generation
ScriptName = mfilename;