Skip to content

Commit 133cd53

Browse files
committed
first commit
0 parents  commit 133cd53

16 files changed

+992
-0
lines changed

amcawgn.m

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function sigOut=amcawgn(sigIn,snr)
2+
%AMCAWGN Adds AWGN noise to signals according to Signal-to-noise ratio.
3+
%
4+
% sigOut=amcawgn(sigIn,snr) measures the power
5+
% of input signal sigIn and adds noise according
6+
% to snr (dB) to generate signals with noise sigOut
7+
%
8+
% Example: if sigIn = [1; j; -1; j; -j; -1] and snr = 10
9+
%
10+
% sigOut=amcawgn(sigIn,snr)
11+
%
12+
% sigOut =
13+
%
14+
% 1.2950 - 0.1861i
15+
% -0.0579 + 0.6392i
16+
% -1.3238 - 0.0961i
17+
% 0.0932 + 1.3479i
18+
% 0.0650 - 1.1780i
19+
% -0.7895 + 0.1439i
20+
%
21+
% Copyright (C) 2014 Zhechen Zhu
22+
% This file is part of Zhechen Zhu's AMC toolbox 0.5
23+
%
24+
% Update (version no.): modification (editor)
25+
% 0.5: The dimension of the input signal is no longer restricted (Zhechen Zhu)
26+
27+
% Determine the dimension of input signal data
28+
N = size(sigIn);
29+
30+
% Generate unscaled AWGN noise components
31+
noise = randn(N) + j*randn(N);
32+
33+
% Calculate signal power
34+
sigPower = mean(abs(sigIn).^2);
35+
36+
% Calculate unscaled noise power
37+
noisePower = mean(abs(noise).^2);
38+
39+
% Calculate scaling factor for noise components according to SNR
40+
sigNoise = sqrt(sigPower./noisePower).*(10^(-snr/20));
41+
42+
% Map the noise power scaling factor
43+
sigOut = sigIn + noise*sigNoise;

amcgp.m

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function featureCombo = amcgp(sigIn,modulationPool,channelParameter)
2+
%AMCGP Create a feature combination for AMC.
3+
%
4+
% featureCombo = amcgp(sigIn,modulationPool,channelParameter) selects a
5+
% set features from the raw features and creates a new feature as a
6+
% combination of selected raw features.The fitness evaluation is
7+
% implemented through a mini-classification method using k-nearest
8+
% neighbor classifier.
9+
%
10+
% Copyright (C) 2014 Zhechen Zhu
11+
% This file is part of Zhechen Zhu's AMC toolbox 0.4
12+
%
13+
% Update (version no.): modification (editor)
14+
15+
sampleNo=length(sigIn);
16+
17+
% Create reference feature sets
18+
iModulationCandidate = 1;
19+
for iModulationCandidate = 1:numel(modulationPool)
20+
modulationCandidate = modulationPool{iModulationCandidate};
21+
22+
for iRef = 1:30
23+
refSignal = genmodsig(modulationCandidate,sampleNo);
24+
refSignal = amcawgn(refSignal,channelParameter); % AWGN channel;
25+
[refMomI(iRef+(iModulationCandidate-1)*30,:), refCumI(iRef+(iModulationCandidate-1)*30,:)] = hos(real(refSignal));
26+
[refMomQ(iRef+(iModulationCandidate-1)*30,:), refCumQ(iRef+(iModulationCandidate-1)*30,:)] = hos(imag(refSignal));
27+
end
28+
29+
% create label for the referenc feature sets
30+
label((iModulationCandidate-1)*30+1:(iModulationCandidate-1)*30+30,1)=iModulationCandidate;
31+
32+
end
33+
34+
% Prepare GP training data
35+
x=[refCumI refCumQ];
36+
y=label;
37+
filex=strcat(pwd,'\gpleab','\tempx.txt');
38+
filey=strcat(pwd,'\gplab','\tempy.txt');
39+
dlmwrite(filex,x,'delimiter','\t');
40+
dlmwrite(filey,y,'delimiter','\t');
41+
42+
% Set GP parameters
43+
p=resetparams;
44+
p.calcfitness='knnfitness'; % Set fitness evaluation method
45+
p=setfunctions(p,'times',2,'plus',2,'minus',2,'mylog',1,'sqrt',1,'sin',1,'cos',1,'asin',1,'acos',1,'tan',1,'tanh',1,'abs',1,'negator',1);
46+
p=setoperators(p,'crossover',2,2,'mutation',1,1);
47+
p.operatorprobstype='fixed';
48+
p.initialprobstype='fixed';
49+
p.initialfixedprobs=[0.8 0.2];
50+
p.minprob=0;
51+
p.datafilex=filex;
52+
p.datafiley=filey;
53+
p.usetestdata=0;
54+
p.calcdiversity={'uniquegen'};
55+
p.calccomplexity=1;
56+
57+
% Screen & Graphic Output
58+
p.output='silent';
59+
% p.graphics={'plotfitness','plotdiversity','plotcomplexity','plotoperators'};
60+
61+
% Run GP program
62+
if exit gplab
63+
[v,b]=gplab(100,25,p);
64+
else
65+
fprintf('The GPLAB toolbox is not installed. Please visit http://gplab.sourceforge.net/ to install the toolbox.')
66+
end
67+
featureCombo = b.str;

