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}\\ ...

RC Coupled Amplifier

RC Coupled Amplifier Dr. Hari V S Department of Electronics and Communication College of Engineering Karunagappally What You will Learn You will understand the design of RC coupled amplifier. You will appreciate its frequency response and understand the variation of voltage gain at low and high frequencies. You will understand the effect of emitter bypass capacitor (or rather the effect of current series negative feedback) on the voltage gain and frequency response of the amplifier. You will understand the concept of stability of amplifier by analyzing the Nyquist plot and understand how negative feedback improves the stability. Objectives To design and implement RC coupled amplifier and to observe voltage amplification both in Qucs and on breadboard. To plot its frequency response curve and to compute the bandwidth with and without feedback. Design Let $V_{CC}=15V$, $\beta=200$ and $I_{C}=5mA$. For active region ...