Code covered by the BSD License  

Highlights from
res_meas

image thumbnail

res_meas

by

 

16 May 2007 (Updated )

GUI for resonator measurement and data download from Signal Analyzers and Oscilloscopes

res=feedthru(tot,cap)
function res=feedthru(tot,cap)
% RES = FEEDTHRU(TOT,CAP) calculates the "true" resonator response assuming
%  that the noise floor is due to a large capacitor in parallel with the
%  resonator (the "feedthrough capacitance", Cf).
%
% TOT, CAP and RES are resonator data structures as created by RES_MEAS.
%  TOT is the measured total response of the resonator (i.e., a typical
%  resonator measurement from the network analyzer). CAP is the capacitive
%  feedthrough (i.e., a measurement with bias = 0V). RES is the resulting
%  computed "true" resonator response with the capacitive feedback signal
%  subtracted.
%
% Requires: bandqr.m
%
% Example:
%
%  First, measure the resonator:
%
%  >> t = measure_res(tools,0,1000);
%
%  Next, measure the feedthrough capacitance (i.e., repeat the previous
%   measurement with the bias voltage set to 0 V):
%
%  >> c = measure_res(tools,t.mark1.x,1000);
%
%  Now, compute the resonator response with the feedthrough subtracted:
%
%  >> rc = feedthru(t,c);
% 
%
% M.A. Hopcroft
%      hopcroft at mems.stanford.edu
%
% MH MAR2007
% v1.2  fix units bug
%       add estimate of feedthrough capacitance value
%       copy all fields
% v1.12 convert source field

% MH FEB2007
% v1.1  update units field, use bandqr
% MH SEP2005
% v1.0

% imag
% real
% angle
% abs
% Z = R.*exp(i*theta)
% rad = deg*2*pi/360

% identify frequency axis- assume it is the same for both tot & cap
xfreq=tot.trace1.x;
% convert magnitude to linear units
tmag=10.^(tot.trace1.y./20);
cmag=10.^(cap.trace1.y./20);
% convert phase to radians
tphase=tot.trace2.y*2*pi/360;
cphase=cap.trace2.y*2*pi/360;
% convert to complex quantities
tcmx=tmag.*exp(i*tphase);
ccmx=cmag.*exp(i*cphase);
% subtract to get resonator response
rcmx=tcmx-ccmx;
% convert back to phasor
rmag=abs(rcmx);
rphase=angle(rcmx);
% convert to dB
rdb=20*log10(rmag);
% convert to degrees
rdeg=rphase*360/2/pi;


%% output a res structure
% first, copy the existing fields, then overwrite them
res = tot;
% overwrite with new values
res.trace1.x=xfreq';
res.trace1.y=rdb';
res.trace2.x=xfreq';
res.trace2.y=rdeg';
% set the marker values based on max amplitude
res.mark1.y=max(rdb);
% take the first peak (left) if there are multiple peaks
res.mark1.x=xfreq(find(rdb==res.mark1.y));
  res.mark1.x=res.mark1.x(1);
res.mark2.x=res.mark1.x;
res.mark2.y=rdeg(find(rdb==res.mark1.y));
  res.mark2.y=res.mark2.y(1);
% compute Q based on these markers
[res.bandwidth res.Q res.equ_circuit res.db res.phase_shift]=bandqr(res);
% bandqr estimates a value for feedthrough capacitance, but we can improve
%  on that estimate because we have a measurement of it, if the amplifier 
%  gain has been provided
if isfield(cap,'amp_gain')
    res.equ_circuit(2)=(10^(mean(cap.trace1.y)/20))/(2*pi*median(cap.trace1.x)*cap.amp_gain);
    res.amp_gain=cap.amp_gain;
end


% update old formats
if isfield(tot,'source')
    if isstruct(tot.source) && isfield(tot.source,'level') % old school
        res=rmfield(res,'source');
        res.source=tot.source.level;
    end
end
if isfield(tot,'V_bias')
    res=rmfield(res,'V_bias');
    res.Vbias_set=tot.V_bias;
end
if isfield(tot,'units1')
    res=rmfield(res,'units1');
	res.trace1.units=tot.units1;
end
if isfield(tot,'units2')
    res=rmfield(res,'units2');
	res.trace2.units=tot.units2;
end

return


Contact us