Accueil > Unclassified > LC filter and oscillator
Unclassified

LC filter and oscillator

1. LC bandpass filter

1.a. Study tour

To obtain the Bode diagram of the frequency response, the LC filter is connected to the SysamSP5 analog / digital converter.

LC bandpass filter

The values used are R = 1.0kΩ, C = 1.0μF and L = 47mH.

1.b. Acquisition program

The Eurosmart SysamSP5 converter is controlled with the pycan module.

import pycan.main as pycan 
import numpy
import math
import time
                

The following function performs the analysis of the filter at a given frequency, for a chosen amplitude of the input sine wave. It returns the gain in decibels, the cosine of the phase shift and the phase shift.

def analyser(sys,f,a):
    print("Frequence = %f"%f)
    ne = 50
    T=1.0/f
    te=T/ne
    v1 = numpy.zeros(ne,numpy.double)
    for k in range(ne):
        phi = 2*math.pi/ne*k
        v1[k] = a*math.sin(phi)
    sys.config_sortie(1,te*10**6,v1,-1)
    sys.config_entrees([0,1],[10.0,10.0])
    np=100 # nombre de périodes de l'acquisition
    nea = ne*np
    duree = nea*te
    sys.config_echantillon(te*10**6,nea)
    sys.declencher_sorties(1,0)
    time.sleep(1) # régime transitoire
    sys.acquerir() # première acquisition pour connaitre l'amplitude de la sortie
    sys.stopper_sorties(1,0)
    t=sys.temps()
    u=sys.entrees()
    max1 = u[1].max()
    sys.config_entrees([0,1],[10.0,max1]) # ajustement du gain pour la sortie
    sys.config_echantillon(te*10**6,nea)
    sys.declencher_sorties(1,0)
    time.sleep(1) # régime transitoire
    sys.acquerir()
    sys.stopper_sorties(1,0)
    t=sys.temps()
    u=sys.entrees()
    mu0 = numpy.mean(u[0])
    mu1 = numpy.mean(u[1])
    rms0 = numpy.std(u[0])
    rms1 = numpy.std(u[1])
    g = rms1/rms0
    gdb = 20.0*math.log10(g)
    print("GdB = %f"%(gdb))
    cosphi = numpy.mean((u[0]-mu0)*(u[1]-mu1))/(rms0*rms1)
    print("cosphi = %f"%cosphi)
    phi = math.acos(cosphi)*180.0/math.pi
    print("phi = %f deg"%phi)
    return gdb,cosphi,phi
                

We open the interface with the SysamSP5, we generate the table of frequencies and we carry out the calculation loop. The results are saved in a file.

sys = pycan.Sysam("SP5")
freq = numpy.logspace(start=2,stop=4,num=80)
gdb = numpy.zeros(freq.size,dtype=numpy.float32)
cosphi = numpy.zeros(freq.size,dtype=numpy.float32)
phi = numpy.zeros(freq.size,dtype=numpy.float32)
amplitude = 1.0 # à choisir en fonction du filtre, pour ne pas dépasser 10 V en sortie
for k in range(freq.size):
    gdb[k],cosphi[k],phi[k] = analyser(sys,freq[k],amplitude)   
sys.fermer()
numpy.savetxt("filtrePasseBande.txt",[freq,gdb,cosphi])
                

1.c. Bode diagram

The experimental points are represented in the form of a Bode diagram for the gain in decibels and the cosine of the phase shift. A transfer function is defined by adding an internal resistance r to the inductor. The parameters L, C and r are adjusted to obtain the superposition of the curves with the experimental points.

import numpy as np
import math
import matplotlib.pyplot as plt
import cmath

[freq,gdb,cosphi] =np.loadtxt("filtrePasseBande.txt") R=1000 C=0.98e-6 L=44e-3 r=30 def H(f): # fonction de transfert du filtre     w=2*math.pi*f     z=1.0/(1.0/(1j*L*w+r)+1j*C*w)     return z/(R+z) def GdB(f):     return 20*np.log10(np.absolute(H(f))) def CosPhi(f):     return math.cos(cmath.phase(H(f))) ufunc_cosphi = np.frompyfunc(CosPhi,1,1) freq_theo = np.logspace(start=2,stop=4,num=1000) gdb_theo = GdB(freq_theo) cosphi_theo = ufunc_cosphi(freq_theo) plt.figure() plt.semilogx(freq,gdb,'ro') plt.semilogx(freq_theo,gdb_theo) plt.xlabel("f (Hz)") plt.ylabel("G") plt.figure() plt.semilogx(freq,cosphi,'ro') plt.semilogx(freq_theo,cosphi_theo) plt.xlabel("f (Hz)") plt.ylabel("cos(phi)") plt.show()                 
GdB
Bode diagram
phase
Bode diagram

2. LC Oscillator

2.a. Study tour

The oscillator is built from the previous filter. For this, the output of the filter is amplified to be applied to the input. The gain of the amplifier must compensate for the maximum gain of the filter, ie -4 dB. It must therefore have a gain G = 1.6 approximately. A potentiometer allows fine adjustment of the gain.

LC Oscillator

2.b. Analysis program

The program acquires the input (channel EA0) and the output (channel EA1) of the filter. Spectral analysis of the output is performed.

import pycan.main as pycan
import numpy
import math
import time
import matplotlib.pyplot as plt
import numpy.fft

sys = pycan.Sysam("SP5")
te=10.0e-6
ne=100000
duree=te*ne
sys.config_entrees([0,1],[10.0,10.0])
sys.config_echantillon(te*1e6,ne)
sys.acquerir()
t=sys.temps()
u=sys.entrees()
sys.fermer()
tfd=numpy.fft.fft(u[1])
f=numpy.arange(tfd.size)
for k in range(f.size):
    f[k] = 1.0*k/duree
spectre=20*numpy.log10(numpy.absolute(tfd))
plt.figure()
plt.plot(t[0],u[0],label="EA0")
plt.plot(t[1],u[1],label="EA1")
plt.xlabel("t (s)")
plt.ylabel("u (V)")
plt.axis([0,0.01,-10.0,10.0])
plt.grid()
plt.legend()
plt.figure()
plt.plot(f,spectre)
plt.axis([0,10000.0,0,numpy.amax(spectre)])
plt.grid()
plt.xlabel("f (Hz)")
plt.ylabel("A")
plt.show()
                

2.c. Oscillations analysis

In the first example, the gain of the amplifier is adjusted to obtain sinusoidal oscillations at the output of the amplifier (at the input of the filter).

signal
Oscillations analysis
spectre
Oscillations analysis

The spectrum shows an almost harmonic oscillation. A third order harmonic with an amplitude -60 dB is observed with respect to the fundamental.

In the second example, the gain is adjusted to obtain saturation at the output of the amplifier.

signal
Oscillations analysis
spectre
Oscillations analysis

This setting has the advantage of being more stable than the previous one. The relatively high quality factor of the filter (around 4.5) enables an almost sinusoidal oscillation to be obtained at the output of the filter, with a distortion rate of less than -50 dB.

It may interest you

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve : *
26 × 26 =