echo off;clear;clc;close all
sitil = ['-k  ';'--k ';':k  ';'-.k ';'-*k ';'--*k';':*k ';'-.*k';'-ok ';'--ok';':ok ';'-.ok';'-xk ';'--xk';':xk ';'-.xk'];
linwid = [2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2];
vt = [1 -1 -1 1 -1 1 1 1 1]; %%% Mary message signal, M = 2
% vt = [1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 -1 -1 1 1 1 -1 1 -1 -1 -1 -1 -1];
% vt = [1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 -1 -1 -1 -1];
%vt = [1 -1 -1 -3 -1 1 -1 3 1];
%vt = [-3 -3 1 1 -1];vt = [1 -1];
%%% Setting parameters for CPMFX_Exp1_Sept2012 model file 
fc = 100;Fs = fc*6;Fs = fc*60;vt = vt';initph = '3.218*pi/3*1';initph = '0*pi/3*1';
M = '2';h = '2/3';gtshape = 'Rectangular';L = '1';preH = '1';sPS = '1';%gtshape = 'Raised Cosine';preH = '-3';
%preH = '[1 1]';%preH = '[-1 1]';%preH = '[1 -1]';%preH = '[-1 -1]';
set_param('CPMFX_Exp1/CPM Modulator Baseband','Mnum',M,'modIdx',h,'pulseShape',gtshape,'pulseLength',L,....
    'preHistory',preH,'samplesPerSymbol',sPS,'phaseOffset',initph);

sim('CPMFX_Exp1');%st
t = (0:length(st) - 1)/Fs;fazCPM = log(st)/j;fazCPM = fazCPM';
%%% Conversion into the interval 0 to 2*pi
phCPM1 = atan2(imag(st), real(st));phCPM = phCPM1 + sign(phCPM1).*(sign(phCPM1) - 1)*pi;
phCPM3 = (phCPM*3/pi)';
utCPM = cos(2*pi*fc*t + fazCPM);phCPM3
Cu = unique(phCPM3)
NN = length(Cu) - sum(diff(Cu)<1e-5) - sum(Cu >= 6)
figure(1)
plot(t,utCPM,'-k ','LineWidth',2);
set(gcf,'Color','w');set(gca,'FontSize',16)

xlabel('\itt','FontSize',18,'FontWeight','bold'); 
ylabel('\itu \rm( \itt \rm) - CPM waveform with carrier','FontSize',18,'FontWeight','bold'); 

%%%%% Conventional PSK for the same message signal of vt
% vt = (vt + 1)/2 ; %%% Converting to unipolar
% sPSnum = str2num(sPS);vtarr = [];
% for iv = 1:length(vt)
%     vts = vt(iv);vte = repmat(vts,1,sPSnum);
%     vtarr = [vtarr vte];end
% fazPSK = pi*vtarr;
% utPSK = cos(2*pi*fc*t + fazPSK);
% figure(2)
% plot(t,utPSK,'-k ','LineWidth',2);
% set(gcf,'Color','w');set(gca,'FontSize',16)
% 
% xlabel('\itt','FontSize',18,'FontWeight','bold'); 
% ylabel('\itu \rm( \itt \rm) - PSK waveform with carrier','FontSize',18,'FontWeight','bold');
% 
% %%%% Finding the frequency spectrums of CPM and PSK signals
% %utCPM = [zeros(1,100) utCPM zeros(1,100)]; 
% NFFT = 2^nextpow2(length(t) + 4000); 
% figure(3)
% UfCPM = fft(utCPM,NFFT)/Fs;f = Fs/2*linspace(0,1,NFFT/2)*1;
% semilogy(f,2*abs(UfCPM(1:NFFT/2)),sitil(2,:),'LineWidth',linwid(2));set(gcf,'Color','w');
% %plot(f,abs(UfCPM(1:NFFT/2)),sitil(2,:),'LineWidth',linwid(2));set(gcf,'Color','w');set(gca,'FontSize',16)
% xlabel('\itf','FontSize',18,'FontWeight','bold');set(gca,'FontSize',16) 
% ylabel('\itU_C_P_M \rm( \itf \rm) - CPM signal in frequency domain','FontSize',14,'FontWeight','bold')
% axis ([min(f)*1 max(f)*1 1e-4*1 max(UfCPM)*4]);
% figure(4)
% UfPSK = fft(utPSK,NFFT)/Fs;f = Fs/2*linspace(0,1,NFFT/2);
% semilogy(f,2*abs(UfPSK(1:NFFT/2)),sitil(2,:),'LineWidth',linwid(2));set(gcf,'Color','w');
% %plot(f,abs(UfPSK(1:NFFT/2)),sitil(2,:),'LineWidth',linwid(2));set(gcf,'Color','w');set(gca,'FontSize',16)
% xlabel('\itf','FontSize',18,'FontWeight','bold');set(gca,'FontSize',16) 
% ylabel('\itU_P_S_K \rm( \itf \rm) - PSK signal in frequency domain','FontSize',14,'FontWeight','bold')
% axis ([min(f)*1 max(f)*1 1e-4*1 max(UfPSK)*4]);