Vous êtes sur la page 1sur 4

EE411L Digital Signal Processing: Lab 1

Objectives Get familiar with discrete-time signals in MATLAB Be able to work with sounds in MATLAB Implement simple discrete-time systems in MATLAB Get comfortable with discrete-time sinusoids, and develop a feel for the relationship between and rapidness of signal variation with respect to .

Assumptions Except for tasks 1 and 5, the first element of the vector representing a signal corresponds to n=0, so explicit specification of n is unnecessary. Representation of Discrete-time Signals in MATLAB Discrete-time signals are sequences of numbers Natural way of representing discrete-time signals in MATLAB: Vectors o Vectors in MATLAB are in fact digital signals. However, they are good approximations to discrete-time signals when double precision numbers are used. Can be plotted using stem command Indices of vectors in MATLAB range from 1 to length(s). Built-in MATLAB commands (for convolution, Fourier transform etc) assume that the first element of the signal vector corresponds to n=0. We need to create a vector to keep track of sample number, when required. o >> s = [1:10]; n =[ -5:4]; stem(n, s); xlabel('n'); ylabel ('s[n]');

Sounds in MATLAB Completely described by two vectors o Samples of sound: y o Sampling frequency: Fs Sound(y, Fs) plays sound contained in vector y at the rate of Fs samples per second.

Convolution using MATLAB z = conv(x, y) computes convolution of the sequences x and y and stores it in z conv() does not take time-indices into account (it assumes that the first element of each vector corresponds to n=0. Therefore, the first element of the result corresponds to n=0). If z is convolution of x and y, and if we know the time-indices for x and y, we can figure out timeindices of z using following expressions o nz = (min(nx)+min(ny)):(max(nx)+max(ny))

TASK 1: Create a MATLAB function y=unitstep(n, n0) that returns the values of and n0 (n0 is a number, n is a vector). Do not use for loop. Example: unitstep([-2:5], 3) should return the following vector: [0 0 0 0 0 1 1 1] for given values of n

TASK 2: Load gong.mat (it will add two variables y and Fs in MATLAB). Execute the following commands, and explain your observations. Stem(0:length(y-1), y); Sound(y, Fs) Sound(y(1:end/2), Fs) Sound(y, 2*Fs) Sound(y, Fs/2) Sound(flipud(y, Fs)) (play the sounds in reverse) Sound(y+0.07*randn(size(y)), Fs); %See the documentation of randn

TASK 3: Implement the following system without using for loop { [ ]

Implement it as a MATLAB function that takes input arguments x (a vector) and M (a number) and returns y (first element of vector x is assumed to correspond to n = 0) Is this system linear? Verify your answer. Is the system time-invariant? Verify your answer.

TASK 4: Implement the following system without using for loop

Implement it as a MATLAB function that takes input arguments (a vector) and (a number) and returns (first element of vector is assumed to correspond to = 0) Is this system linear? Verify your answer. Is the system time-invariant? Verify your answer.

TASK 5: Write a function conv_n that takes two input signals and corresponding time indices and generates the result of their convolutions along with the time-indices of the result Convolve with itself for n =-10:10; o Comment on the shape of the resultant sequence Convolve with for n = -10:10; o Comment on the shape of the resultant sequence

TASK 6: Your goal is to implement a function that adds echoes to a sound using convolution. The function should take three input arguments 1. x: original sound 2. d: A vector consisting of delays (in terms of number of samples) for individual echoes (e.g. [8000, 16000, 24000]) 3. att: A vector consisting of attenuations for individual echoes (e.g. [0.5, 0.25, 0.125]). Length of att must be equal to length of d. Approach: Generate a sequence h (consisting of appropriately shifted and scaled impulses). Convolve x with h to obtain the sound with echoes.

TASK 7: a) Plot cos(w*n+pi/4) against n (0<=n<16) for following values of w (use stem instead of plot) o pi, -.75*pi, -0.5*pi, -.25*pi, 0, .25*pi, .5*pi, .75*pi, pi, 1.25*pi, 1.5*pi, 1.75*pi, 2*pi, 2.25*pi, 2.5*pi, 2.75*pi Note: You do not need to copy these values. w varies from pi to 2.5*pi in increments of .25*pi

All 16 signals should be plotted on a single figure (separate axes; use subplot with 4 rows and 4 columns of axes) Do not use multiple stem commands. You can use a single stem command in a for loop. Labels the axes appropriately (within the for loop). The title of each axis should be the value of w for that plot.

b) How does the number of zero-crossings (transistions from ve to +ve, and vice versa) vary as you vary w? o What values of w correspond to most/least rapid changes with respect to n ?

c) Are all the sinusoids plotted in the figure unique? o If not so, what is the maximum range of w for which different values of w result in unique sinusoids cos(w*n+pi/4)? Is that range unique?

d) Find a value of w such that cos(w*n+pi/4) is aperiodic o Use stem command to verify your answer.

Vous aimerez peut-être aussi