Uet Signals Lab Manual PDF
Uet Signals Lab Manual PDF
Name: __________________________
Reg. No. : _______________________
Date of Lab: ____________________
1 – …..
Problem
2 – …..
Number
3 – …..
Working
Lab
Performance Viva
Instructor’s Verification
For example,
>> y=2*(1+4*j)
y=
2.0000 + 8.0000i
There are also a number of predefined functions that can be used when defining a
variable. Some common functions that are used in this text are:
abs Magnitude of a number
angle Angle of a complex number in radians
cos Cosine function, assumes argument is in radians
sin Sine function, assumes argument is in radians
exp Exponential function
For example, with y defined as above,
>> c=angle(y)
c=
1.3258
>> c=abs(y)
c=
8.2462
>> c=angle(y)
c=
1.3258
>> c=cos(a)
c=
-0.9900
>> c=exp(a)
1.3 M-FILES
M files are macros of MATLAB commands that are stored as ordinary text files with the
extension ''.m'', that is ‘filename.m’. An M-file can be either a function with input and
output variables or a list of commands. MATLAB requires that the M-file must be
stored either in the working directory or in a directory that is specified in MATLAB
path list. For example consider using MATLAB on a PC with a user-defined M-file
stored in a directory called ''\MATLAB\MFILES''. In order to access that M-file, either
change the working directory by typing ‘cd\MATLAB\mfiles’ within MATLAB
command window or add the directory to the path. Permanent addition to the path is
accomplished by editing the ‘\MATLAB\MATLABrc.m’ file, while temporary
modification to the path is accomplished by typing ‘path(path,’\MATLAB\mfiles');’
within MATLAB. Or, this can easily be achieved through the path browser. As an
example, create a file in your working directory named ‘yplusx.m’ that contains the
following commands:
function z = yplusx(y,x)
z=y+x;
The following commands typed within MATLAB demonstrate how this M-file is used:
>> x=2;
>> y=3;
>> yplusx(y,x)
ans =
5
MATLAB M-files can either be ‘scripts’ or ‘functions’. Scripts are simply files
containing a sequence of MATLAB statements. Functions make use of their own local
variables and accept input arguments. Variables, which are used in a script m-file are
all global variables. The name of a function, as defined in the first line of the M-file,
should be the same as the name of the file without the .m extension. Function M-files
start with the command function. MATLAB M-files are most efficient when written in a
way that utilizes matrix or vector operations. Loops and if statements are available but
should be used sparingly since they are computationally inefficient. For example:
>> for k=1:10;
x(k)=cos(k);
end
This creates a 1x10 vector x containing the cosine of the positive integers from l to 10.
This operation is performed more efficiently with the commands
>> k=1:10;
>> x=cos(k);
Which utilizes a function of a vector instead of a for loop. An if statement can be used
to define conditional statements. The allowed comparisons between expressions are
>= Greater than and equal
<= Less than and equal
> Greater than
< Less than
== Is Equal
~= Not Equal
>> X=A.^2
X=
1 1 1
1 4 9
1 9 36
1.5.5 Matrix Manipulation
Cat -Concatenate arrays
diag -Diagonal matrices and diagonals of a matrix
fliplr -Flip matrices left-right .
flipud -Flip matrices up-down
repmat -Replicate and tile an array
reshape -Reshape array
rot90 -Rotate matrix 90 degrees
tril -Lower triangular part of a matrix
triu -Upper triangular part of a matrix
: (colon) -Index into array, rearrange array
1.5.6 Accessing Vectors and Matrices
f(25) – Accesses the 25th element of f.
f(3:10) – Accesses elements 3 to 10.
f(1:2:50) – Accesses the odd-numbered elements between 1 and 50.
f(1:3,4:8) – Defines a matrix that is equivalent to a section of the matrix f
containing the first, second and third rows, and the fourth to eight columns.
>> a = j*exp(j*11*pi/4)
a=
-0.7071-0.7071i
For a range 0 → 1 with 0.001 increments we would use the following piece of code:
>> t = 0:0.001:1;
>> f = 3* exp(j*3*pi*t)
1.8 LOOPS
From other computer programming experiences, you should be familiar with the idea
of creating a loop to repeat the same task for different values. Here's an example of
how to do that using MATLAB. Suppose we want to generate an output vector where
each element is the sum of the current element and the element from 10 places back in
an input vector. The task to be repeated is the sum of two elements; we need to repeat
this for each element in the vector past 10. The elements of the vector x define the
input ramp function to be integrated, y will hold the result, and k is the loop index:
>> x=3*(0:0.01:5)+2;
>> y=zeros(size(x) );
>> for k=11:length(x)
y(k)=x(k-10)+x(k);
end
As mentioned previously that loops are inefficient in MATLAB so we can rewrite this
problem to use vector addition by creating two new vectors. One which is x offset by
10 and the other which is x padded with 10 zeros (since we can only add vectors of
similar lengths)
>> x=3*(0:0.1:5)+2;
>> x1=[zeros(1,10) x];
>> x2=[x zeros(1,10) ];
>> y=x1+x2;
>> y(1:10)=0;
>> y=y(1:51);
Check the above two approaches. Which one is better?
1.10 SUBSTITUTIONS
MATLAB provides a command that allows us to substitute values, symbolic or
otherwise, for symbolic values. The ‘subs’ command performs the substitution. Use
MATLAB help to learn more about this command.
1.11 EXERCISES
1. Use the subplot command to provide following three plots in one figure:
Plot 1: sin(t), sin(3t), sin(5t)
Plot 2: cos(t), cos(3t), cos(5t)
Plot 3: tan(t), tan(3t), tan(5t)
For . It is important to use different color schemes to differentiate the
harmonics; provide legend, xlabel, ylabel, and title for each plot.
3. Define the symbolic variable x. Make use of this variable to define the symbolic
function sin(1/x). Then, plot the function from 0 to 2. What do you see? Why might
the plotting routine be having trouble plotting this function?
Write a MATLAB function that takes two inputs R and C, and plots the natural
response of this circuit for .
Name: __________________________
Exercise – 1
Exercise – 2
Problem
Number
Exercise – 3
Exercise – 4
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
2.1 OBJECTIVES
Classification of signals, signal energy and power
Useful signal transformations
Systems and their properties
2.2 SIGNALS
A signal is a set of information, message, or data, for example speech, video, pictures,
and television etc. Signals are mathematically expressed as a function of one or more
independent variable. For example a speech signal can be represented mathematically
by acoustic pressure as a function of time. Signals are classified in a variety of ways.
Here we shall discuss the following main classifications only:
1. Continuous-time and Discrete-time Signals: Continuous-time signals are defined
for a continuum of values of time. Discrete time signals are defined only at discrete
values of time. This classification qualifies the nature of a signal along the
horizontal axis representing the independent variable, time.
2. Analog and Digital Signals: A signal whose amplitude can take any value in a
continuous range is an analog signal. A digital signal, on the other hand, is one
whose amplitude can take only a finite number of values. This classification
qualifies the nature of a signal along vertical axis representing signal’s amplitude.
2 2 2
1 1 1
0 0 0
0 2 4 6 8 2 4 6 8 10 -4 -2 0 2 4 6
Figure 2.1
Original Signal:
Time Delayed Signal:
Time Advanced Signal:
Similar is the case with continuous time signals. The following program can be used to
implement time shift in MATLAB:
>> t=[1 2 3 4 5 6 7];
>> x=[0 1 2 3 2 1 0];
>> a=t+3; % Advance the Signal
>> b=t-3; % Delay the Signal
>> subplot(1,3,1)
>> stem(t,x) % Plots the Original Signal
>> subplot(1,3,2)
>> stem(a,x) % Plots the Time Advanced Signal
>> subplot(1,3,3)
>> stem(b,x) %Plots the Time Delayed Signal
Applications of time shift are found in radar and seismic signal processing, in which
several receivers at different locations observe a signal being transmitted through a
medium (water, rock, air etc). The difference in propagation time from the point of
origin of the transmitted signal to any 2 receivers results in a time shift between the
signals at the 2 receivers.
2.4.2 Time Scaling
The compression or expansion of a signal in time is known as time scaling. Consider
the following continuous time signals:
Original Signal x(t) Expanded Signal x(t/2) Compressed Signal x(2t)
1.5 1.5 1.5
1 1 1
-2 -1 0 1 2 -4 -2 0 2 4 -4 -2 -1 0 1 2 4
Figure 2.2
Original Signal:
Expanded Signal:
Compressed Signal:
Example: Let represent an audio tape recording. Then represents the
same audio tape being compressed in time, so it plays at twice the speed. On the
other hand, represents the same audio tape being expanded in time, so it is
slowed down and plays at half the speed.
4 4
2 2
0 0
-2 -2
-4 -2 0 2 4 -4 -2 0 2 4
Figure 2.3
>> t=[-3 -2 -1 0 1 2 3];
>> x=[ -1 1 2 2 3 4 5];
>> x1 = fliplr(x);
>> subplot(1,2,1)
>> stem(t,x) % Plots Original Signal
>> subplot(1,2,2)
>> stem(t,x1) % Plots Time Reversed Signal
2.4.4 Amplitude Scaling
So far operations were performed on the horizontal (time) axis. Here we scale the
vertical (amplitude) axis of a signal. Following figure illustrates a signal , it’s
amplitude scaled versions , and :
1 1 1
0 0 0
-1 -1 -1
-2 -2 -2
5 10 15 20 5 10 15 20 5 10 15 20
Figure 2.4
2.5 SYSTEMS
A system is defined as an entity that transforms/processes a set of signals (inputs)
and yields another set of signals (outputs). A system may consist of physical
components such as electrical or mechanical systems, or it may be an algorithm that
takes some inputs, does some processing and yields outputs.
2) A resistor is a memory less system. Let be the input current and be the
output voltage, then input and output relation is given by:
Thus an accumulator remembers the past inputs and calculates the running sum of
all the inputs up to the current time.
2) A delay system:
3) A capacitor (capacitance given by C), where the current is taken as input and
the output voltage is given as follows:
Figure 2.5
2) A system that produces zero output sequence for any input sequence or a system in
which we cannot determine the sign of the input from the knowledge of the output
is a noninvertible system e.g.:
2.6.3 Causality
A system is said to be causal if the output at any time depends only on the values of the
input at the present time and in the past, not on the future values. A Few examples are
given below:
1) All memoryless systems are casual since the output responds only to the current
values of the input.
2) A delay system is causal:
2.6.4 Stability
A system is known as stable if it’s output stays bounded for a bounded input (i.e. if its
magnitude does not grow without bound), and therefore cannot diverge. Consider
following examples to understand:
1) An accumulator sums all of the past values of the input rather than just a finite set of
values, and the system is unstable since the sum can grow continually even if is
bounded.
2) A model for a bank account balance is an example of an unstable system. If an initial
deposit is made and there are no subsequent withdrawals then that deposit will grow
each month without bound because of compounding effect of interest payments.
2.6.5 Time Invariance
A system is said to be time invariant if a time shift in the input signal results in an
identical time shift in the output signal. Let be the input of a discrete time
invariant system and be the output of a discrete time invariant system. Then for a
time invariant system, is the output when is applied.
3) Analyze each of the following continuous-time systems in terms of the six basic
system properties. In addition, summarize your conclusions in the table below.
(a)
(b)
(c)
Time
Syste Memor Causalit Invertibilit Stabilit Linearit
Invarianc
m y y y y y
e
S1
S2
S3
5) Record your own sound saying the sentence, “The quick brown fox jumps over the
lazy dog”. Play this recording in MATLAB with and without time reversal, also
comment on the observations.
6) Play the sound recording of the previous question after and before expansion and
compression. What is the expansion and compression factor? (i.e. upsampling and
downsampling factor)
Name: __________________________
Exercise – 1
Exercise – 2
Exercise – 3
Problem
Number
Exercise – 4
Exercise – 5
Exercise – 6
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
3.1 OBJECTIVES
Useful functions: unit step and unit impulse
Even and odd signals; even and odd components of a signal
Periodic signals; harmonics
Exponential and sinusoidal signals
The continuous time unit step function is defined in a similar manner, except for the
fact that it is discontinuous at :
u [n] [n]
1 1
0.5 0.5
0 0
-10 -5 0 5 10 -10 -5 0 5 10
u (t) (t)
1 1
0.5 0.5
0 0
-10 -5 0 5 10 -10 -5 0 5 10
80
500
60
0
40
-500
20
0 -1000
-10 -5 0 5 10 -10 -5 0 5 10
An interesting fact is that any signal can be broken into a sum of two signals, one of
which is even and one of which is odd.
1
Original Signal 1 Even Part
0.8
0.5
0.6
0 0.4
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1
0.5
Odd Part 1
Check = Even + Odd
0 0.5
-0.5 0
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1
Figure 3.3
In other words, a periodic signal has the property that it is unchanged by a time shift of
‘ ’. In this case we say that is periodic with time . A very common example of a
periodic signal is a sine wave.
CT Periodic Signal DT Periodic Signal
1 3
2
0.5
1
0 0
2
-1
-0.5
-2
-1 -3
-5 0 5 5 10 15 20
Figure 3.4
The above figure shows that the sine signal repeats itself after a time period
A periodic signal in discrete time is defined analogously. A discrete time signal
is periodic with period , where is a positive integer, if the signal is unchanged
by a time shift of ‘ ’ i.e.
3.6 HARMONICS
Harmonics are integral multiples of a signal. Consider the signal . Its
harmonics will be and so on. Similar is the case with discrete
time signals where for the harmonics can be and
so on. The fundamental harmonic is the first harmonic of the signal i.e. when or
. In the above examples and are fundamental harmonics.
1
sin (t)
sin (2t)
0.5 sin (3t)
-0.5
-1
0 10 20 30 40 50 60
Figure 3.5
2
4 Harmonics of cosine 2
4 Harmonics of sine
1 1
0 0
-1 -1
-2 -2
0 50 100 150 0 50 100 150
Figure 3.6
100
50
0
0 2 4 6 8 10
Figure 3.7
If ‘a’ is real, we have real exponential signal.
If ‘a’ has an imaginary part, we have a complex signal:
For the real and imaginary parts of a complex exponential are sinusoidal.
For they correspond to growing exponential sinusoidal signals.
For they correspond to decreasing exponential sinusoidal signals.
10 10
0 0
-10 -10
-20 -20
3. Decompose the following signal into its even and odd parts
4. Use MATLAB to produce a plot of a discrete-time sinusoid with amplitude 2.0 and a
period of T = 7.
6. Add up first 10 harmonics of ‘sin’ and plot the waveform. What is it like?
7. Add up first 10 harmonics of ‘cos’ and plot the waveform. What is it like?
Name: __________________________
Exercise – 1
Exercise – 2
Exercise – 3
Problem
Exercise – 4
Number
Exercise – 5
Exercise – 6
Exercise – 7
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
4.1 OBJECTIVES
Fourier series representations
Discrete Fourier Series
Fourier Series in MATLAB
Where ω0 = 2π/N.
4.2.3 Fourier Series in MATLAB
MATLAB does not have any built-in function that directly computes the discrete
Fourier series coefficients. The following program taken from [1] is used to find the
Fourier Series Coefficients. It returns the magnitude and phase of each sinusoidal
component in the Fourier series expansion for one cycle of a periodic signal. It is
≫N=length(x)
≫frequencies=[0:fs/N:fs/2];
≫plot(frequencies, magnitude);
≫xlabel('frequency in Hertz')
≫ylabel('amplitude')
3. Understand the working of function fourierSeries, and relate the particular form of
Fourier series expansion used in this function to the trigonometric Fourier
coefficients.
This is called a chirp signal. Listen to it. Plot its Fourier series coefficients using
the fourierSeries function as described. This chirp is 8-kHz samples of the
continuous-time waveform.
For the given values t used to compute samples y, what is the range of
instantaneous frequencies? Explain how this corresponds with the plot of the
Fourier series coefficients, and how it corresponds with what you hear.
6. The Fourier series coefficients computed in part 3 describe the range of
instantaneous frequencies of the chirp pretty well, but they do not describe the
dynamics very well. Plot the Fourier series coefficients for the waveform given by
Listen to this sound. Does it sound the same as y? Does its Fourier series plot look
the same or is it different? Why?
7. The chirp signal has a dynamically varying frequency-domain structure. More
precisely, there are certain properties of the signal that change slowly enough that
our ears detect them as a change in the frequency structure of the signal rather
than as part of the frequency structure (the timbre or tonal content). Recall that
our ears do not hear sounds below about 30 Hz. Instead, the human brain hears
changes below 30 Hz as variations in the nature of the sound rather than as
frequency domain content. The preceding Fourier series methods fail to reflect this
psychoacoustic phenomenon.
A simple fix is the short-time Fourier series. The preceding chirp signals have
8,000 samples, lasting one second. But since we don’t hear variations below 30 Hz
as frequency content, it probably makes sense to reanalyze the chirp signal for
frequency content 30 times in the one second. This can be done using the
Waterfall Spectrogram function. Spectrogram are color based visualizations of
the evolution of power spectrum of speech signal as the signal is swept through
Name: __________________________
Exercise – 1
Exercise – 2
Exercise – 3
Exercise – 4
Problem
Number
Exercise – 5
Exercise – 6
Exercise – 7
Exercise – 8
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
5.1 OBJECTIVES
LTI Systems
Impulse Response and Convolution
Laplace Transform
The fundamental result in LTI system theory is that any LTI system can be
characterized entirely by a single function called the system's impulse response. The
output of the system is simply the convolution of the input to the system with the
system's impulse response.
LTI System
Figure 5.1
Figure 5.2
MATLAB provides function ‘impulse’ to find the impulse response of an LTI system.
Impulse response is an important feature because it enables us to measure the output
of an LTI system in response to any input signal, by simply performing convolution.
Continuous Time Discrete Time
Convolution Integral Convolution Sum
MATLAB uses the command “laplace” to find the Laplace transform of a function, and
“ilaplace” for the inverse Laplace. Consider the following example of single sided
Laplace transform:
Time Shifting
Frequency Shifting
Scaling
Convolution
Then “deconv” the signal to check if you get the original signal back or not.
2. Write a function that will perform convolution sum bit by bit rather than using the
‘conv’ command.
4. Determine the output of the system is the input of the system is:
Name: __________________________
Exercise – 1
Exercise – 2
Exercise – 3
Exercise – 4
Problem
Exercise – 5
Number
Exercise – 6
Exercise – 7
Exercise – 8
Exercise – 9
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
6.1 OBJECTIVES
z-transform
Transfer functions
Poles and zeros
6.2 Z-TRANSFORM
z-transform is the discrete time counter part of the Laplace transform. The complex
variable ‘ ’ in Laplace domain is replaced by ‘ ’ in z-domain.
z-Transform Inverse z-Transform
1
Imaginary Part
0.5
-0.5
-1
-1 -0.5 0 0.5 1
Real Part
Figure 6.2 Z-plane of the above example
Transfer functions are defined in MATLAB by storing the coefficients of the numerator
and the denominator in vectors. Given a continuous-time transfer function:
Where Y and
Store the coefficients of Y and X in the vectors in order of descending powers
of s. In this text, the names of the vectors are generally chosen to be num and den, but
We may find the poles and zeros of this equation using the following commands:
>> z=roots([4,0,6])
z=
0 + 1.2247i
0 - 1.2247i
>> p=roots([1,1,0,-2])
p=
-1.0000 + 1.0000i
-1.0000 - 1.0000i
1.0000
Hence we identify a pair of complex conjugate zeros at , a pole at
and a pair of complex conjugate poles at . The command poly(r) uses the
poles and zeros specified in the vector to determine the coefficients of the
corresponding polynomial. To find the zeros, poles and gain of a transfer function from
the vectors num and den which contain the coefficients of the numerator and
denominator polynomials, type:
>> num = [4,0,6];
>> den = [1,1,0,-2];
>> [z,p,k]=tf2zp(num,den)
z=
0 + 1.2247i
0 - 1.2247i
p=
-1.0000 + 1.0000i
Or
>> H=zpk(z,p,k)
Zero/pole/gain:
4 (s^2 + 1.5)
--------------------
(s-1) (s^2 + 2s + 2)
Pole-Zero Map
1.5
1
Imaginary Axis
0.5
-0.5
-1
-1.5
-1.5 -1 -0.5 0 0.5 1
Real Axis
Figure 6.3
Pole-Zero Map
15
10
Imaginary Axis
-5
-10
-15
-4 -3 -2 -1 0
Real Axis
Figure 6.4 Pole and Zero locations in the s-plane
2. The transfer functions for two causal LTI systems are given below,
a) Plot the pole-zero diagram of H1(z) and H2(z) using ‘zplane’. From the locations
of the poles and zeros, determine if the systems are stable or unstable and
explain your answer.
b) Plot the magnitude and phase of the frequency responses of the two systems in
the range 0 ≤ ≤ 2π. Use the function subplot for this section. Note: The
frequency response function of a system is obtained by substituting in
the transfer function.
c) Use the inverse z-transform to obtain the impulse responses of the two
systems, h1(n) and h2(n). Plot the impulse responses for 0 ≤ n ≤ 25. Do the
impulse responses verify your answer regarding system stability in part (a)?
How?
3. Determine the poles and zeros of the following systems and plot them in the s-
plane:
4. Find the partial fraction expansion for the Laplace Transform (also show working):
Name: __________________________
Exercise – 1
Exercise – 2
Problem
Number
Exercise – 3
Exercise – 4
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
7.1 OBJECTIVES
Fourier Transform (FT)
Discrete Fourier transform (DFT)
Discrete Time Fourier transform (DTFT)
There are two important results that one should remember i.e.
Fourier transform of a periodic signal has discrete values
Fourier transform of an aperiodic signal has continuous values
7.2.1 Fourier Transform in MATLAB
MATLAB has a built in function fourier() and ifourier() for calculating the Fourier
transform and inverse Fourier transform respectively. Consider the following signal:
Then the Fourier Transform of the signal can be found by performing the integration,
using the following MATLAB commands:
>> syms a t f
>> sig=t/abs(t);
>> ut=(1+sig)/2;
>> pulse=subs(ut,t+a/2)-subs(ut,t-a/2)
pulse =
1/2*(t+1/2*a)/abs(t+1/2*a)-1/2*(t-1/2*a)/abs(-t+1/2*a)
>> pretty(pulse)
t + 1/2 a t - 1/2 a
1/2 ------------- - 1/2 --------------
| t + 1/2 a | | -t + 1/2 a |
>> Xjw=int( exp(-j*2*pi*f*t)*subs(pulse,a,1),t,-inf,inf)
Xjw =
-1/2*i*(exp(i*pi*f)-exp(-i*pi*f))/pi/f
>> pretty(simple(Xjw))
sin(pi f)
---------
pi f
The simple() command looks for a simple form of the function . The ezplot
command won’t give optimal results (check!). Plot the Fourier transform for above
example!!
The most important thing while taking the DFT of a signal is the ‘number of points' or
‘N’. It indicates the number of points we are taking (from the signal) for the transform.
There are three cases with regards to N
N < Length of signal: Results in a frequency response which doesn't show all the
frequency components present in the signal
N = Length of signal: Results in a frequency response that gives all the frequency
components in the signal at their exact frequency value
N > Length of signal: The DFT of the sampled signal becomes close to the transform
of the original signal i.e. DTFT.
7.3.1 Discrete Fourier Transform in MATLAB
When we sample a signal and want to get its Fourier transform we perform what is
called a Discrete Fourier Transform (DFT). An algorithm to do a DFT quickly is called
the Fast Fourier Transform (FFT). The algorithm is fast if the number of points is a
power of 2 (radix-2 FFT). The Discrete Fourier Transform of a sampled pulse will be a
scaled version of the Fourier transform of a pulse in continuous time. MATLAB uses
the following command to find the DFT of a signal
≫
The fast Fourier transform (FFT) is an efficient algorithm for computing the DFT of a
sequence; it is not a separate transform. It is particularly useful in areas such as signal
and image processing, where its uses range from filtering, convolution, and frequency
analysis to power spectrum estimation. To find the inverse DFT:
≫
To represent the equation in MATLAB avoiding loops we transform the summation
into its equivalent matrix operations by:
>> N = 40;
>> k=0:N-1;
>> n=0:N-1;
>> z=N-length(x);
>> x=[x zeros(1,z) ];
>> w=2*pi*k/N;
>> X=x* exp(-j*n'*w);
Explain when and why do we use the above piece of code which includes zero
padding??
2) Find and plot the Discrete Fourier Transform of the following signals:
3) Find and plot the Discrete Time Fourier Transform of the following signal:
4) Write a program to calculate the inverse Fourier transform of a signal and apply it
on part 1 to recover the original signals given.
5) Write a program to calculate the inverse discrete Fourier transform of a signal and
apply it on part 2 to recover the original signal given.
6) Write a program to calculate the inverse discrete time Fourier transform of a signal
and apply it on part 3 to recover the original signals given.
Name: __________________________
Exercise – 1
Exercise – 2
Exercise – 3
Problem
Number
Exercise – 4
Exercise – 5
Exercise – 6
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
8.1 OBJECTIVES
Transforming sound signals
Explore images and colormaps
1. Sample the function at 8 kHz, and plot the samples for the entire interval
. How many samples are there?
2. Change the frequency of the sine wave from the previous section to 440Hz and plot
the signal for the interval . Why is the plot hard to read? Plot the samples
that lie in the interval [0, 0.01] instead.
Where sampled_signal is the signal you created in part 2 above. Explain in what
way these are different from what you heard in the previous part.
5. Listen to
Attenuation Delay
We begin this section by constructing the MATLAB commands that generate this
image. To do this, you need to know a little about how MATLAB represents images. In
fact, MATLAB is quite versatile with images, and we will only explore a portion of what
it can do.
The first of these is a familiar sinusoidal signal. The second is a sinusoidal signal
with a decaying exponential envelope. The third is a sinusoidal signal with a
growing exponential envelope. Choose a sampling period so that the plots closely
resemble the continuous-time functions. Explain your choice of the sampling
period. Use subplot to plot all three functions in a single figure.
2. Use MATLAB to listen to a one-second sinusoidal waveform scaled by a decaying
exponential given by
Use a sample rate of 8,000 samples/second. Describe how this sound is different
from sinusoidal sounds that you heard before in the lab tasks.
3. Construct a sound signal that consists of a sequence of half-second sinusoids with
exponentially decaying envelopes, as in the previous part, but with a sequence of
frequencies: 494, 440, 392, 440, 494, 494, and 494. Listen to the sound. Can you
identify the tune?
4. Copy a .wav file into the work directory of MATLAB. Use the ‘wavread’ command
to read it into your MATLAB. Convert it into a mono sound if it’s a stereo.
Manipulate it to create a double function, a half function and an echo function
described above.
5. What is the representation in a MATLAB colormap for the color white? What about
black?
6. Create a 200 × 200 pixel image like that shown in figure 9.2. Set the colormap to
gray(256), as indicated above. Note that when you display this image using the
image command, it probably will not be a square. This is because of the (somewhat
annoying) stretching that MATLAB insists on doing to make the image fit the
default graphics window. To disable the stretching and get a square image, use the
axis command. As usual with MATLAB, a brute-force way to create matrices is to
use for loops, but there is almost always a more elegant (and faster) way that
exploits MATLAB’s ability to operate on arrays all at once. Try to avoid using for
loops to solve this and subsequent problems.
7. Change your image so that the sinusoidal variations are horizontal rather than
vertical. Vary the frequency so that you get four cycles of the sinusoid instead of
one. What is the frequency of this image?
8. An image can have both vertical and horizontal frequency content at the same time.
Change your image so that the intensity at any point is the product of a vertical and
horizontal sinusoid. Be careful to stay within the numerical range that indexes the
colormap.
Name: __________________________
Learning Tasks
Exercise – 1
Exercise – 2
Exercise – 3
Problem
Exercise – 4
Number
Exercise – 5
Exercise – 6
Exercise – 7
Exercise – 8
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
9.1 OBJECTIVES
Building Graphical User Interface (GUI) in MATLAB.
These boxes can be placed anywhere in the checked screen, by clicking on them and
dragging them with the mouse. Once we are sure that we have made all the changes
and that this is the kind of outlook we want, we can save the file with a name in the
current work directory. The file is saved as a ‘.fig' file and can be accessed in the
MATLAB command window by just typing its name. When the file is saved, a ‘.m' file is
9.3 EXAMPLES
MATLAB help provides elaborate examples for using different functions and toolboxes.
In order to see a sample GUI, type “doc” in command window. This will open HTML
documentation in help browser.
Search for “Simple GUI"
Read this example
Open its m-file
Play the file
Study its callback functions
9.4 EXERCISE
1. Make a model in GUI that will calculate the first 5 harmonics of a sine wave, also
display the results in GUI.
2. Make a model in GUI that will add up the harmonics of a sine wave and display a
square wave. Input the wave from GUI and display the output in GUI. The output
must near a perfect square wave when more and more odd harmonics are added.
Name: __________________________
Exercise – 1
Problem
Exercise – 2
Number
Exercise – 3
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
10.1 OBJECTIVES
Sampling and Aliasing
Nyquist criteria
10.2 INTRODUCTION
It is often desired to analyze and process continuous-time signals using a computer.
However, in order to process a continuous-time signal, it must first be digitized. This
means that the continuous-time signals must be sampled and quantized, forming a
digital signal that can be stored in a computer. Analog systems can be converted to
their discrete-time counterparts, and these digital systems then process discrete-time
signals
to produce discrete-time outputs. The digital output can then be converted back to an
analog signal, or reconstructed, through a digital-to-analog converter. Figure 10.1 is an
illustration containing the three general components described above: a sampling
system, a digital signal processor, and a reconstruction system. In this lab we will focus
on the process of sampling and reconstruction.
Figure 10.1
10.3 SAMPLING
Sampling is simply the process of measuring the value of a continuous-time signal at
certain instants of time. Typically, these measurements are uniformly separated by the
sampling period . If is the input signal, then sampled signal is as follows:
In the spectral domain, sampling produces a periodic spectrum, with images of the
original spectrum centered around multiples of the sampling frequency (aliases):
Where is the sampled signal spectrum, and is the original signal spectrum. If the
signal is sampled properly, it is possible to reconstruct it perfectly from the discrete
values. Sampling frequencies that are too low lead to aliasing – frequencies from the
aliases of the original spectrum will appear in the original band, and the nature of the
spectrum is changed. If the sampling frequency is too low, some harmonic components
can end up being aliased into the negative frequency range. These components fold
back around zero frequency and appear in the original band as low frequency
components.
1. Assume you sample a 2 Hz sinusoid, at a sampling rate = 8Hz starting at 0s. Is the
Nyquist criterion satisfied? Calculate values of the sampled signal during the first
second. (HINT: create an appropriate vector in MATLAB starting at 0 and ending at
1. Check help for the sine function.)
2. Now assume you sample a 10 Hz sinusoid at the same sampling rate. What about
the Nyquist criterion now? Calculate the values of the sampled signal during the
first second. Compare the results with the previous calculation. What happened?
Sketch both signals during the first second, and mark the sampling instants and the
samples on your sketch.
4. The spectrum shown in Figure 11.4 is that of a band pass signal. What is its Nyquist
rate? Assume that it is ideally (impulse) sampled a) at = 500Hz and b) at =
200Hz. Is the Nyquist criterion satisfied in these two cases? Sketch the spectra for
both cases of sampled signals. Mark the relevant frequencies. Is there aliasing?
Could the original signal be reconstructed? If so, how (in the ideal case)?
1. Generate a chirp as explained above that lasts for 8,192 samples at an 8-kHz
sample rate and sweeps from a frequency of zero to 2,500 Hz. Listen to the
resulting sound. Are there any aliasing artifacts? Why or why not?
2. Use the FFT algorithm, to create a plot of the magnitude of the DFT of the chirp
signal from the previous part over the frequency range -4 kHz to 4 kHz. Make sure
the horizontal axis of the plot is labeled in Hertz. Does the plot look like a sensible
frequency-domain representation of this chirp?
3. Modify the chirp so that it sweeps from 0 to 5 kHz. Listen to it. Do you hear aliasing
artifacts? Plot the magnitude of the DFT over -4 kHz to 4 kHz. Can you see the
aliasing artifacts in this plot? Explain why the plot has the shape that it does.
4. Return to the chirp that you generated in part 1, which sweeps from 0 to 2,500 Hz.
Create a new signal with sample rate 4,000 samples/second by downsampling
that chirp. That is, create a vector in MATLAB that has half the length by selecting
every second sample from the original chirp. For example, if y(n) is the original
chirp, define w(n) as . Now plot the magnitude DFT of this signal.
Since the sampling rate is lower by a factor of 2, you should plot over the frequency
interval -2 kHz to 2 kHz. Is there aliasing distortion? Why?
5. Return again to the chirp that you generated in part 1, which sweeps from 0 to
2,500 Hz. Create a new signal with sample rate 16,000 samples/second by
upsampling that chirp. That is, create a vector in MATLAB that has twice the
length by inserting zero-valued samples between each pair of samples from the
original chirp. For example, if y(n) is the original chirp, define z by
6. Now plot the magnitude DFT of this signal. Since the sampling rate is higher by a
factor of 2, you should plot over the frequency interval -8 kHz to 8kHz. Explain this
plot. Listen to the sound by giving a sampling frequency argument to soundsc as
follows:
≫
7. How does the sound relate to the plot? Note that this technique is used in most
compact disc players today. The signal on the CD is sampled at 44,100
samples/second. The CD player first upsamples it by a factor of 4 or 8 to get a
sample rate of 176,400 samples/second or 352,800 samples/second. The
upsampling is accomplished by inserting zero-valued samples. The resulting signal
is then digitally filtered to get a high sample rate and accurate rendition of the
audio. The higher sample rate signal is then converted to a continuous-time signal
by a digital to analog converter that operates at the higher sample rate. This
technique shifts most of the difficulty of rendering a high-quality audio signal to
the discrete time domain, where it can be done with digital circuits or
microprocessors (such as programmable DSPs) rather than with analog circuits.
Name: __________________________
Learning Tasks
Exercise – 1
Exercise – 2
Exercise – 3
Problem
Number
Exercise – 4
Exercise – 5
Exercise – 6
Exercise – 7
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification
11.1 OBJECTIVES
Introduction to Simulink
11.2 SIMULINK
MATLAB and Simulink are two very different pieces of software with radically
different approaches to modeling of signals and systems. MATLAB is an imperative
programming language, whereas Simulink is a block diagram language. Simulink is
used for a variety of purposes, but mainly for the simulation of real time systems. The
function of Simulink is very similar to that of electronic work bench or circuit designer.
There are certain components already defined in Simulink, like clocks, muxes,
input/output switches, signal generators, scopes and many more. By connecting these
components we can generate a simulation of the actual circuit and visualize its
response to different inputs. The in-built functional blocks can be modified to a certain
extent, but if we want to create a custom block or macro, we have to use s-functions.
Each block that is created has a .m file behind it or a C-code that executes whenever
the block is activated. By writing an s-function we mean that we create an m-file or a
C-code by our own in which the function of the block is explained with its different
inputs.
11.2.1 How to Launch Simulink
The Simulink can be launched by typing ‘Simulink’ in the MATLAB command window.
When we do so, a window pops up:
Figure 11.1
In the Simulink library browser shown in above figure is a list of toolboxes on the left
and a list of components on the right. Whenever a particular toolbox is selected the list
1. Create a model that adds up 4 sinusoids to generate a square wave, stores the
result in the Workspace, and displays the result on the scope.
3. Create a model that will calculate the z-transform of an input signal given by you.
4. Create a model that will calculate the Fourier Transform of an input signal
provided by a user, and show its frequency contents using ‘spectrum analyzer’.
Name: __________________________
Exercise – 1
Exercise – 2
Problem
Number
Exercise – 3
Exercise – 4
MATLAB Codes
Lab
Performance
Viva
Instructor’s Verification