-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_analog_input_signal.m
59 lines (48 loc) · 1.83 KB
/
generate_analog_input_signal.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
function [x] = generate_analog_input_signal(g, targets)
P = g.P;
Q = g.Q;
% create "analog" signal
% buckets before chopping
num_buckets = P + Q - 1;
x = zeros(length(g.Ci), round(g.tau * g.Fs), num_buckets);
x_tmp = zeros(round(g.tau * g.Fs)*num_buckets,1); % a matrix for each channel (needed for another dimension support)
% Following from the equation: g.tau * g.Fs = Nsamples
n_start = round(targets.t * g.Fs) + 1;
n_stop = n_start + g.h_length - 1;
phi1 = -2j*pi*targets.f*(0:P-1)*g.tau; % phase shift for calculations
phi2 = -2j*pi*targets.f.*floor(targets.t/g.tau)*g.tau; % phase shift for calculations
%===============================
C_delay_element=exp(-1j*2*pi*g.Ci'*(0:P-1)/P) ; % Phase shift by modulation
%===============================
for c=1:length(g.Ci)
for l=1:g.L
% for p=1:P
for p = g.less_p
x_tmp((n_start(l):n_stop(l)) + (p - 1) * round(g.tau * g.Fs),1) = ...
x_tmp((n_start(l):n_stop(l)) + (p - 1) * round(g.tau * g.Fs),1) + ...
targets.a(l) * g.h * exp(phi1(l,p)+phi2(l))*C_delay_element(c,p);
end
end
% Make a matrix out of the linearized signal
x_iter = reshape(x_tmp,[round(g.tau * g.Fs), num_buckets]);
x(c,:,:) = x_iter;
end
% chop matrix
x = x(:,:,g.m_p(Q:end)); % Dimensions: 1=Channel, 2=Time, 3=Bucket
% add noise
if g.snr < inf % add noise
Ps = get_h_power(g);
sigma_n = sqrt(Ps / g.snr);
n = sigma_n * (randn(size(x)) + j * randn(size(x))) / sqrt(2);
if 0
figure;
plot(real(n(1,:,1)),'g.:');
hold on;
plot(real(x(1,:,1)),'b.:');
end
x = x + n;
end
end
function [Ps] = get_h_power(g)
Ps = g.h'*g.h / g.h_length; % get average power
end