-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_gp.m
84 lines (70 loc) · 2.85 KB
/
demo_gp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
%%DEMO Demonstrates program to show examples simulated communication
%%signal and the classificaition of modulation classifiers
%
% Copyright (C) 2014 Zhechen Zhu
% This file is part of Zhechen Zhu's AMC toolbox 0.4
%
% Update (version no.): modification (editor)
% Specify demo script setting
textDisp = 1; % if display text status
graphic = 1; % if give visual illustrations
% Define signal generation specifications
modulation = '16qam';
sampleNumber = 1024;
% Generate transmitted signal
signalT = genmodsig(modulation,sampleNumber);
% Transpose transmitted signal with given channel
SNR = 5; % signal-to-noise ratio (dB)
signalR = amcawgn(signalT,SNR); % AWGN channel
% Plot contellation of transmitted and received signal
if graphic == 1
subplot(2,2,1);
scatter(real(signalT),imag(signalT));
title('Transmitted clear signal');
subplot(2,2,2);
scatter(real(signalR),imag(signalR));
title('Received noisy signal');
end
% Implement GP feature selection and combination
featureCombo = amcgp(signalR,modulationPool,SNR);
% Generate reference features for each modulation candidate
for iModulationCandidate = 1:numel(modulationPool)
% Select modulation candidate
modulationCandidate = modulationPool{iModulationCandidate};
% Generate reference signals and features
for iRef = 1:30
refSignal = genmodsig(modulationCandidate,length(signalR));
refSignal=amcawgn(refSignal,SNR);
refCumI(iRef+(iModulationCandidate-1)*30,:) = cumulant(real(refSignal));
refCumQ(iRef+(iModulationCandidate-1)*30,:) = cumulant(imag(refSignal));
end
% create label for the referenc feature sets
label((iModulationCandidate-1)*30+1:(iModulationCandidate-1)*30+30,1)=iModulationCandidate;
end
% Maximum likelihood classifier
modulationPool = {'2pam' '4pam' '8pam' '2psk' '4psk' '8psk' '4qam' '16qam' '64qam'};
if textDisp
fprintf('Automatic modulation classification in progress...\n\n')
fprintf(['Testing modulation:\t\t' modulation '\n']);
fprintf('Communication channel:\tAWGN \n');
fprintf(['Signal-to-noise ratio:\t' int2str(SNR) ' dB\n\n']);
fprintf('Classifier:\t\t\t\tMaximum Likelihood Classifier.\n\n')
end
[class likelihood]= amcknn(signalR,modulationPool,SNR);
if textDisp
fprintf('Automatic modulation classification in completed.\n\n')
fprintf(['Classified modulation:\t' class '\n'])
fprintf('\n')
if strcmp(modulation,class)
fprintf('Automatic modulation classificall is successful!\n\n')
else
fprintf('Automatic modulation classificall has failed.\n\n')
end
end
if graphic == 1
subplot(2,2,[3 4]);
bar(likelihood-mean(likelihood))
title('Normalized likelihood from different hypotheses')
set(gca,'XTickLabel',modulationPool)
set(gcf, 'Position', [50 50 700 600])
end