Matlab Exercises PDF
Matlab Exercises PDF
– exercises
Markus Kuhn
Exercise 2: Give a MATLAB expression that uses only a single matrix multiplication
with B to obtain
(a) the sum of columns 5 and 7 of B
(b) the last row of B
(c) a version of B with rows 2 and 3 swapped
Exercise 5:
(a) Write down the function g(t) that has the shape of a sine wave that increases linearly
in frequency from 0 Hz at t = 0 s to 5 Hz at t = 10 s.
(b) Plot the graph of this function using MATLAB’s plot command.
(c) Add to the same figure (this can be achieved using the hold command) in a different
colour a graph of the same function sampled at 5 Hz, using the stem command.
(d ) [Extra credit] Plot the graph from (c) separately. Can you explain its symmetry?
[Hints: sampling theorem, aliasing].
1
Exercise 6: Use MATLAB to write an audio waveform (8 kHz sampling frequency) that
contains a sequence of nine tones with frequencies 659, 622, 659, 622, 659, 494, 587, 523,
and 440 Hz. Then add to this waveform a copy of itself in which every other sample has
been multiplied by −1. Play the waveform, write it to a WAV file, and use the specgram
command to plot its spectrogram with correctly labelled time and frequency axis.