Train_inputX1 =All_data_segments;
Train_outputX1 =Modulation_Schemes ;
Test_X1 =ceil(0.1 *size(All_data_segments,1));
idx1_t= randperm(size(All_data_segments,1),Test_X1);
testX1_input = All_data_segments(idx1_t',:);
testX1_output = Modulation_Schemes(idx1_t);
Train_inputX1(idx1_t',:) = [];
Train_outputX1(idx1_t',:) =[];
Train1_inputX1 = Train_inputX1;
Train1_outputX1 =Train_outputX1;
Val_X1 =ceil(0.2 *size(Train_outputX1,1));
idx1_v= randperm(size(Train_outputX1,1),Val_X1);
ValX1_input =Train1_inputX1(idx1_v',:);
ValX1_output =Train_outputX1(idx1_v);
Train1_inputX1(idx1_v',:) = [];
Train1_outputX1(idx1_v',:) =[];
DataParts = zeros(size(Train1_inputX1,1), size(Train1_inputX1,2),1,2);
DataParts(:,:,:,1) = real(cell2mat(Train1_inputX1));
DataParts(:,:,:,2) = imag(cell2mat(Train1_inputX1)) ;
XTrain=(reshape(DataParts, [400,1,2,3600]));
DataParts1 = zeros(size(testX1_input,1), size(testX1_input,2),1, 2);
DataParts1(:,:,:,1) = real(cell2mat(testX1_input));
DataParts1(:,:,:,2) = imag(cell2mat(testX1_input)) ;
Ttrain=(reshape(DataParts1,[400,1,2,500]));
DataParts2 = zeros(size(ValX1_input,1), size(ValX1_input,2),1, 2);
DataParts2(:,:,:,1) = real(cell2mat(ValX1_input));
DataParts2(:,:,:,2) = imag(cell2mat(ValX1_input));
Vtrain =(reshape(DataParts2,[400,1,2,900]));
Valoutfinal= categorical(ValX1_output);
testoutfinal =categorical(testX1_output);
Trainoutfinal=categorical(Train1_outputX1);
layers = [imageInputLayer([400 1 2])
convolution2dLayer([300 1],3,'Stride',1)
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
imageInputLayer([400 1 2])
convolution2dLayer([3 1],8,'Padding',[0 0 0 1])
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer([3 1],16,'Padding',[0 0 0 1])
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer([3 1],32,'Padding',[0 0 0 1])
opts = trainingOptions('adam', ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'ValidationData',{Vtrain,(Valoutfinal)},...
'ValidationPatience',Inf);
opts1 = trainingOptions('adam', ...
'InitialLearnRate',1e-3, ...
'Plots','training-progress', ...
'ValidationData',{Vtrain,(Valoutfinal)},...
'ValidationPatience',Inf);
net1 = trainNetwork(XTrain,Trainoutfinal,layers,opts);