amcknn.m

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function [modulationDecision, neighbours] = amcknn(modulationPool,testFeature,refFeature,label)
2+
%AMCKNN Modulation classifies using K-nearest neighbour classifier.
3+
%
4+
% [modulationDecision, neighbours] = amcknn(modulationPool,testFeature,refFeature,label)
5+
% classifies the modulation type of sigIn from a pool of modulation
6+
% canddiates defined by modulation pool. The channel state information
7+
% channelParameter is needed to complete the classification.
8+
%
9+
% Copyright (C) 2014 Zhechen Zhu
10+
% This file is part of Zhechen Zhu's AMC toolbox 0.4
11+
%
12+
% Update (version no.): modification (editor)
13+
14+
% % Feature extraction
15+
% cumI = cumulant(real(sigIn));
16+
% cumQ = cumulant(imag(sigIn));
17+
%
18+
% % Create reference feature sets
19+
% for iModulationCandidate = 1:numel(modulationPool)
20+
%
21+
% % Select modulation candidate
22+
% modulationCandidate = modulationPool{iModulationCandidate};
23+
%
24+
% % Generate reference signals and features
25+
% for iRef = 1:30
26+
% refSignal = genmodsig(modulationCandidate,length(sigIn));
27+
% refSignal=amcawgn(refSignal,channelParameter(1));
28+
% refCumI(iRef+(iModulationCandidate-1)*30,:) = cumulant(real(refSignal));
29+
% refCumQ(iRef+(iModulationCandidate-1)*30,:) = cumulant(imag(refSignal));
30+
% end
31+
%
32+
% % create label for the referenc feature sets
33+
% label((iModulationCandidate-1)*30+1:(iModulationCandidate-1)*30+30,1)=iModulationCandidate;
34+
% end
35+
36+
% Measure distance from the test signal to reference signals
37+
distance = sum(abs(bsxfun(@minus,testFeature,refFeature)),2);
38+
decisionMatrix = [distance label];
39+
decisionMatrix = sortrows(decisionMatrix);
40+
decisionMatrix = decisionMatrix(1:11,:);
41+
42+
% Finding the mode of modulations in all neighbours
43+
class = mode(decisionMatrix(:,2));
44+
neighbours = hist(decisionMatrix(:,2),1:numel(modulationPool));
45+
modulationDecision = modulationPool{class};

