- added
git-svn-id: http://moon:8086/svn/matlab/trunk@129 801c6759-fa7c-4059-a304-17956f83a07c
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
## Copyright (C) 2019 Jens
|
||||||
|
##
|
||||||
|
## This program 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, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## 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 for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see
|
||||||
|
## <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
## -*- texinfo -*-
|
||||||
|
## @deftypefn {} {@var{retval} =} lens (@var{input1}, @var{input2})
|
||||||
|
##
|
||||||
|
## @seealso{}
|
||||||
|
## @end deftypefn
|
||||||
|
|
||||||
|
## Author: Jens <jens@orion>
|
||||||
|
## Created: 2019-08-27
|
||||||
|
|
||||||
|
function retval = lens (f)
|
||||||
|
|
||||||
|
pw = 2048;
|
||||||
|
ph = 1536;
|
||||||
|
d = 11.1;
|
||||||
|
|
||||||
|
a = pw/ph
|
||||||
|
dh = sqrt(d*d/(1+a*a))
|
||||||
|
dw = a*dh
|
||||||
|
|
||||||
|
%f = 12.5;
|
||||||
|
dw_norm = 36;
|
||||||
|
dh_norm = 24;
|
||||||
|
|
||||||
|
a_norm = dw_norm/dh_norm
|
||||||
|
d_norm = sqrt(dw_norm*dw_norm + dh_norm*dh_norm)
|
||||||
|
crop_factor = d_norm / d
|
||||||
|
f_norm = f * crop_factor
|
||||||
|
|
||||||
|
aov_norm = 360/pi*atan(d_norm/(2*f))
|
||||||
|
aov = 360/pi*atan(d/(2*f))
|
||||||
|
|
||||||
|
endfunction
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
## Copyright (C) 2020 Jens
|
||||||
|
##
|
||||||
|
## This program 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, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## 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 for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see
|
||||||
|
## <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
## -*- texinfo -*-
|
||||||
|
## @deftypefn {} {@var{retval} =} master_slave_eval (@var{input1}, @var{input2})
|
||||||
|
##
|
||||||
|
## @seealso{}
|
||||||
|
## @end deftypefn
|
||||||
|
|
||||||
|
## Author: Jens <jens@orion>
|
||||||
|
## Created: 2020-08-04
|
||||||
|
|
||||||
|
function retval = master_slave_eval (input1, input2)
|
||||||
|
N_cycles = 10
|
||||||
|
|
||||||
|
N_phases_per_cycle = 4
|
||||||
|
dN = 24
|
||||||
|
|
||||||
|
N = N_cycles*N_phases_per_cycle
|
||||||
|
|
||||||
|
k_jitter = 2;
|
||||||
|
# Create Master
|
||||||
|
xp = zeros(1, N_cycles*N_phases_per_cycle*dN);
|
||||||
|
xv = zeros(1, N_cycles*N_phases_per_cycle*dN);
|
||||||
|
|
||||||
|
phase = 0;
|
||||||
|
v = 0;
|
||||||
|
for n=0:N-1,
|
||||||
|
pos = max(1, n*dN + 1 + fix(0.5 + 2*k_jitter*randn()/sqrt(12)));
|
||||||
|
xp(pos) = phase;
|
||||||
|
xv(pos) = v + 1;
|
||||||
|
phase = mod(phase + 1, N_phases_per_cycle);
|
||||||
|
v = mod(v + 1, N_phases_per_cycle);
|
||||||
|
|
||||||
|
endfor
|
||||||
|
|
||||||
|
# Slave
|
||||||
|
k_upd = 0.5;
|
||||||
|
|
||||||
|
phi = 0;
|
||||||
|
dphi = 0;
|
||||||
|
last_n = 0;
|
||||||
|
last_xp = 0;
|
||||||
|
param_changed = 1;
|
||||||
|
|
||||||
|
_phi = [];
|
||||||
|
_dphi = [];
|
||||||
|
_err_phi = [];
|
||||||
|
_err_dphi = [];
|
||||||
|
err_phi = 0
|
||||||
|
err_dphi = 0
|
||||||
|
for n=1:length(xp)
|
||||||
|
yp(n) = phi;
|
||||||
|
phi = mod(phi + dphi, N_phases_per_cycle);
|
||||||
|
|
||||||
|
if xv(n) > 0
|
||||||
|
if last_n > 0
|
||||||
|
doRecalc = param_changed;
|
||||||
|
param_changed = 0;
|
||||||
|
|
||||||
|
den = (n - last_n);
|
||||||
|
dp = mod(xp(n) - last_xp, N_phases_per_cycle);
|
||||||
|
xdphi = dp/den;
|
||||||
|
|
||||||
|
err_phi = phase_error_detector(phi, xp(n));
|
||||||
|
err_dphi = frequency_error_detector(dphi, xdphi);
|
||||||
|
dphi = dphi - k_upd*err_dphi;
|
||||||
|
|
||||||
|
if doRecalc
|
||||||
|
phi = xp(n);
|
||||||
|
dphi = xdphi;
|
||||||
|
end
|
||||||
|
|
||||||
|
if xv(n) == 2
|
||||||
|
# phi = xp(n);
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
last_xp = xp(n);
|
||||||
|
last_n = n;
|
||||||
|
end
|
||||||
|
|
||||||
|
_err_phi = [_err_phi err_phi];
|
||||||
|
_err_dphi = [_err_dphi err_dphi];
|
||||||
|
_phi = [_phi phi];
|
||||||
|
_dphi = [_dphi dphi];
|
||||||
|
|
||||||
|
endfor
|
||||||
|
|
||||||
|
function err = phase_error_detector(lo, ext)
|
||||||
|
err = lo - ext;
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function err = frequency_error_detector(lo, ext)
|
||||||
|
err = lo - ext;
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
close all
|
||||||
|
subplot(3, 1, 1)
|
||||||
|
plot (1:length(xp), xp, 1:length(yp), yp); legend('xp','yp'); grid;
|
||||||
|
|
||||||
|
subplot(3, 1, 2)
|
||||||
|
plot (1:length(_err_phi), _err_phi); legend('err_{phi}'); grid;
|
||||||
|
|
||||||
|
subplot(3, 1, 3)
|
||||||
|
plot (1:length(_err_dphi), _err_dphi); legend('err_{dphi}'); grid;
|
||||||
|
|
||||||
|
endfunction
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
## Copyright (C) 2020 Jens
|
||||||
|
##
|
||||||
|
## This program 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, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## 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 for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see
|
||||||
|
## <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
## -*- texinfo -*-
|
||||||
|
## @deftypefn {} {@var{retval} =} mc_pd_eval (@var{input1}, @var{input2})
|
||||||
|
##
|
||||||
|
## @seealso{}
|
||||||
|
## @end deftypefn
|
||||||
|
|
||||||
|
## Author: Jens <jens@orion>
|
||||||
|
## Created: 2020-08-07
|
||||||
|
|
||||||
|
function retval = mc_pd_eval (delay)
|
||||||
|
|
||||||
|
Nc = 4
|
||||||
|
Nspc = 24;
|
||||||
|
|
||||||
|
ka = 0.9;
|
||||||
|
xmc_i = [ka*ones(1, Nspc/2) -ka*ones(1, Nspc/2)];
|
||||||
|
xmc_q = [-ka*ones(1, Nspc/4) ka*ones(1, Nspc/2) -ka*ones(1, Nspc/4)];
|
||||||
|
x = repmat(xmc_i, 1, Nc);
|
||||||
|
|
||||||
|
lo_i = repmat(xmc_i, 1, Nc);
|
||||||
|
lo_q = repmat(xmc_q, 1, Nc);
|
||||||
|
|
||||||
|
if delay > 0
|
||||||
|
hdly = [zeros(1, delay) 1];
|
||||||
|
xdly = filter(hdly, 1, x);
|
||||||
|
else
|
||||||
|
xdly = x
|
||||||
|
end
|
||||||
|
|
||||||
|
y_i = lo_i.*xdly;
|
||||||
|
y_q = lo_q.*xdly;
|
||||||
|
|
||||||
|
close all;
|
||||||
|
subplot(2, 1, 1)
|
||||||
|
plot(1:Nc*Nspc, lo_i, 1:Nc*Nspc, lo_q); legend('Lo_I','Lo_Q'); grid
|
||||||
|
|
||||||
|
subplot(2, 1, 2)
|
||||||
|
plot(1:Nc*Nspc, y_i, 1:Nc*Nspc, y_q); legend('I','Q'); grid
|
||||||
|
|
||||||
|
endfunction
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
## Copyright (C) 2020 Jens
|
||||||
|
##
|
||||||
|
## This program 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, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## 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 for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see
|
||||||
|
## <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
## -*- texinfo -*-
|
||||||
|
## @deftypefn {} {@var{retval} =} mc_pd_eval (@var{input1}, @var{input2})
|
||||||
|
##
|
||||||
|
## @seealso{}
|
||||||
|
## @end deftypefn
|
||||||
|
|
||||||
|
## Author: Jens <jens@orion>
|
||||||
|
## Created: 2020-08-07
|
||||||
|
|
||||||
|
function retval = mc_pd_eval2 (perr, ferr, slave_oversample)
|
||||||
|
|
||||||
|
Nc = 10;
|
||||||
|
Nspc = 96;
|
||||||
|
|
||||||
|
ka = 0.9;
|
||||||
|
klead = 0.2;
|
||||||
|
klag = 0.01/slave_oversample;
|
||||||
|
|
||||||
|
# Create master
|
||||||
|
xm = [];
|
||||||
|
for n=1:Nspc,
|
||||||
|
for m=1:slave_oversample,
|
||||||
|
xm = [xm n];
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
x = repmat(xm, 1, Nc);
|
||||||
|
|
||||||
|
N = Nc*Nspc*slave_oversample;
|
||||||
|
assert (N == length(x));
|
||||||
|
|
||||||
|
# Create slave
|
||||||
|
pc = 1.0/slave_oversample + Nspc/2 + perr;
|
||||||
|
dpc = 1.0/slave_oversample + ferr;
|
||||||
|
|
||||||
|
sample_count = slave_oversample;
|
||||||
|
|
||||||
|
for n=1:N,
|
||||||
|
sample_count = sample_count - 1;
|
||||||
|
perr = phase_det(pc, x(n), Nspc);
|
||||||
|
if sample_count == 0,
|
||||||
|
sample_count = slave_oversample;
|
||||||
|
else
|
||||||
|
perr = 0;
|
||||||
|
end
|
||||||
|
_lo(n) = mod(pc - Nspc/2 - 1, Nspc) + 1;
|
||||||
|
pc = mod(pc + dpc - klead*perr, Nspc);
|
||||||
|
dpc = dpc - klag*perr;
|
||||||
|
_perr(n) = perr;
|
||||||
|
_dpc(n) = dpc;
|
||||||
|
end
|
||||||
|
|
||||||
|
function perr = phase_det(lo, x, Nspc)
|
||||||
|
perr = mod((lo - x), Nspc) - Nspc/2;
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
close all;
|
||||||
|
subplot(3, 1, 1)
|
||||||
|
plot(1:N, _lo, 1:N, x); legend('Lo', 'x'); grid
|
||||||
|
|
||||||
|
subplot(3, 1, 2)
|
||||||
|
plot(1:N, _dpc); legend('f'); grid
|
||||||
|
|
||||||
|
subplot(3, 1, 3)
|
||||||
|
plot(1:N, _perr); legend('p'); grid
|
||||||
|
|
||||||
|
endfunction
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
## Copyright (C) 2020 Jens
|
||||||
|
##
|
||||||
|
## This program 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, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## 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 for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see
|
||||||
|
## <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
## -*- texinfo -*-
|
||||||
|
## @deftypefn {} {@var{retval} =} mc_pd_eval (@var{input1}, @var{input2})
|
||||||
|
##
|
||||||
|
## @seealso{}
|
||||||
|
## @end deftypefn
|
||||||
|
|
||||||
|
## Author: Jens <jens@orion>
|
||||||
|
## Created: 2020-08-07
|
||||||
|
|
||||||
|
function retval = mc_pd_eval3 (perr, freq, slave_oversample)
|
||||||
|
|
||||||
|
Nc = 10;
|
||||||
|
Nspc = 96;
|
||||||
|
|
||||||
|
ka = 0.9;
|
||||||
|
klead = 0.4;
|
||||||
|
klag = 0.01/slave_oversample;
|
||||||
|
lag = 0;
|
||||||
|
|
||||||
|
# Create master
|
||||||
|
xm = [];
|
||||||
|
for n=1:Nspc,
|
||||||
|
for m=1:slave_oversample,
|
||||||
|
xm = [xm n];
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
x = repmat(xm, 1, Nc);
|
||||||
|
|
||||||
|
N = Nc*Nspc*slave_oversample;
|
||||||
|
assert (N == length(x));
|
||||||
|
|
||||||
|
# Create slave
|
||||||
|
pc = Nspc/2 + perr;
|
||||||
|
dfreq = freq/slave_oversample;
|
||||||
|
dpc = dfreq;
|
||||||
|
|
||||||
|
sample_count = slave_oversample;
|
||||||
|
for n=1:N,
|
||||||
|
perr = phase_det(pc, x(n), Nspc);
|
||||||
|
sample_count = sample_count - 1;
|
||||||
|
if sample_count == 0,
|
||||||
|
sample_count = slave_oversample;
|
||||||
|
else
|
||||||
|
perr = 0;
|
||||||
|
end
|
||||||
|
dpc = dfreq - (klag*lag + klead*perr);
|
||||||
|
pc = mod(pc + dpc, Nspc);
|
||||||
|
lag = lag + perr;
|
||||||
|
_lo(n) = mod(pc - Nspc/2 - 1/slave_oversample, Nspc);
|
||||||
|
_perr(n) = perr;
|
||||||
|
_dpc(n) = dpc;
|
||||||
|
end
|
||||||
|
|
||||||
|
function perr = phase_det(lo, x, Nspc)
|
||||||
|
perr = mod((lo - x), Nspc) - Nspc/2;
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
close all;
|
||||||
|
subplot(3, 1, 1)
|
||||||
|
plot(1:N, _lo, 1:N, x); legend('Lo', 'x'); grid
|
||||||
|
|
||||||
|
subplot(3, 1, 2)
|
||||||
|
plot(1:N, _dpc); legend('f'); grid
|
||||||
|
|
||||||
|
subplot(3, 1, 3)
|
||||||
|
plot(1:N, _perr); legend('p'); grid
|
||||||
|
|
||||||
|
endfunction
|
||||||
Reference in New Issue
Block a user