-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample3.m
executable file
·175 lines (91 loc) · 3.76 KB
/
example3.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
% 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 3
%
% In this example, a nonuniformly sampled 1D amplitude-modulated signal built from a
% white-noise carrier and an LP-random modulator is generated and demodulated by
% using the AP-Projected algorithm. The inferred modulator is then compared with the
% predefined one. This example illustrates application of the functions
% 'f_apd_demodulation' and 'f_apd_demodulation_mex' to demodulate nonuniformly sampled
% signals.
close all
clear all %#ok<CLALL>
% Function type (m or mex) selected by the user
fType = 'mex'; % 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^10;
% Time vector
rng(1);
t = [0; cumsum(0.5+2.0*rand(n,1))];
t = 10 * t(1:end-1) / t(end);
% Modulator (a low-pass-randomsignal)
m = zeros(n,1);
w = [1.5648, 0.5312, 0.1413, 0.7588, -0.8616, -0.3586, 0.9106, -0.1787, -0.0108, ...
-0.0989, -0.3559, -0.4015, 0.2917, -0.3458, -1.1990, 0.7651, -0.9884, -1.1668, ...
0.6584, -1.3693, -0.4143, 0.6981, 0.9181, 2.9477, -0.3757, 0.8218, -0.5699, ...
-0.5495, -0.0108, 0.0854, 1.0189, 1.7904, 0.7577, -0.8434, -0.7300, -0.8675, ...
-0.6159, -0.3319, 1.4449, 0.6741];
for i=0:19
m = m + w(1+2*i)*cos(2*pi*i*t/10+w(2*(i+1)));
end
m = m - min(m(:)) + 0.001;
m = m / max(m(:));
% Carrier (a sine)
c = sin(2*pi*5*t);
% Signal
s = c .* m;
% Handle to the chosen demodulation function (m-file or mex)
if strcmpi(fType, 'm')
fDemod = @(x,y,z) f_apd_demodulation (x, y, [], z);
elseif strcmpi(fType, 'mex')
fDemod = @(x,y,z) f_apd_demodulation_mex (x, y, [], z);
end
% Demodulation control parameters
Par.Al = 'P'; % algorithm
Par.Fs = 1 / mean(diff(t)); % sampling frequency
Par.Fc = 25 * Par.Fs / (n*8); % cutoff frequency
Par.Et = 10^-4; % infeasibility error tolerance
Par.Ni = 3*10^4; % maximum iteration number
Par.Nr = n * 8; % number of sample points on the interpolation grid
% Demodulation
[m_, e, Niter, tcpu] = fDemod (s, Par, t);
% Visualization: signal and modulator
figure('Name', 'Signal and Modulator')
set(gcf, 'Units', 'centimeters');
set(gcf, 'Position', [0 2 35 7]);
plot(t,abs(s),'o-','LineWidth',0.75,'MarkerSize',2)
hold on
plot(t,m,'k','LineWidth',2)
plot(t,m_,'r','LineWidth',1)
hold off
xlabel('t')
ylabel('x')
axis([2 4 0 1])
box('off')
legend({'$\bf{|s|}$','$\bf{m}$','$\hat{\bf{m}}$'}, 'Interpreter','latex', ...
'Location',[0.40, 0.75, 0.1, 0.1], 'FontSize',11)
tcpu