Signal Representation
Signal Representation
2 Wave Representation
Waves exhibit various properties that describe their behavior and characteristics. Here are some
fundamental wave properties:
1. Amplitude
• Definition: The maximum displacement or distance moved by a point on a vibrating
body or wave measured from its equilibrium or rest position.
• Significance: Amplitude determines the intensity or loudness of a wave in the case of
sound waves and the brightness of light waves.
2. Frequency
• Definition: The number of oscillations or cycles of a wave that occur in one second.
• Significance: Frequency is inversely related to the wavelength. It determines the pitch
of sound waves and the color of light waves.
3. Wavelength
• Definition: The distance between two successive points that are in phase in a wave.
• Significance: Wavelength is inversely related to frequency. It defines the spatial extent
of a wave and is used to classify different types of waves.
4. Speed
• Definition: The rate at which a wave travels through space or a medium.
• Significance: The speed of a wave is the product of its frequency and wavelength. It
determines how quickly a disturbance is transmitted through a medium.
5. Phase
• Definition: Describes the position of a point in a wave cycle relative to a reference point.
• Significance: Phase is important in understanding interference and the behavior of waves
when they encounter each other.
6. Period
• Definition: The time taken for one complete cycle of a wave to pass a given point.
• Significance: It is the reciprocal of frequency, and the two are inversely proportional.
1
3 Frist you need to import Python packages you’ll use
Anyone who has used any programming language knows that sometimes there is a need for third-
party packages. In Python, we use many packages to perform various tasks. For example, the
Numpy package is for the calculation of any kind of numerical operatio n. Therefore, we use Numpy
to multiply, divide, power. In addition, Matplotlib package is used for data representation, such as
curve of motion as a function of time.
In this notebook we will represent a signal with the help of a software such as Python. In order to
do so, we need some requirements: 1. Select the wave function. We will choose a sine function. 2.
Define the parameters of the wave: amplitude, frequency, phase. 3. Define a time vector
Let’s start by saying that our function is a sine function. We want to evaluate the function from 0
to 1 seconds, so we define the time vector.
To define the vector, we use the Numpy package by calling it with np.
[8]: array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])
As you can see, we use Numpy’s linspace function by typing the command t = np.linspace(0,
1, 11). Where 0 is the start point, 1 is the end point, and 11 is the number of elements in the
array. so the array t has 11 elements.
Now that we have the time vector, we can evaluate the sine function. First, we need to define some
parameters such as frequency and phase.
[9]: # Frencuency
f = 1 #1 Hz
ph = 0 #rads
Now we will evaluate the sine function using the defined parameters. As before, we use Numpy to
call the sine function from this package.
Note that 2 ∗ 𝜋 ∗ 𝑓 is the angular frequency 𝜔 in (rads/s). That’s it, the sine function is evaluated
based on the parameters. As expected, the result vector y must have the same amount of t, since
we are using the time vector for the evaluation. You can type y at the end of a cell to print the
result like this
[11]: y1
2
-9.51056516e-01, -5.87785252e-01, -2.44929360e-16])
[12]: print(y1)
print(y1.shape)
print(y1.shape[0])
11
(11,)
11
Okay. We can plot the sine function as a function of time. To do this, we will use the plot function
from the Matplotlib package. The keyword plt is used to invoke the Matplotlib package, so we can
use its functions. The step to plot the results are the folowing: 1. create a figure object 2. create
a plot within the figure 3. define the x and y labels. The following are very optional 4. define the
legend position 5. define the margin step width 6. activate the grid in the image 7. define the axis
min and max limits
[14]: dt = 0.1
#1
plt.figure(1)
#2
plt.plot(t,y1, label='y = sin(2$\pi$f t + $\phi$)')
#3
plt.xlabel('tiempo (s)')
plt.ylabel('y(t)')
#4
plt.legend(loc=0)
#5
plt.margins(dt)
#6
plt.grid()
#7
plt.axis([0, 1, -2, 2])
3
Simple as that. Now we have plotted the sine as a function of time.
Let us do some analysis from this figure: 1. the amplitude of the signal is 1 (A or V, m; depends
on the quantity being measured) 2. The frequency of the signal is 1 Hz. This means that the signal
repeats once per second. 3. the period of the signal is 1 s. It means it takes 1 second for the signal
to complete one cycle. 4. the phase of the signal is 0 rad 5. the angular frequency of the signal is
2𝜋 rad. Remember 𝜔 = 2𝜋𝑓
Now we are going to make some changes to the signal parameters as follows: 1. frequency 𝑓 = 2
Hz 2. amplitude $A = 2.5 $ (V, assuming we are measuring voltage)
Accordingly, the period of the signal must change. Let’s see
[15]: # f equals to 5 Hz
f = 2
# Amplitud equals to 2.5 V
A = 2.5
# sine function
y2 = A*np.sin(2*np.pi*f*t + ph)
4
#1
plt.figure(2)
#2
plt.plot(t,y2, label='y = sin(2$\pi$f t + $\phi$)')
#3
plt.xlabel('tiempo (s)')
plt.ylabel('y(t)')
#4
plt.legend(loc=0)
#5
plt.margins(dt)
#6
plt.grid()
#7
plt.axis([0, 1, -2.5, 2.5])
As expected, the singnal repets twice in a second because the frequency is 2 Hz. Therefore, it
means that the period of the signal is $1/f = 0.5 $ sec. In other words, faster the variation of the
signal (frequency) as a function of time, less the time it take to complete a cycle (period).
5
On the other hand, there seems to be something strange in the sine curve compared to the one at
the beginning of this notebook. The result does not show a smooth variation, but strong edges as
time passes. In other words, the result does not fit the shape of an actual sine function. did you
wonder what is going on?
It has to do with the time we use to sample the signal. It is called the sampling frequency.
The sampling frequency 𝐹𝑠 is defined as the number of samples of a signal taken per second during
the analog-to-digital conversion process.
In this case, the signal representation takes 1 second and during this time we take 11 samples {0,
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}. This means that the sampling time 𝑇𝑠 = 1/𝐹𝑠 is equal
to 0.1 sec. Therefore, the sampling frequency is 𝐹𝑠 = 1/𝑇𝑠 = 10.
# Time Vectors
t1 = np.arange(0, 1,dt1)
t2 = np.arange(0, 1,dt2)
y1 = A*np.sin(2*np.pi*f*t1 + ph)
y2 = A*np.sin(2*np.pi*f*t2 + ph)
length t1 10
length t2 100
Now, lets plotting…
6
[17]: #1
plt.figure(3)
#2
plt.plot(t1,y1, label='y1 = sin(2$\pi$f t + $\phi$), $F_s = 10$')
plt.plot(t2,y2, label='y2 = sin(2$\pi$f t + $\phi$), $F_s = 100$')
#3
plt.xlabel('tiempo (s)')
plt.ylabel('y(t)')
#4
plt.legend(loc=0)
#5
plt.margins(dt)
#6
plt.grid()
#7
plt.axis([0, 1, -2.5, 2.5])
You see! The results show two representations of the same signal, but with different sampling
7
frequencies. Clearly, y2 is more likely to be a sine function.
Now let us make some phase changes in y2. Let’s add a phase shift of 1/4𝑝𝑖 and see what happens.
plt.figure(4)
#2
plt.plot(t1,y1, label='y1 = sin(2$\pi$f t + $\phi$), $F_s = 10$')
plt.plot(t2,y2, label='y2 = sin(2$\pi$f t + $4/\pi$), $F_s = 100$')
#3
plt.xlabel('tiempo (s)')
plt.ylabel('y(t)')
#4
plt.legend(loc=0)
#5
plt.margins(dt)
#6
plt.grid()
#7
plt.axis([0, 1, -2.5, 2.5])
8
Now let’s add a phase shift of −1/4𝑝𝑖 and see what happends
plt.figure(4)
#2
plt.plot(t1,y1, label='y1 = sin(2$\pi$f t + $\phi$), $F_s = 10$')
plt.plot(t2,y2, label='y2 = sin(2$\pi$f t + $4/\pi$), $F_s = 100$')
plt.plot(t2,y3, label='y2 = sin(2$\pi$f t - $4/\pi$), $F_s = 100$')
#3
plt.xlabel('tiempo (s)')
plt.ylabel('y(t)')
#4
plt.legend(loc=0)
#5
plt.margins(dt)
9
#6
plt.grid()
#7
plt.axis([0, 1, -2.5, 2.5])
What we have done is a phase shift. It is the amount by which one waveform is shifted in time
with respect to another waveform. In this case, y2 was shifted 𝜋/4 rads, while y3 was shifted −𝜋/4
rads with respect to y1.
The following examples uses NumPy and Matplotlib to generate and plot two cosine waveforms.
The script defines a function s1 to generate a cosine waveform with specified frequency (f) and
amplitude (A). Then, it creates two waveforms (x1 and x2) using this function and plots them
using Matplotlib.
10
b = 2*np.pi # Final time
dt = 0.01 # Time sampling interval
t = np.arange(a, b, dt) # Time vector
# Plotting
plt.figure(1)
plt.plot(t,x1, label='x1 = Acos(2$\pi$f t)')
plt.plot(t,x2, label='x2 = 2Acos(2$\pi$2f t)') # esto es para graficar la␣
↪nueva función
plt.xlabel('tiempo (s)')
plt.ylabel('x(t)')
plt.legend(loc=0)
plt.margins(dt)
plt.grid()
plt.axis([0, 1, -2, 2])
11
Again, we have a x2 undersampled signal. Let us check the sampling frequency:
[21]: fs = 1/dt
fs
[21]: 100.0
Considering the above, let’s change the sampling frequency of the signals and look at the results.
Note that it is necessary to update the time vector
[22]: dt = 0.0001
fs = 1/dt
fs
[22]: 10000.0
12
[24]: A = 1
f = 5
x1 = s1(t,f, A)
x2 = s1(t,2*f, 2*A)
[25]: plt.figure(1)
plt.plot(t,x1, label='x1 = Acos(2$\pi$f t)')
plt.plot(t,x2, label='x2 = 2Acos(2$\pi$2f t)') # esto es para graficar la␣
↪nueva función
plt.xlabel('tiempo (s)')
plt.ylabel('x(t)')
plt.legend(loc=0)
plt.margins(dt)
plt.grid()
plt.axis([0, 1, -2, 2])
13