%%%% Finding P_e manually. Arranged on 29.03.2011
clear;clc;close;clf reset
Mary = '4';M = str2num(Mary);STstr = num2str(M-1);ST = str2num(STstr);sed = num2str(randi(40,1));
%%%% Setting the Mary and stoptime (number of symbols to be transmitted and received) in modulator and demodulator
set_param('ModWaveforms_Exp6/Random Integer Generator','mul',Mary);
set_param('ModWaveforms_Exp6/Random Integer Generator','seed',sed);
set_param('ModWaveforms_Exp6/M-ASK Modulator Baseband','M',Mary);
set_param('ModWaveforms_Exp6/M-PSK Modulator Baseband','M',Mary);
set_param('ModWaveforms_Exp6/Rectangular QAM Modulator Baseband','M',Mary);
set_param('ModWaveforms_Exp6','StopTime',STstr);sim('ModWaveforms_Exp6');

legtit = ['Mary signal';'ASK  signal';'PSK  signal';'QAM  signal'];
smtpsk = [];smtqam = [];
for i = 1:ST + 1;
    sPSK = [real(smtPSK(i));imag(smtPSK(i))];sQAM = [real(smtQAM(i));imag(smtQAM(i))];
    smtMary = smtMary';smtpsk = [smtpsk;sPSK];smtqam = [smtqam;sQAM];
end
rep1 = 10;smtpsk = smtpsk';smtqam = smtqam';
smtMaryarr = [];smtaskarr = [];smtpskarr = [];smtqamarr = [];
for rept = 1:length(smtpsk)
    st = ones(1,rep1)*smtMary(round((rept+0.1)/2));smtMaryarr = [smtMaryarr st];
    st = ones(1,rep1)*smtASK(round((rept+0.1)/2));smtaskarr = [smtaskarr st];
    st = ones(1,rep1)*smtpsk(rept);smtpskarr = [smtpskarr st];
    st = ones(1,rep1)*smtqam(rept);smtqamarr = [smtqamarr st];
end
%%%% Plotting waveforms    
stmat = [smtMaryarr;smtaskarr;smtpskarr;smtqamarr];
for ip = 1:length(stmat(:,1))
    
subplot(4,1,ip);plot((0:length(stmat(1,:)) - 1)/(2*rep1),stmat(ip,:),'LineWidth',3);
set(gcf,'Color',[1 1 1]);set(gca,'FontSize',16)
axis ([0 (length(stmat(1,:)) - 1)/(2*rep1) min(stmat(ip,:))- 1/M max(stmat(ip,:)) + 1/M]);
title([legtit(ip,:) ' for \bf\itM \rm\bf= ' Mary])
end
