Resonance Matlab Script
Resonance Matlab Script
C = 0.002e-6;
R = 330;
V = 5;
clc;
fr = 1/(2*pi*sqrt(L*C));
f = 100:10:fr*3;
xl = 2*pi*f*L;
xc = 1./(2*pi*f*C);
q = (1/R)*sqrt(L/C);
fr = 1/(2*pi*sqrt(L*C));
z = sqrt((R^2)+ (xl - xc).^2);
i = V./z;
ph = atan((xl-xc)/R);
%====================================================================
figure(1); clf; hold off
plot(f, R*i,'color','blue');
hold on
plot(f,xl.*i,'color','red');
plot(f,xc.*i,'color',[1,0.5,0]);
set(gca,'Color',[1 0.78 0.80]);
%====================================================================
text(3*fr/4,max(xc.*i)+ max(xc.*i)*0.1,['fr = ' num2str(fr)]);
text(3*2*fr/4,max(xc.*i)+ max(xc.*i)*0.1,['i(max) = ' num2str(max(i))]);
text(3*3*fr/4,max(xc.*i)+ max(xc.*i)*0.1,['Q = ' num2str(q)]);
xlim([0 fr*3]);
%===================================================================
figure(2)
plot(f,ph*180/pi,'color','black'); %phase
xlim([0 fr*3]);
set(gca,'Color',[1 0.78 0.80]);