# Class

# LCR in series



Resonating frequency
\begin{equation}
f_0=\frac{1}{2\pi\sqrt{LC}}
\end{equation}

Quality factor
\begin{equation}
Q=\frac{1}{R}\sqrt{\frac{L}{C}}
\end{equation}

Inductive reactance
\begin{equation}
X_L=2\pi fL
\end{equation}

Capacitive reactance
\begin{equation}
X_C=\frac{1}{2\pi fC}
\end{equation}

Impedance
\begin{equation}
z=\sqrt{(X_L-X_C)^2+R^2}
\end{equation}

Phase angle
\begin{equation}
\phi=\tan^{-1}(\frac{X_L-X_C}{R})
\end{equation}


```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
```


```python
class lcr():
    def __init__(self,L,C,R,f):
        self.L     = L
        self.C     = C
        self.R     = R
        self.f     = f
        
    def fo(self):
        fr=(2*np.pi*np.sqrt(self.L*self.C))**-1
        return fr
    
    def Q(self):
        ql=np.sqrt(self.L/self.C)/self.R
        return ql
    
    def inductiveReactance(self):
        XL=2*np.pi*self.L*self.f 
        return XL
    
    def capacitiveReactance(self):
        XC=1/(2*np.pi*self.C*self.f)
        return XC
    
    def impedance(self):
        imp=np.sqrt((self.inductiveReactance()-self.capacitiveReactance())**2+self.R**2)
        return imp
    
    def phase(self):
        pi=np.arctan((self.inductiveReactance()-self.capacitiveReactance())/self.R)*180/np.pi
        return pi    # degree
    
```


```python
l=0.1    #inductance in H
c=1e-6   #capacitance in F
r=10     # resistance in ohm
v=100    #voltage in V
```


```python
d=lcr(l,c,r,100)
print('Resonating frequency:',d.fo(),'Hz')
print('Q factor:',d.Q())
```

    Resonating frequency: 503.2921210448704 Hz
    Q factor: 31.622776601683796



```python
freq=np.arange(10,1500,10)
g=lcr(l,c,r,freq)
xl=g.inductiveReactance()
xc=g.capacitiveReactance()
z=g.impedance()
ph=g.phase()
I=v/z  # current
vr=I*r  #p.d.across reisitor
vl=I*xl  #p.d.across inductor
vc=I*xc  #p.d.across capacitor
power =v*I*np.cos(ph*np.pi/180)
```


```python
plt.plot(freq,xl,'m.',label='Inductive Reactance')
plt.plot(freq,xc,'c-.',label='Capacitive Reactance')
plt.xlabel(xlabel="Frequency(Hz)",fontsize=14,fontstyle='italic',color="black")
plt.ylabel(ylabel="Reactance(ohm)",fontsize=14,fontstyle='italic',color="black")
plt.title(label="LCR circuit",fontsize=20,fontweight='bold',color="red")
plt.legend()
plt.tight_layout()
plt.savefig("image\LCR1.pdf", dpi = 600) # dpi dot per inch
plt.show()
plt.close()
```


```python
plt.plot(freq,vr,'g-',label='p.d. across R')
plt.plot(freq,vl,'b-',label='p.d. across L')
plt.plot(freq,vc,'r-',label='p.d. across C')
plt.xlabel(xlabel="Frequency(Hz)",fontsize=14,fontstyle='italic',color="black")
plt.ylabel(ylabel="P.d.(V)",fontsize=14,fontstyle='italic',color="black")
plt.title(label="LCR circuit",fontsize=20,fontweight='bold',color="red")
plt.legend()
plt.tight_layout()
plt.savefig("image\LCR2.pdf", dpi = 600)
plt.show()
plt.close()
```


```python
plt.plot(freq,z,'m^')
plt.xlabel(xlabel="Frequency(Hz)",fontsize=14,fontstyle='italic',color="black")
plt.ylabel(ylabel="Impedance(ohm)",fontsize=14,fontstyle='italic',color="black")
plt.title(label="LCR circuit",fontsize=20,fontweight='bold',color="red")
plt.tight_layout()
plt.savefig("image\LCR3.pdf", dpi = 600)
plt.show()
plt.close()
```


```python
plt.plot(freq,I,'c*')
plt.xlabel(xlabel="Frequency(Hz)",fontsize=14,fontstyle='italic',color="black")
plt.ylabel(ylabel="Current(A)",fontsize=14,fontstyle='italic',color="black")
plt.title(label="LCR circuit",fontsize=20,fontweight='bold',color="red")
plt.tight_layout()
plt.savefig("image\LCR4.pdf", dpi = 600)
plt.show()
plt.close()
```


```python
plt.plot(freq,np.cos(ph*np.pi/180),'k+')
plt.xlabel(xlabel="Frequency(Hz)",fontsize=14,fontstyle='italic',color="black")
plt.ylabel(ylabel="power factor(unitless)",fontsize=14,fontstyle='italic',color="black")
plt.title(label="LCR circuit",fontsize=20,fontweight='bold',color="red")
plt.tight_layout()
plt.savefig("image\LCR7.pdf", dpi = 600)
plt.show()
plt.close()
```