amcks.m

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
function [modulationDecision, testStat] = amcks(sigIn,modulationPool,channelParameter)
2+
%%AMCKS Classifies the modulation type of the input signal using
3+
%%Kolmogorov-Smirnov test classifier
4+
%
5+
% result = amcks(sigIn,modulationPool,channelParameter) classifies the
6+
% modulation type of sigIn from a pool of modulation canddiates defined
7+
% by modulation pool. The channel state information channelParameter is
8+
% needed to complete the classification.
9+
%
10+
% Copyright (C) 2014 Zhechen Zhu
11+
% This file is part of Zhechen Zhu's AMC toolbox 0.4
12+
%
13+
% Update (version no.): modification (editor)
14+
15+
% Construct emperical distribution on in-phase segment
16+
signalI = sort(real(sigIn));
17+
probI = hist(signalI,signalI);
18+
empericalI = cumsum(probI)/length(sigIn);
19+
20+
% Construct emperical distribution on quadrature segment
21+
signalQ = sort(imag(sigIn));
22+
probQ = hist(signalQ,signalQ);
23+
empericalQ = cumsum(probQ)/length(sigIn);
24+
25+
for iModulationCandidate = 1:numel(modulationPool)
26+
% Select modulation candidate
27+
modulationCandidate = modulationPool{iModulationCandidate};
28+
29+
% Generated alphabet set/symbols for the modulation candidate
30+
symbol = getalphabet(modulationCandidate);
31+
32+
symbolI = sort(real(symbol));
33+
symbolQ = sort(imag(symbol));
34+
35+
% Calculate the noise variance from SNR
36+
sigma = sqrt(10^(-channelParameter(1)/10))/sqrt(2);
37+
38+
% Calculate referene cumulative distribution at in-phase signal values
39+
for iCentroid = 1:length(symbolI)
40+
cumdisI(iCentroid,:) = cdf('normal',signalI,symbolI(iCentroid),sigma);
41+
end
42+
cumdisI= sum(cumdisI)/length(symbolI);
43+
44+
% Evaluate KS distance between in-phase signal and reference CDF
45+
dI(iModulationCandidate)=max(abs(empericalI-cumdisI));
46+
47+
% Calculate referene cumulative distribution at in-phase signal values
48+
for iCentroid = 1:length(symbolQ)
49+
cumdisQ(iCentroid,:) = cdf('normal',signalQ,symbolQ(iCentroid),sigma);
50+
end
51+
cumdisQ= sum(cumdisQ)/length(symbolQ);
52+
dQ(iModulationCandidate)=max(abs(empericalQ-cumdisQ));
53+
54+
% Calcualte the KS test statistics for the modulation candidate
55+
testStat(iModulationCandidate) = mean([dI(iModulationCandidate) dQ(iModulationCandidate)]);
56+
end
57+
58+
% Find the modulation hyphotheses with smallest test statistics
59+
[Y,iModulationDecision] = min(testStat);
60+
modulationDecision = modulationPool{iModulationDecision};

