clear;clc ;clf reset;close all
% syms t
% T = 0.4;fsub = 2.5:2.5:20;M = 8;Iarr = [];Iearr = [];
% for m = 1:M-1
%     for i = 1:M - m
%         p = m + i;
% c1 = cos(2*pi*fsub(p)*t);c2 = cos(2*pi*fsub(m)*t);
% c1e = exp(j*2*pi*fsub(p)*t);c2e = exp(-j*2*pi*fsub(m)*t);
% I = int(c1*c2,t,0,T);Iarr = [Iarr I];
% I = int(c1e*c2e,t,0,T);Iearr = [Iearr I];
% end;end
% 
% if Iarr == 0;disp('OK');end
% if Iearr == 0;disp('OK');end
%%%%%% Section for demodulation %%%%%%%

s1_8PSK = 1;s2_8PSK = 1/sqrt(2)*(1 + j);s3_8PSK = j;s4_8PSK = 1/sqrt(2)*(-1 + j);
s5_8PSK = -1;s6_8PSK = 1/sqrt(2)*(-1 - j);s7_8PSK = -j;s8_8PSK = 1/sqrt(2)*(1 - j);%%%%  Symbols for 8 PSK
%%%%% Subcarriers and testing for orthogonality
farr = 1:8;narr = (0:7)/8;
for ii = 1:8
res = exp(j*2*pi*farr(ii)*narr)*(exp(j*2*pi*farr(8)*narr))';
[ii res/farr(end)];
end
farr8PSK = [1 2 3 4 5 6 7 8];

st8PSK = (s4_8PSK*exp(j*2*pi*farr8PSK(1)*narr) + s4_8PSK*exp(j*2*pi*farr8PSK(2)*narr) + ....
          s2_8PSK*exp(j*2*pi*farr8PSK(3)*narr) + s1_8PSK*exp(j*2*pi*farr8PSK(4)*narr) + ....
          s1_8PSK*exp(j*2*pi*farr8PSK(5)*narr) + s7_8PSK*exp(j*2*pi*farr8PSK(6)*narr) + ....
          s8_8PSK*exp(j*2*pi*farr8PSK(6)*narr) + s5_8PSK*exp(j*2*pi*farr8PSK(7)*narr))/farr(end);
 
dt_8PSK = (st8PSK*(exp(j*2*pi*farr8PSK(1)*narr))')