```python
plt.plot(freq,ph,'k+')
plt.xlabel(xlabel="Frequency(Hz)",fontsize=14,fontstyle='italic',color="black")
plt.ylabel(ylabel="phase angle(degree)",fontsize=14,fontstyle='italic',color="black")
plt.title(label="LCR circuit",fontsize=20,fontweight='bold',color="red")
plt.tight_layout()
plt.savefig("image\LCR5.pdf", dpi = 600)
plt.show()
plt.close()
```


```python
plt.plot(freq,power,'yo')
plt.xlabel(xlabel="Frequency(Hz)",fontsize=14,fontstyle='italic',color="black")
plt.ylabel(ylabel="Power(W)",fontsize=14,fontstyle='italic',color="black")
plt.title(label="LCR circuit",fontsize=20,fontweight='bold',color="red")
plt.tight_layout()
plt.savefig("image\LCR6.pdf", dpi = 600)
plt.show()
plt.close()
```


```python
data={}
data.update({'Freqency':freq,'in.rect.':xl,'cap.Rect':xc,'imp.':z,'curren':I,'phase':ph,'power':power})
```


```python
DF = pd.DataFrame(data)
DF
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Freqency</th>
      <th>in.rect.</th>
      <th>cap.Rect</th>
      <th>imp.</th>
      <th>curren</th>
      <th>phase</th>
      <th>power</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>10</td>
      <td>6.283185</td>
      <td>15915.494309</td>
      <td>15909.214267</td>
      <td>0.006286</td>
      <td>-89.963986</td>
      <td>0.000395</td>
    </tr>
    <tr>
      <th>1</th>
      <td>20</td>
      <td>12.566371</td>
      <td>7957.747155</td>
      <td>7945.187077</td>
      <td>0.012586</td>
      <td>-89.927886</td>
      <td>0.001584</td>
    </tr>
    <tr>
      <th>2</th>
      <td>30</td>
      <td>18.849556</td>
      <td>5305.164770</td>
      <td>5286.324672</td>
      <td>0.018917</td>
      <td>-89.891615</td>
      <td>0.003578</td>
    </tr>
    <tr>
      <th>3</th>
      <td>40</td>
      <td>25.132741</td>
      <td>3978.873577</td>
      <td>3953.753482</td>
      <td>0.025292</td>
      <td>-89.855085</td>
      <td>0.006397</td>
    </tr>
    <tr>
      <th>4</th>
      <td>50</td>
      <td>31.415927</td>
      <td>3183.098862</td>
      <td>3151.698800</td>
      <td>0.031729</td>
      <td>-89.818206</td>
      <td>0.010067</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>144</th>
      <td>1450</td>
      <td>911.061870</td>
      <td>109.762030</td>
      <td>801.362236</td>
      <td>0.124788</td>
      <td>89.285002</td>
      <td>0.155719</td>
    </tr>
    <tr>
      <th>145</th>
      <td>1460</td>
      <td>917.345055</td>
      <td>109.010235</td>
      <td>808.396673</td>
      <td>0.123702</td>
      <td>89.291224</td>
      <td>0.153021</td>
    </tr>
    <tr>
      <th>146</th>
      <td>1470</td>
      <td>923.628240</td>
      <td>108.268669</td>
      <td>815.420892</td>
      <td>0.122636</td>
      <td>89.297330</td>
      <td>0.150396</td>
    </tr>
    <tr>
      <th>147</th>
      <td>1480</td>
      <td>929.911425</td>
      <td>107.537124</td>
      <td>822.435099</td>
      <td>0.121590</td>
      <td>89.303323</td>
      <td>0.147842</td>
    </tr>
    <tr>
      <th>148</th>
      <td>1490</td>
      <td>936.194611</td>
      <td>106.815398</td>
      <td>829.439497</td>
      <td>0.120563</td>
      <td>89.309206</td>
      <td>0.145355</td>
    </tr>
  </tbody>
</table>
<p>149 rows × 7 columns</p>
</div>




```python
DF.to_csv("data/lcr.csv")  #save data in csv format in excel
```


```python

```

d5c7b4a62d23d968c108a6e3d89ad51ef177faa9
ipynb
Jupyter Notebook
lcr.ipynb
AmbaPant/NPS
0500f39f6708388d5c3f2b8d3e5ee5e56a1f646f
MIT
2020-09-16T03:21:55.000Z
2020-09-16T03:21:55.000Z
lcr.ipynb
AmbaPant/NPS
0500f39f6708388d5c3f2b8d3e5ee5e56a1f646f
MIT
lcr.ipynb
AmbaPant/NPS
0500f39f6708388d5c3f2b8d3e5ee5e56a1f646f
MIT
2020-08-10T12:17:21.000Z
2020-09-13T14:31:02.000Z
Qwen/Qwen-72B
1. YES
2. YES