%%load the relevant circuit parameters

%LC
balun

m = zeros(N-1,N-1,Nvals);
Current_Source = [1,zeros(1,N-2)]'

mm = sum(y,1);

for ii = 1:N-1

      m(ii,ii,:) = mm(1,ii,:);

      for k = 1:N-1
            if  ii ~= k 
                 m(ii,k,:) = -y(k,ii,:);
            end
      end
end

Volts = zeros(N-1,Nvals);
for ii = 1:Nvals
       Volts(:,ii) = inv(m(:,:,ii))*Current_Source;
end

%Plot out the voltage at node 1. Since this is the node where 1 Ampere is injected, we are in effect calculating the input impedance...
figure(1)
subplot(2,1,1)
inode = 1
semilogx(frequency,real(Volts(inode,:)))
ylabel(['Real(Z) at node ',num2str(inode)])
axis([min(frequency) max(frequency) -20 100]);
subplot(2,1,2)

semilogx(frequency,imag(Volts(inode,:)))
ylabel(['Imag(Z) at node ',num2str(inode)])

figure(2)
Vout34 = Volts(3,:) - Volts(4,:);
Vout1   = Volts(1,:);

gain = abs(Vout34) ./ abs(Vout1);
gain = 20*log10(gain);

semilogx(frequency,gain, 'ko')
ylabel('dB')
axis([min(frequency) max(frequency) 0 10]);



shg

break
%%load the relevant circuit parameters
LC

m = zeros(N-1,N-1,Nvals);
Current_Source = [1,zeros(1,N-2)]'

mm = sum(y,1);

for ii = 1:N-1

      m(ii,ii,:) = mm(1,ii,:);

      for k = 1:N-1
            if  ii ~= k 
                 m(ii,k,:) = -y(k,ii,:);
            end
      end
end

Volts = zeros(N-1,Nvals);
for ii = 1:Nvals
       Volts(:,ii) = inv(m(:,:,ii))*Current_Source;
end

%Plot out the voltage at node 1. Since this is the node where 1 Ampere is injected, we are in effect calculating the input impedance...
subplot(2,1,1)
inode = 1
semilogx(frequency,real(Volts(inode,:)))
ylabel(['Real(Z) at node ',num2str(inode)])
axis([min(frequency) max(frequency) -20 100]);
subplot(2,1,2)

semilogx(frequency,imag(Volts(inode,:)))
ylabel(['Imag(Z) at node ',num2str(inode)])
shg