amcmimo.m

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function sigOut=amcmimo(sigIn,Nt,Nr,snr)
2+
% AMCMIMO Adds MIMO channnel and AWGN noise to signals according
3+
% value of Signal-to-noise ratio (SNR)
4+
%
5+
% sigOut=amc_awgn(sigIn,snr) measures the power
6+
% of input signal sigIn and adds noise according
7+
% to snr (dB) to generate signals with noise sigOut
8+
%
9+
% Copyright (C) 2013 Zhechen Zhu
10+
% This file is part of Zhechen Zhu's AMC toolbox 0.1
11+
%
12+
% Update (version no.): modification (editor)
13+
14+
% Determine the dimension of input signal data
15+
N = length(sigIn);
16+
17+
% Generate the fading channel matrix
18+
19+
% Determine the number of transmitters and receivers
20+
% Nt=hMIMOChan.NumTransmitAntennas;
21+
% Nr=hMIMOChan.NumReceiveAntennas;
22+
Nr=size(hMIMOChan,1);
23+
Nt=size(hMIMOChan,2);
24+
25+
% Split the signal to spatial streams
26+
channelInput = reshape (sigIn, [Nt N/Nt]).';
27+
28+
% Filter the signal using MIMO channel
29+
% [channelOutput, pathGains] = step(hMIMOChan, channelInput);
30+
channelOutput = (hMIMOChan*channelInput.').';
31+
32+
for i = 1:Nr
33+
% Generate unscaled AWGN noise componentsv
34+
noise(:,i) = randn(N/Nt,1) + j*randn(N/Nt,1);
35+
36+
% Calculate signal power
37+
sigPower(:,i) = mean(abs(channelOutput(:,i)).^2);
38+
39+
% Calculate unscaled noise power
40+
noisePower(:,i) = mean(abs(noise(:,i)).^2);
41+
42+
% Calculate scaling factor for noise components according to SNR
43+
sigNoise(:,i) = sqrt(sigPower(:,i)./noisePower(:,i)).*(10^(-snr/20));
44+
45+
% Map the noise power scaling factor
46+
sigOut(:,i) = channelOutput(:,i) + noise(:,i)*sigNoise(:,i);
47+
end

amcmimo.m~

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function sigOut=amcmimo(sigIn,Nt,Nr,snr)
2+
% AMCMIMO Adds MIMO channnel and AWGN noise to signals according
3+
% value of Signal-to-noise ratio (SNR)
4+
%
5+
% sigOut=amc_awgn(sigIn,snr) measures the power
6+
% of input signal sigIn and adds noise according
7+
% to snr (dB) to generate signals with noise sigOut
8+
%
9+
% Copyright (C) 2013 Zhechen Zhu
10+
% This file is part of Zhechen Zhu's AMC toolbox 0.1
11+
%
12+
% Update (version no.): modification (editor)
13+
14+
% Determine the dimension of input signal data
15+
N = length(sigIn);
16+
17+
% Determine the number of transmitters and receivers
18+
% Nt=hMIMOChan.NumTransmitAntennas;
19+
% Nr=hMIMOChan.NumReceiveAntennas;
20+
Nr=size(hMIMOChan,1);
21+
Nt=size(hMIMOChan,2);
22+
23+
% Split the signal to spatial streams
24+
channelInput = reshape (sigIn, [Nt N/Nt]).';
25+
26+
% Filter the signal using MIMO channel
27+
% [channelOutput, pathGains] = step(hMIMOChan, channelInput);
28+
channelOutput = (hMIMOChan*channelInput.').';
29+
30+
for i = 1:Nr
31+
% Generate unscaled AWGN noise componentsv
32+
noise(:,i) = randn(N/Nt,1) + j*randn(N/Nt,1);
33+
34+
% Calculate signal power
35+
sigPower(:,i) = mean(abs(channelOutput(:,i)).^2);
36+
37+
% Calculate unscaled noise power
38+
noisePower(:,i) = mean(abs(noise(:,i)).^2);
39+
40+
% Calculate scaling factor for noise components according to SNR
41+
sigNoise(:,i) = sqrt(sigPower(:,i)./noisePower(:,i)).*(10^(-snr/20));
42+
43+
% Map the noise power scaling factor
44+
sigOut(:,i) = channelOutput(:,i) + noise(:,i)*sigNoise(:,i);
45+
end

amcml.m

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function [modulationDecision, likelihood]= amcml(sigIn,modulationPool,channelParameter)
2+
%%AMCML Classifies the modulation type of the input signal using maximum
3+
%%likelihood classifier
4+
%
5+
% result = amcml(sigIn,modulationPool,channelParameter) classifies the
6+
% modulation type of sigIn from a pool of modulation canddiates defined
7+
% by modulation pool. The channel state information channelParameter is
8+
% needed to complete the classification.
9+
%
10+
% Copyright (C) 2013 Zhechen Zhu
11+
% This file is part of Zhechen Zhu's AMC toolbox 0.3
12+
%
13+
% Update (version no.): modification (editor)
14+
15+
for iModulationCandidate = 1:numel(modulationPool)
16+
% Select modulation candidate
17+
modulationCandidate = modulationPool{iModulationCandidate};
18+
19+
% Generated alphabet set/symbols for the modulation candidate
20+
symbol = getalphabet(modulationCandidate);
21+
22+
% Calculate the noise variance from SNR
23+
sigma = sqrt(10^(-channelParameter(1)/10))/sqrt(2);
24+
25+
% Evaluate the likelihood using AWGN noise model
26+
likelihood(iModulationCandidate) = likelihoodfunction(sigIn,symbol,sigma);
27+
end
28+
29+
% Find the modulation candidate that provides the highest likelihood
30+
[Y,iModulationDecision] = max(likelihood);
31+
modulationDecision = modulationPool{iModulationDecision};

0 commit comments

Comments
 (0)