0% found this document useful (0 votes)
148 views

Matlab Assignment - 1

This document provides instructions for several MATLAB assignments involving signal generation and processing. It first describes loading and plotting a sampled train whistle signal and image, and generating a chirp signal that is written to a WAV file and then read back. It then lists four problems to solve using MATLAB: 1) sampling a 4cos(2πt) signal at different rates and determining information loss, 2) a problem from the textbook on sampling, 3) another textbook problem on sampling, and 4) a textbook problem on signal representation.

Uploaded by

M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views

Matlab Assignment - 1

This document provides instructions for several MATLAB assignments involving signal generation and processing. It first describes loading and plotting a sampled train whistle signal and image, and generating a chirp signal that is written to a WAV file and then read back. It then lists four problems to solve using MATLAB: 1) sampling a 4cos(2πt) signal at different rates and determining information loss, 2) a problem from the textbook on sampling, 3) another textbook problem on sampling, and 4) a textbook problem on signal representation.

Uploaded by

M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ELEC 360-Signals and Systems

Matlab Assignment # 1

"Signal Generation using Matlab"


Part 1: Signal generation using Matlab
Reference: Chapter 0 of ebook: Luis Chaparro, Page 37-41.

Follow all steps and verify all results by using the given codes and
scripts.
1.1 MATLAB provides data files for experimentation that you can load and work with using the
function load. For instance, the file train.mat is the recording of a train whistle, sampled at
the rate of Fs samples/second (which accompanies the sampled signal y(n)). To be able to
work with this file you can just type the following commands to load the data file (with
extension . mat) into the work space:
% Loading of test signal train
%%
clear all
load train
Information about the file is given by the function whos and shown as Name Size Bytes Class
whos
Name Size Bytes Class Attributes
Fs 1x1 8 double
y 12880x1 103040 double
The sampling frequency is Fs = 8,192 samples/second, and the sampled train sequence is a
column vector with 12,880 samples. One could then listen to this signal using the function sound
with two input parameters, the sampled signal y and Fs, and then plot it:
%%
% Listening to/plotting train signal
%%
sound(y,Fs)
t=0:1/Fs:(length(y)-1)/Fs;
figure(2); plot(t,y’); grid
ylabel(’y[n]’); xlabel(’n’)
To plot the signal, MATLAB provides the functions plot and stem. The function plot gives an
interpolated version of the sequence, making the plot look continuous. The function stem plots
the sequence of samples. To plot 200 samples of the train signal with stem we use the following
script. Notice the way MATLAB gets samples 100–299 from the signal.
%%
% Using stem to plot 200 samples of train
%%
figure(3)
n=100:299;
stem(n,y(100:299)); xlabel(’n’);ylabel(’y[n]’)
title(’Segment of train signal’)
axis([100 299 -0.5 0.5] )


 
a) Show the whole train signal plotted using plot.
b) Show the segment of train signal plotted using stem.
1.2 MATLAB also provides test images, such as clown.mat (with 200 × 320 pixels). It can be
loaded using the script
clear all
load clown
Information about the file is given by the function whos and shown
whos
Name Size Bytes Class Attributes
X 200x320 512000 double
ans 200x320 512000 double
caption 2x1 4 char
map 81x3 1944 double

a) Plot this image in gray levels using the following script:

colormap (’gray’)
imagesc (X)
1.3 It is possible to generate your own signals by using many of the functions available in
MATLAB. The following script illustrates how to generate a wave audio file and then
reading it back and listening to it. Create an m-file and save it in your root directory.
% Creating a WAV file from scratch and reading it back
%%
clear all
Fs=5000; % sampling rate
t=0:1/Fs: 5; % time parameter
y=0.1*cos(2*pi*2000*t)-0.8*cos(2*pi*2000*t.^2); % sinusoid and chirp
%% writing chirp.wav file
audiowrite('chirp.wav',y, Fs)
%% reading chirp.wav back into MATLAB as y1 and listening to it
[y1, Fs] = audioread('chirp.wav');
sound(y1, Fs) % sound generated
figure(4)
plot(t(1:1000), y1(1:1000))
The signal we create with this script is a sinusoid added to a chirp (a sinusoid with varying
frequency). The signal has a duration of 5 sec, and it is sampled at a rate of 5,000 samples per
second, so the signal has a total of 25,001 samples. The function audiowrite converts the signal
generated by MATLAB into a wav audio file called ’chirp.wav’. This file is then read back by
audioread and the function sound plays the sound file.
a) Show the generated signal segment composed of sinusoid added to chirp.


 
Part 2: Problems Using Matlab
Use matlab to solve the following problems. Support your solution
with all scripts, codes, results, and graphs.
2.1 Sampling—Consider a signal 𝑥 𝑡 4𝑐𝑜𝑠 2𝜋𝑡 defined for ∞ 𝑡 ∞. For the
following values of the sampling period 𝑇 generate a discrete-time signal
𝑥 𝑛 𝑥 𝑛𝑇𝑠 𝑥 𝑡 |

(i) 𝑇 0.1, (ii) 𝑇 0.5, (iii) 𝑇 1


Determine for which of the given values of 𝑇 the discrete-time signal has lost the information in
the continuous-time signal. Use MATLAB to plot 𝑥 𝑡 (use 𝑇 10 and the plot function)
and the resulting discrete-time signals (use the stem function). Superimpose the analog and the
discrete-time signals for 0 𝑡 3; use subplot to plot the four figures as one figure. You also
need to figure out how to label the different axes and how to have the same scales and units.

2.2 Luis Chaparro: Chapter 0- Problem 0.9.


2.3 Luis Chaparro: Chapter 0- Problem 0.13.
2.4 Luis Chaparro: Chapter 1- Problem 1.17.


 

You might also like