In this post, we introduce frequency responses of linear systems and provide a brief introduction to Fourier series. Most importantly, we perform a real physical experiment of observing a frequency response of a resistor-capacitor (RC) circuit. A video about this post is given below. A YouTube video accompanying this post is given below. The video contains the frequency response measurement experiment.
Fourier Series
First, we provide a brief introduction to Fourier Series. Mr. Fourier, who was a French mathematician, claimed that any periodic function (even a periodic function with square corners!) can be used to be mathematically expressed as a sum of sinusoids! Sounds truly amazing.
So, let be a periodic function with the period of
. According to Fourier, we can represent this function as follows
(1)
where
![Rendered by QuickLaTeX.com \omega_{0}= 2\pi /T](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-acd44332d4a884b2b1a60bc9a746b196_l3.png)
![Rendered by QuickLaTeX.com c_{m} \in \mathbb{C}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-40f36bdba5eafc19348c1043370422ca_l3.png)
![Rendered by QuickLaTeX.com j](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-43c82d5bb00a7568d935a12e3bd969dd_l3.png)
![Rendered by QuickLaTeX.com f(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-59d54ba73238a26eb8acae54cb83607e_l3.png)
(2)
Let us determine the Fouries series expansion for a periodic function shown in figure below.
![](https://aleksandarhaber.com/wp-content/uploads/2019/08/periodic_function-1024x512.jpg)
The period of this function is . This is a square wave function ( or a periodic pulse function) that is often encountered in signal analysis and control engineering. In its period
This function can be formally expressed as follows:
(3)
where
![Rendered by QuickLaTeX.com A](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-25b206f25506e6d6f46be832f7119ffa_l3.png)
So let us apply the formula \eqref{fouriesCoefficients}
(4)
Next, we use the following trigonometric identities:
(5)
By using these identities in the previous expression, we obtain
(6)
Next, by using the Euler’s formula:
![Rendered by QuickLaTeX.com e^{xj}=cos(x)+jsin(x)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-d02c13edb4247c0d3faffa6800d07f05_l3.png)
(7)
Now, we have to resolve possible indeterminate cases (when ). We notice that for
,
takes the form of
. We can write:
(8)
where we used L’Hôpital’s rule to compute the limit (we can also use the limit of
![Rendered by QuickLaTeX.com sin(x)/x](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-15e5bd68a9597d17fb60f11c0aeeb37e_l3.png)
(9)
By substituting the Euler’s formula, and by substituting the last expression as well as the expression for
![Rendered by QuickLaTeX.com c_{0}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-3270d6445df765705e9b6427770645ae_l3.png)
(10)
The following figure demonstrates the performance of the Fourier series expansion.
![](https://aleksandarhaber.com/wp-content/uploads/2019/08/fourier_expression2-356x1024.jpg)
# -*- coding: utf-8 -*-
"""
Fourier series expansion - analytical
"""
import numpy as np
import matplotlib.pyplot as plt
import math
A=1
T=2
x=np.arange(-T,2*T,0.01)
y=np.zeros(shape=(x.shape[0],))
for i in range(x.shape[0]):
if (x[i]<(-T/2)) or ((x[i]>0) and (x[i]<T/2)) or ((x[i]>T) and (x[i]<3*T/2)):
y[i]=1
fig= plt.figure(figsize=(8,4))
plt.xlim(-2.5, 4.5)
plt.ylim(-0.2, 1.2)
plt.axis('equal')
plt.ylabel('f(t)')
plt.xlabel('time - t')
plt.plot(x,y,'b', linewidth=2.5, label='Periodic function')
plt.savefig('periodic_fuction.eps')
k_max=100
w0=2*math.pi/T
yapprox=[]
for i in range(x.shape[0]):
sum=0
for k in np.arange(1,k_max+1):
sum=sum+A*((math.sin(k*math.pi/2))/(k*math.pi/2))*math.cos(k*w0*x[i]-k*math.pi/2)
yapprox.append(sum+0.5*A)
fig= plt.figure(figsize=(8,4))
plt.xlim(-2.5, 4.5)
plt.ylim(-0.2, 1.2)
plt.axis('equal')
plt.ylabel('f(t)')
plt.xlabel('time - t')
plt.plot(x,y,'b', linewidth=2.5, label='Periodic function')
plt.plot(x,yapprox,'r', linewidth=2.5, label='Fourier series approximation')
plt.legend()
plt.savefig('approximationk_100.eps')
Frequency Response
Consider a linear dynamical system S shown in Fig. 1.
![](https://aleksandarhaber.com/wp-content/uploads/2019/07/diagram1-1024x368.jpg)
The system input is denoted by and the system output is
. The input is an external signal affecting the system dynamics, and the output is a signal that we usually observe and whose dynamical behavior is of interest to us.
There are several ways of mathematically describing the relationship between the inputs and outputs. We can use differential equations to relate inputs and outputs. Differential equations can be used to argue about system stability and by solving them we can compute the system output for a given input. However, in many situations, we would like to have a simpler representation of the system behavior, that can be more useful from an engineering standpoint.
Frequency response is such a system representation. First, we will motivate the need for frequency response functions.
We know that (almost) every (periodic) function can be represented as a sum of harmonic functions (sin() and cos() functions). This follows from the Fourier series expansion. For example, consider a periodic ramp function:
(11)
and where the period is
![Rendered by QuickLaTeX.com 2\pi](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-5bfa2124624f767670227d1aeab8d85c_l3.png)
(12)
Motivated by this, let us write the input function
![Rendered by QuickLaTeX.com u(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-58d0c0135c4411d75d00353f169797fc_l3.png)
(13)
where
![Rendered by QuickLaTeX.com \omega_{i}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-972eb00d0e0d15617ac24b15e717192c_l3.png)
![Rendered by QuickLaTeX.com a_{i}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-6a400497127dbe770ca279531e110c74_l3.png)
![Rendered by QuickLaTeX.com u(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-58d0c0135c4411d75d00353f169797fc_l3.png)
(14)
where
![Rendered by QuickLaTeX.com y_{i}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-439a852f120600201dba9816b5c33dae_l3.png)
![Rendered by QuickLaTeX.com \cos(\omega_{i} t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-e277f6ea5277ce6f33d30fbe0c166de2_l3.png)
This motivates us to consider the following problem. What is the system response when the input function is
![Rendered by QuickLaTeX.com \cos(\omega t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-1ec1a04d82358f18332993f1cf8e38fc_l3.png)
First of all, we know that the system response can be computed as a convolution of an impulse response and the input:
(15)
where
![Rendered by QuickLaTeX.com h(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-e5f085081671bb76fc2d617c2a65b6d3_l3.png)
![Rendered by QuickLaTeX.com \delta (t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-aa5648ac2c3f578c75945a9a24238d5a_l3.png)
(16)
where
![Rendered by QuickLaTeX.com s](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-ae1901659f469e6be883797bfd30f4f8_l3.png)
(17)
where the term
(18)
is the system transfer function. Notice that the system transfter function is the Laplace transformation of the impulse response function. Let us now use \eqref{transfer1} to compute the system response to a cos() function. Using the Euler’s relation, we can write:
(19)
where
![Rendered by QuickLaTeX.com j](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-43c82d5bb00a7568d935a12e3bd969dd_l3.png)
(20)
Since the system is linear, the reponse to the input
![Rendered by QuickLaTeX.com u(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-58d0c0135c4411d75d00353f169797fc_l3.png)
![Rendered by QuickLaTeX.com u_{1}(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-8923f390a17b75f4037422041f1094b6_l3.png)
![Rendered by QuickLaTeX.com u_{2}(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-1f2b2e6a1868587e4a0c5729bc45fe32_l3.png)
![Rendered by QuickLaTeX.com u_{1}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-c1d3d34805a28055f7c2013d795ff074_l3.png)
![Rendered by QuickLaTeX.com s=j\omega](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-d2211b4d6e6d68b5daef7bbe1ef51138_l3.png)
(21)
On the other hand,
![Rendered by QuickLaTeX.com H(j\omega)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-9fc7d1cd34b3a73c139bfc8ed4079517_l3.png)
![Rendered by QuickLaTeX.com H(j\omega)= M(\omega)e^{j \phi (\omega)}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-46718191dacb767ebe63c0d25f61ded7_l3.png)
![Rendered by QuickLaTeX.com M(\omega)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-72fd8af7c93f57fe78a5457cc7acbdb6_l3.png)
![Rendered by QuickLaTeX.com \phi (\omega)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-993ac68fd0893b818508df5c13bd4ead_l3.png)
(22)
For
![Rendered by QuickLaTeX.com u_{2}(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-1f2b2e6a1868587e4a0c5729bc45fe32_l3.png)
(23)
Since
![Rendered by QuickLaTeX.com H(-j\omega) =M(\omega)e^{-j\phi(\omega)}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-9f123f587fb95393c57b8eec931653e2_l3.png)
(24)
Finally, we have:
(25)
From the Euler’s relation, it follows that the second term in the last expression is equal to
![Rendered by QuickLaTeX.com \cos(\omega t+\phi(\omega))](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-ec9ab941be34631e78180bd3e302394e_l3.png)
(26)
To conclude, if the system input is
![Rendered by QuickLaTeX.com A_{u}\cos(\omega t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-cbef1ecc4536cb91f2f28fe83e9cb06c_l3.png)
![Rendered by QuickLaTeX.com M(\omega) A_{u} \cos(\omega t+\phi(\omega))](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-decc1e6ebdd5956a389e6acf5964918e_l3.png)
The frequency response is characterized by the following two functions:
(27)
The first one in \eqref{frequencyResponse1} is the magnitude response. It tells us the amplification of the amplitude of the input signal. The second one in \eqref{frequencyResponse2} is the phase response. The phase response gives us information about the delay of the output signal with respect to the input signal.
In the sequel, we derive a frequency response of an RC circuit, and we present experimental results of observing the response for several frequency values. The RC circuit is shown in Fig. 2.
![](https://aleksandarhaber.com/wp-content/uploads/2019/07/RC-1024x546.jpg)
A differential equation describing the relation between the input () and output (
) voltages is
(28)
where
![Rendered by QuickLaTeX.com T=RC](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-7ce6ec92e1b4f5602534bf6f00c84c7e_l3.png)
(29)
where
![Rendered by QuickLaTeX.com V_{o}(s)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-17c712fb7869dba146a6e9fadc50cdc2_l3.png)
![Rendered by QuickLaTeX.com V_{s}(s)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-737faae35b8808b33e5b0f828b9b3321_l3.png)
![Rendered by QuickLaTeX.com V_{o}(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-cd642d03b6997e4e75b680e4abbd8af4_l3.png)
![Rendered by QuickLaTeX.com V_{i}(t)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-2d8fec674c85622969d9c5d5b32e1145_l3.png)
![Rendered by QuickLaTeX.com V_{0}(0)](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-83e9e9ff2e8f29a458494569743b62ea_l3.png)
(30)
(31)
From the last equation we conclude:
(32)
Next, we simulate the frequency response. The Python code is given below:
<pre class="wp-block-syntaxhighlighter-code">import numpy as np
import matplotlib.pyplot as plt
R=550
C=100*10**(-9)
T=R*C
w=0.5*np.arange(1000000)
M=(np.sqrt(1+(T*w)**(2)))**(-1)
phi=-np.arctan(T*w)*(180/np.pi)
plt.plot(w,M)
plt.title('Magnitude response')
plt.xlabel('<img src="https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-707fcec15e450815730425a6607a1858_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="\omega" title="Rendered by QuickLaTeX.com" height="8" width="11" style="vertical-align: 0px;"/>')
plt.ylabel('M(<img src="https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-707fcec15e450815730425a6607a1858_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="\omega" title="Rendered by QuickLaTeX.com" height="8" width="11" style="vertical-align: 0px;"/>)')
plt.savefig('magnitude.eps')
plt.show()
plt.plot(w, phi)
plt.title('Phase response')
plt.xlabel('<img src="https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-707fcec15e450815730425a6607a1858_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="\omega" title="Rendered by QuickLaTeX.com" height="8" width="11" style="vertical-align: 0px;"/>')
plt.ylabel('<img src="https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-5b2be26c0c1341f54b29baddda771346_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="\phi" title="Rendered by QuickLaTeX.com" height="16" width="11" style="vertical-align: -4px;"/>(<img src="https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-707fcec15e450815730425a6607a1858_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="\omega" title="Rendered by QuickLaTeX.com" height="8" width="11" style="vertical-align: 0px;"/>) [deg]')
plt.savefig('phase.eps')
plt.show()</pre>
Here are the magnitude and phase responses plots:
![](https://aleksandarhaber.com/wp-content/uploads/2019/07/magnitude-1024x683.jpg)
![](https://aleksandarhaber.com/wp-content/uploads/2019/07/phase-1024x683.jpg)
Another important concept we need to introduce is the concept of the cutoff frequency. The cutoff frequency is usually defined as the frequency at which the magnitude response is equal to
. That is, at this frequency the amplitude of the output signal is
times the amplitude of the input signal. Let us see what is the cutoff frequency of the RC circuit. We have
(33)
From here, we have:
(34)
The experimental results of measuring certain points of an RC circuit are given in the Figure below. The results are generated for and
.
![](https://aleksandarhaber.com/wp-content/uploads/2019/08/magnitude1-1024x683.jpg)
The code for generating these plots is given below and for more details see the video.
<pre class="wp-block-syntaxhighlighter-code">import numpy as np
import matplotlib.pyplot as plt
import math
R=330
C=484*10**(-9)
T=R*C
freq_theoretical=1*np.arange(1500)
M=1/(np.sqrt(1+(T*(2*np.pi*freq_theoretical))**(2)))
phi=-np.arctan(T*(2*np.pi*freq_theoretical))*(180/np.pi)
cutoff=1/(R*C*2*math.pi)
frequency = np.array([195, 399, 590, 804, 992, 1196])
vout_max = np.array([4.56, 4.24, 3.8, 3.36, 3.04, 2.72])
vin_max = np.array([4.56, 4.48, 4.40, 4.24, 4.24, 4.16])
M_measured= vout_max/vin_max
plt.plot(freq_theoretical,M,label='theoretical')
plt.plot(frequency,M_measured,'rx',markersize=10,label='experimental')
plt.title('Magnitude response')
plt.xlabel('frequency [Hz]')
plt.ylabel('M(<img src="https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-707fcec15e450815730425a6607a1858_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="\omega" title="Rendered by QuickLaTeX.com" height="8" width="11" style="vertical-align: 0px;"/>)')
plt.legend()
plt.savefig('magnitude1.eps')
plt.show()
</pre>