Skip to main content

Generation of Signals using MATLAB/Python


Generation of Signals using MATLAB/Python

What You will Learn

  • You will learn about various energy signals and their generation using MATLAB and python.

Signal Generation using MATLAB

MATLAB arrays are used to generate finite energy signals. It should be understood that the signals so generated are discrete in time and amplitude.

Sinusoidal Signal

Consider the sinusoidal signal $x=sin(t)$, which is nothing but a single tone, with the help of the MATLAB code below.
t=linspace(0,10,5000);
x=sin(t);
plot(t,x);
grid;
The execution of the code will result in the signal, shown below.

Amplitude Modulated Signal

The above low frequency tone is used to modulate a sinusoidal carrier $y$ of ten times the original frequency. i.e. $y=sin(10t)$. The amplitude modulated signal $am(t)$ is obtained as \begin{equation} am(t)=x*y+y \end{equation}Such an AM signal is generated with the help of the MATLAB code, given below.
t=linspace(0,10,5000);
x=sin(t);
y=sin(10*t);
am=x.*y+y;
plot(t,am);
grid;
The resulting amplitude modulated signal is shown below.

Square Pulse using MATLAB

Square pulses are used in digital and radar communication, local area networks, analog signal processing etc., though their use is much limited by the wide frequency spectrum. Such a pulse of height one unit is realized by the MATLAB code, listed below.
T=5;
t1=linspace(-T,-0.5*T,2000);
t2=linspace(-0.5*T,0.5*T,2000);
t3=linspace(0.5*T,T,2000);
t=horzcat(t1,t2,t3);
x=horzcat(zeros(1,length(t1)),ones(1,length(t2)),zeros(1,length(t1)));
plot(t,x);
grid;
the above code will create a pulse that is centered about the origin with width $5$ units. The first line dictates that half of the time base is $5$ units. The code in the fifth lines concatenates $t_1$, $t_2$ and $t_3$ to form the time base $t$, using the $horzcat$ function. Vectors of zeros and ones are appropriately conacted in the xixth line to genertae the pulse $x$. The function is then plotted with grid on the GUI. The plot is shown below.

Triangular Signal using MATLAB

The triangular function \begin{equation}x(t)=1-\frac{|t|}{T}\end{equation} Let us look at the code that returns a triangular signal, centered about the origin.
T=2;
t=linspace(-1*T,T,5000);
triang=1-abs(t)/T;
plot(t,triang);
grid;
Observe the signal in the figure below.

Signal Generation using Python

The scipy arrays are used to generate many discrete signals, the same way MATLAB was used earlier. The following code shows the generation of a sinusoid.

from scipy import *
from pylab import *
t=linspace(0,10,1000)
x=sin(t)
plot(t,x)
grid('on')
savefig('sinusplot.pdf')
show()

The above code generates a sinusoid and saves as a .pdf files in the current working directory. The GUI looks like what is shown below.

Amplitude Modulated Signal using Python

The above low frequency tone is used to modulate a sinusoidal carrier $y$ of ten times the original frequency. i.e. $y=sin(10t)$. The amplitude modulated signal $am(t)$ is obtained with the following code
from scipy import *
from pylab import *
t=linspace(0,10,1000)
x=sin(t)
y=sin(10*t)
am=x*y+y
plot(t,am)
grid('on')
savefig('amplot.pdf')
show()
The plot of the AM signal generated is shown below.

Square Pulse using Python

The following code generates a pulse.
from scipy import *
from pylab import *
N1=100
N2=40
x=concatenate([zeros(N1),ones(N2),zeros(N1)])
plot(x)
grid('on')
savefig('pulsesig.pdf')
show()
The pulse signal is shown below.

Triangular Signal using Python

The following Python code generates the triangular signal.
from scipy import *
from pylab import *
T=2
t=linspace(-1*T,T,5000)
triang=1-abs(t)/T
plot(t,triang)
grid('on')
savefig('triang.pdf')
show()

What You Learned

  • You learned the use of MATLAB and python arrays to simulate the energy signals.

Comments

Popular posts from this blog

RC Integrator and Differentiator using QUCS

RC Integrator and Differentiator using QUCS Dr. Hari V S Department of Electronics and Communication College of Engineering Karunagappally What You will Learn You will understand the operation of simple integrator and differentiator circuits using QUCS You will learn the frequency response characteristics of integrator and differentiator by dint of ac simulation. Theory Differentiator is a high pass circuit that produces the time derivative of the input signal at the output. The circuit is shown below. \begin{equation} \nonumber v_{o}=I_{o}R=RC\frac{d(v_{s}-v_{o})}{dt}\\

Voltage Divider Circuit using QUCS

SPICE Simulation of Voltage Divider Dr. Hari V S Department of Electronics and Communication College of Engineering Karunagappally What You will Learn You will wire up a voltage divider network using QUCS You will learn to perform DC, AC and transient simulations on the developed circuit. you will learn to observe, store and export the data from the display ( .dpl ) file. Experiment Launch QUCS. Go to Components in the left pane and select the item Lumped Components . Drag and drop a resistor onto the schematic window. Right click on on to and go to Edit properties and make the resistance 1 k&#937 Right click, copy and paste this resistor twice. Connect the three resistors in series by wires, selected by pressing Cntrl+E . Go to Components in the left pane and select Sources &#8594 ac Voltage Source . Drag and drop the source onto the schematics window. Right click on the source and change