Signal Generation and Visualization
This example shows how to generate widely used periodic and aperiodic waveforms, swept-frequency sinusoids, and pulse trains using functions available in Signal Processing Toolbox™.
Periodic Waveforms
In addition to the sin
and cos
functions in MATLAB®, Signal Processing Toolbox™ offers other functions, such as sawtooth
and square
, that produce periodic signals.
The sawtooth
function generates a sawtooth wave with peaks at ±1 and a period of 2Ï€. An optional width parameter specifies a fractional multiple of 2Ï€ at which the signal's maximum occurs.
The square
function generates a square wave with a period of 2Ï€. An optional parameter specifies duty cycle, the percent of the period for which the signal is positive.
Generate 1.5 seconds of a 50 Hz sawtooth wave with a sample rate of 10 kHz. Repeat the computation for a square wave.
Aperiodic Waveforms
To generate triangular, rectangular and Gaussian pulses, the toolbox offers the tripuls
, rectpuls
, and gauspuls
functions.
The tripuls
function generates a sampled aperiodic, unit-height triangular pulse centered about t = 0 and with a default width of 1.
The rectpuls
function generates a sampled aperiodic, unit-height rectangular pulse centered about t = 0 and with a default width of 1. The interval of nonzero amplitude is defined to be open on the right: rectpuls(-0.5) = 1
while rectpuls(0.5) = 0
.
Generate 2 seconds of a triangular pulse with a sample rate of 10 kHz and a width of 20 ms. Repeat the computation for a rectangular pulse.
The gauspuls
function generates a Gaussian-modulated sinusoidal pulse with a specified time, center frequency, and fractional bandwidth.
The sinc
function computes the mathematical sinc function for an input vector or matrix. The sinc function is the continuous inverse Fourier transform of a rectangular pulse of width 2Ï€ and unit height.
Generate a 50 kHz Gaussian RF pulse with 60% bandwidth, sampled at a rate of 1 MHz. Truncate the pulse where the envelope falls 40 dB below the peak.
Generate the sinc function for a linearly spaced vector:
Swept-Frequency Waveforms
The toolbox also provides functions to generate swept-frequency waveforms such as the chirp
function. Two optional parameters specify alternative sweep methods and initial phase in degrees. Below are several examples of using the chirp
function to generate linear or quadratic, convex, and concave quadratic chirps.
Generate a linear chirp.
Generate a quadratic chirp.
Compute and display the spectrograms of the chirps.
Generate a convex quadratic chirp.
Generate a concave quadratic chirp.
Compute and display the spectrograms of the chirps.
Another function generator is the vco
(voltage-controlled oscillator), which generates a signal oscillating at a frequency determined by the input vector. The input vector can be a triangle, a rectangle, or a sinusoid, among other possibilities.
Generate 2 seconds of a signal sampled at 10 kHz whose instantaneous frequency is a triangle. Repeat the computation for a rectangle.
Plot the spectrograms of the generated signals.
Pulse Trains
To generate pulse trains, you can use the pulstran
function.
Construct a train of 2 GHz rectangular pulses sampled at a rate of 100 GHz at a spacing of 7.5 ns.
Generate a periodic Gaussian pulse signal at 10 kHz with 50% bandwidth. The pulse repetition frequency is 1 kHz, the sample rate is 50 kHz, and the pulse train length is 10 milliseconds. The repetition amplitude should attenuate by 0.8 each time. Uses a function handle to specify the generator function.
0 Comments