How can i combine the two coding

2 Ansichten (letzte 30 Tage)
Fatin Najwa Nursyadza Mohd Ramdan
first code (OFDM)
clc;
clear all;
close all;
L=1;%input('Enter the L factor(1 to 1.5)= '); %oversampling factor
M=16;%input('Enter the alphabet size(Power of 2 and less than number of Symbols)(preferably<32)=');
N=64;%input('Enter the number of transmitted symbols(Power of 2)(preferably>32)=');
ran=floor(M*rand(N,1)); %Generating the random data for transmission
a=qammod(ran,M); %QAM modulating the data.
%Inserting zeros
LN=floor(L*N);
at=a';
aa=[at(1:N) zeros(1,LN-N)]';
x=ifft(aa); %Generating OFDM signal and calculating PAPR
xmag=abs(x);
papr=max(xmag.^2)/mean(xmag.^2);
paprdb=10*log(papr);
subplot(3,1,1),stem(xmag),title('Normal OFDM signal');
xlabel('Time')
ylabel('Amplitude')
xlim([0 LN]);
2nd code (GA)
%%Start of Program
clc
clear
close all
tic
%%Algorithm Parameters
SelMethod = 1;
CrossMethod = 1;
PopSize = 1000;
MaxIteration = 50;
CrossPercent = 65;
MutatPercent = 10;
ElitPercent = 100 - CrossPercent - MutatPercent;
CrossNum = round(CrossPercent/100*PopSize);
if mod(CrossNum,2)~=0;Percent
CrossNum = CrossNum - 1;
end
MutatNum = round(MutatPercent/100*PopSize);
ElitNum = PopSize - CrossNum - MutatNum;
%%Problem Satement
VarMin = [1 2 3 4 5 2];
VarMax =[3 5 5 9 7 3];
b=repmat(VarMin,1000,1);
s=repmat(VarMax,1000,1);
DimNum = 6;
CostFuncName = @rastriginsfcn;
%%Initial Population
Pop = rand(PopSize,DimNum).* (s - b) +b;
Cost = feval(CostFuncName,Pop);
[Cost, Indx] = sort(Cost);
Pop = Pop(Indx,:);
%%Main Loop
MeanMat = [];
MinMat = [];
for Iter = 1:MaxIteration
%%Elitism
ElitPop = Pop(1:ElitNum,:);
%%Cross Over
CrossPop = [];
ParentIndexes = SelectParents_Fcn(Cost,CrossNum,SelMethod);
for ii = 1:CrossNum/2
Par1Indx = ParentIndexes(ii*2-1);
Par2Indx = ParentIndexes(ii*2);
Par1 = Pop(Par1Indx,:);
Par2 = Pop(Par2Indx,:);
[Off1 Off2] = MyCrossOver_Fcn(Par1,Par2,CrossMethod);
CrossPop = [CrossPop ; Off1 ; Off2];
end
%%Mutation
MutatPop = rand(MutatNum,DimNum).*(s(1:100,:) - b(1:100,:)) + b(1:100,:);
%%New Population
Pop = [ElitPop ; CrossPop ; MutatPop];
Cost = feval(CostFuncName,Pop);
[Cost Indx] = sort(Cost);
Pop = Pop(Indx,:);
%%Algorithm Progress
disp('----------------------------------------------')
BestP = Pop(1,:)
BestC = Cost(1)
MinMat(Iter) = Cost(1);
MeanMat(Iter) = mean(Cost);
plot(MinMat,'--r','linewidth',2);
hold on
% plot(MeanMat,'--k','linewidth',2);
% hold off
pause(.5)
end
% ylim([0 5])
%%Results
BestSolution = Pop(1,:)
BestCost = Cost(1,:)
%%End of Program
toc
  9 Kommentare
Walter Roberson
Walter Roberson am 18 Mai 2018
Genetic algorithms are only meaningful if you are changing something and measuring how "good" the resulting configuration is. You have nothing to change.
Be careful, by the way, that you do not optimize against one particular sequence of random numbers in a way that might not be good for a different sequence of random numbers.
Fatin Najwa Nursyadza Mohd Ramdan
thank you.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Produkte


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by