Code covered by the BSD License

# CircuitTool (a Test and Measurement Demo)

07 Sep 2004 (Updated )

A demonstration test and measurement application with system identification.

circuit_idsp(output,input,Ts);
```function [T_measured,T_predicted,F,sys] = circuit_idsp(output,input,Ts);
% CIRCUIT_IDSP Perform system identification from circuit time series response
% Uses signal processing toolbox, not sys-id.
%
% [T_measured,T_predicted,F] = CIRCUIT_IDSP(OUTPUT,INPUT,TS)%%

% Copyright 2003-2004 The MathWorks, Inc

%% Analyze system data
NFFT = 2^11;
Fs = 1/Ts;
[Txy,F] = tfe(input,output,NFFT,Fs,hanning(NFFT));
T_measured = abs(Txy);

%% Develop model
% Use INVFREQS to fit a first-order frequency response to the measured
% response

%%
% Compute model
n = 0;                  % Order of numerator
m = 1;                  % Order of denominator
w= 2*pi*F;              % Angular frequency
wt = ones(size(w));     % Weighting vector
wt(F>20000) = 0;        % Cut off above 20k

[b,a] = invfreqs(Txy,w,n,m,wt);
% H = freqs(b,a,2*pi*F);
% h = loglog(F,abs(H),'r');

%%
% Analyze model
% Compute cutoff frequency directly ...
K = b/a(2);         % Gain
wc = a(2)/a(1);     % Cutoff frequency

%% Simulate
sys = tf(b,a);

% Time-domain
% t = (0:1:length(Input)-1)*Ts;
% lsim(sys,Input,t)

% Frequency domain
H = freqresp(sys,w);
T_predicted = abs(squeeze(H));

```