-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample1.m
executable file
·201 lines (102 loc) · 4.18 KB
/
example1.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
% C O P Y R I G H T N O T I C E
%
% Copyright ©2021. Institute of Science and Technology Austria (IST Austria).
% All Rights Reserved. The underlying technology is protected by PCT Patent
% Application No. PCT/EP2021/054650.
%
% This file is part of the AP demodulation library, which is free software: you can
% redistribute it and/or modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation in version 2.
%
% This program is distributed in the hope that it will be useful, but WITHOUT ANY
% WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
% PARTICULAR PURPOSE. See the GNU General Public License v2 for more details. You
% should have received a copy of the GNU General Public License v2 along with this
% program. If not, see https://www.gnu.org/licenses/.
%
% Contact the Technology Transfer Office, IST Austria, Am Campus 1,
% A-3400 Klosterneuburg, Austria, +43-(0)2243 9000, [email protected], for commercial
% licensing opportunities.
%
% See https://github.com/mgabriel-lt/ap-demodulation for the latest version of the
% code and user-friendly explanations on the working principle, domains of
% application, and advice on the usage of different AP Demodulation algorithms in
% practice.
% EXAMPLE 1
%
% In this example, a synthetic 1D amplitude-modulated signal built from a harmonic
% carrier and a sinusoidal modulator is generated and demodulated by using the
% AP-Basic algorithm. The inferred modulator and carriers are then compared with the
% predefined ones. This example illustrates application of the functions
% 'f_apd_demodulation' and 'f_apd_demodulation_mex' in their simplest form, when the
% signal is sampled uniformly, and when only the final estimates of the modulator and
% infeasibility error are required.
close all
clear all %#ok<CLALL>
% Function type (m or mex) selected by the user
fType = 'm'; % select between 'm' and 'mex'
% Paths to the m and mex functions that perform AP-demodulation
addpath ../libm ../libmex
% Number of sample points
n = 2^14;
% Time vector
T = linspace(0,25,n)';
% Modulator (a nonnegative cosine)
m = (1.01+cos(2*pi*T)) / 2.01;
% Carrier (a harmonic signal)
c = zeros(n,1);
w = [0.4170, 0.7203, 0.0001, 0.3023, 0.1468, 0.0923, 0.1863, 0.3456, 0.3968, ...
0.5388, 0.4192, 0.6852, 0.2045, 0.8781, 0.0274, 0.6705, 0.4173, 0.5587, ...
0.1404, 0.1981, 0.8007, 0.9683, 0.3134, 0.6923, 0.8764, 0.8946, 0.0850, ...
0.0391, 0.1698, 0.8781, 0.0983, 0.4211, 0.9579, 0.5332, 0.6919, 0.3155, ...
0.6865, 0.8346, 0.0183, 0.7501];
for i=1:10
c = c + w(1+4*(i-1)) * cos(2*pi* (256*i*(0:n-1)'/n + w(2+4*(i-1))));
c = c + 0.01*w(3+4*(i-1)) * cos(2*pi* ((256*i+128)*(0:n-1)'/n + w(4*i)));
end
c = c / max(abs(c));
% Signal
s = m .* c;
% Handle to the chosen demodulation function (m-file or mex)
if strcmpi(fType, 'm')
fDemod = @(x,y) f_apd_demodulation (x, y);
elseif strcmpi(fType, 'mex')
fDemod = @(x,y) f_apd_demodulation_mex (x, y);
end
% Demodulation control parameters
Par.Al = 'B'; % algorithm ('B' -> AP-Basic)
Par.Fs = 1/(T(2)-T(1)); % sampling frequency
Par.Fc = 1.5; % cutoff frequency
Par.Et = 10^-5; % infeasibility error tolerance
Par.Ni = 10^3; % maximum iteration number
% Demodulation
[m_, e, iter, tcpu] = fDemod (s, Par);
% Visualization: signal and modulator
figure('Name', 'Signal and Modulator')
set(gcf, 'Units', 'centimeters');
set(gcf, 'Position', [0 10 35 7]);
plot(T,abs(s),'LineWidth',0.75)
hold on
plot(T,m,'k','LineWidth',2)
plot(T,m_,'r','LineWidth',1)
hold off
xlabel('t')
ylabel('x')
axis([3.5 8.5 0 1])
box('off')
legend({'$\bf{|s|}$','$\bf{m}$','$\hat{\bf{m}}$'}, 'Interpreter','latex', ...
'Location',[0.545, 0.75, 0.1, 0.1], 'FontSize',11)
% Visualization: carrier
figure('Name', 'Carrier')
set(gcf, 'Units', 'centimeters');
set(gcf, 'Position', [0 1 35 7]);
plot(T,c,'k','LineWidth',2)
hold on
plot(T,s./m_,'Color',[0 0.7 0],'LineWidth',0.75)
hold off
xlabel('t')
ylabel('c')
axis([3.5 4.0 -1 1])
box('off')
legend({'$\bf{c}$','$\hat{\bf{c}}$'}, 'Interpreter','latex', ...
'Location',[0.55, 0.80, 0.1, 0.1], 'FontSize',11)