% plot_SpecBPSKvsDQPSKRect - BPSK vs pi/4-DQPSK

%% parameters
fsT = 20;
Ns  = 100;
Pulse = RectPulse( fsT );
Pulse = Pulse/norm(Pulse);  % ensures proper scaling
M     = 500; % number of averages

AlphabetBPSK = [ 1, -1];   % BPSK
PriorsBPSK   = ones( size( AlphabetBPSK) ) / length(AlphabetBPSK);

AlphabetDQPSK = -3:2:3;   % 4-PAM
PriorsDQPSK   = ones( size( AlphabetDQPSK) ) / length(AlphabetDQPSK);

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

 
for kk=1:M
    % generate signals
    SymbolsBPSK  = RandomSymbols(Ns, AlphabetBPSK, PriorsBPSK);
    SignalBPSK   = LinearModulation(SymbolsBPSK,Pulse,fsT);

    SymbolsDQPSK = RandomSymbols(Ns, AlphabetDQPSK, PriorsDQPSK);
    SymbolsDQPSK = DPSK(SymbolsDQPSK, pi/4);
    SignalDQPSK  = LinearModulation(SymbolsDQPSK,Pulse,fsT);

    % accumulate periodogram
    PsBPSK  = PsBPSK  + Periodogram( SignalBPSK );
    PsDQPSK = PsDQPSK + Periodogram( SignalDQPSK );

end

%average
PsBPSK  = PsBPSK/M;
PsDQPSK = PsDQPSK/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(PsBPSK), ffT1, 10*log10(PsDQPSK) ) 

grid
xlabel('Normalized Frequency (fT)')
ylabel('PSD (dB)')
axis( [-10 10 -50 5])
legend( 'BPSK', '\pi/4-DQPSK')


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