Files
matlab/tunable_bandpass.m
jens f59fb8f67d added
git-svn-id: http://moon:8086/svn/matlab/trunk@100 801c6759-fa7c-4059-a304-17956f83a07c
2018-12-14 17:16:15 +00:00

115 lines
4.4 KiB
Matlab
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## Copyright (C) 2018 Jens Ahrensfeld
##
## 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 <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {@var{retval} =} tunable_bandpass (@var{input1}, @var{input2})
##
## @seealso{}
## @end deftypefn
## Author: Jens Ahrensfeld <ahrensfeld@w2ess001vm>
## Created: 2018-11-26
## taken from: https://www.mwrf.com/components/bandpass-filters-feature-wide-tuning-ranges
function tunable_bandpass(varargin)
params = struct ('f_low_Hz', 100e6, 'f_high_Hz', 600e6, 'f_step_Hz', 1e6, 'B_geo_Hz', 20e6, 'R_geo', 1000, 'R_0', 50, 'k_gamma', 1.0);
units = struct ('f_low_Hz', 'Hz', 'f_high_Hz', 'Hz', 'f_step_Hz', 'Hz', 'B_geo_Hz', 'Hz', 'R_geo', 'Ω', 'R_0', 'Ω', 'k_gamma', '');
% Parse parameters
names = fieldnames(params);
for k=1:nargin-1,
for n=1:length(names),
if strcmpi(varargin{k}, names{n})
params.(names{n}) = varargin{k+1};
end
end
end
print_parameters(params)
f_low_Hz = params.f_low_Hz; % Minimum tunable filter center frequency (Hz)
f_high_Hz = params.f_high_Hz; % Maximum tunable filter center frequency (Hz)
B_geo_Hz = params.B_geo_Hz; % -3 dB RF filter bandwidth (in Hz) at the geometric center frequency
R_geo = params.R_geo; % Internal filter impedance (in Ω) at the geometric center frequency of the filter
R_0 = params.R_0; % Port impedance, usually taken as 50 Ω
k_gamma = params.k_gamma; % Constant value. A value of γ = 1.0 results in a constant-Q filter design,
% while a value of γ = 2.0 results in a constant-bandwidth filter design.
% A value between one and two will yield a blend of the two filter characteristics.
% Inductor Q values will be more critical as the value of γ is increased.
f_step_Hz = params.f_step_Hz;
f_Hz = f_low_Hz:f_step_Hz:f_high_Hz;
omega = 2*pi*f_Hz;
f_geo_Hz = sqrt(f_low_Hz*f_high_Hz) % Hz
omega_geo = 2*pi*f_geo_Hz % rad/sec
% Design I.
R_t = R_geo*(omega/omega_geo).^k_gamma; % Equ. (1)
L_c = R_geo/omega_geo % Equ. (2)
C_tgeo = 1./(pi*sqrt(2)*R_geo*B_geo_Hz) % Equ. (3)
L_eff = 1./(omega_geo.^2*C_tgeo) % Equ. (4)
L_r = L_eff * L_c / (L_c - L_eff) % Equ. (5)
C_t = (omega_geo./omega).^2 * C_tgeo; % Equ. (6)
% Tuning capacitances C1 and C2 are given by Eqs. 7 and 8
C_1 = (omega*R_0).^(-1) .* sqrt((omega_geo./omega).^k_gamma * (R_0/R_geo) + omega.^2.*C_t.^2*R_0*R_geo.*(omega/omega_geo).^k_gamma - 1); % Equ. (7)
C_2 = ((omega.^2.*C_t)./((omega_geo./omega).^(2*k_gamma) .* (1/R_geo)^2 + (omega.*C_t).^2) - (omega.^2*R_0^2.*C_1)./(1+(omega*R_0.*C_1).^2)).^(-1); % Equ. (8)
C_1_geo = (omega_geo*R_0).^(-1) .* sqrt((omega_geo./omega_geo).^k_gamma * (R_0/R_geo) + omega_geo.^2.*C_tgeo.^2*R_0*R_geo.*(omega_geo/omega_geo).^k_gamma - 1) % Equ. (7)
C_2_geo = ((omega_geo.^2.*C_tgeo)./((omega_geo./omega_geo).^(2*k_gamma) .* (1/R_geo)^2 + (omega_geo.*C_tgeo).^2) - (omega_geo.^2*R_0^2.*C_1_geo)./(1+(omega_geo*R_0.*C_1_geo).^2)).^(-1) % Equ. (8)
subplot (2,1,1)
plot(f_Hz*1e-6, C_1*1e12); grid; xlabel("f/MHz"), ylabel("C_1 [pF]");
subplot (2,1,2)
plot(f_Hz*1e-6, C_2*1e12); grid; xlabel("f/MHz"), ylabel("C_2 [pF]");
% Design II.
L_c = R_geo/omega_geo; % Equ. (9)
L_eff = R_geo./(pi*sqrt(2)*B_geo_Hz); % Equ. (10)
L_r = L_eff - L_c; % Equ. (11)
C_tgeo = 1./(L_eff*omega_geo^2); % Equ. (12)
C_t = (omega_geo./omega).^2 * C_tgeo; % Equ. (13)
a = -omega.^2*R_0.*R_t; % Equ. (14)
b = 1./C_t; % ...
d = R_t/R_0; % Equ. (14)
alpha = (d-b.^2/a)./(1+b.^2/a - d); % Equ. (15)
beta = (b./a)./(1 + b.^2/a - d); % Equ. (16)
C_2 = alpha.*C_1 + beta; % Equ. (17)
function print_parameters(params)
align = 32;
names = fieldnames(params);
for n=1:length(names),
fprintf('%s', names{n});
remain = align - length(names{n});
if remain < 0
error('Invalid variable length!');
else
for j=1:remain
fprintf(' ');
end
fprintf('= %g %s\n', params.(names{n}), units.(names{n}));
end
end
endfunction
endfunction