3
MCS-EE Dept Signals & Systems Aug 2007 1 Digital Signal Processing Signals & Systems ...Lab 2 After an introduction to MATLAB, we are in a position to explore different aspects of science, in general, and DSP in particular, by making the use of the environment of MATLAB--- ideal software for studying DSP. It has many functions to create and process signals, and the results can be readily plotted in many ways. Stepping towards DSP demands a strong foundation of signals and systems. In life, we can fearlessly say, are only two things: one is signals and the other is systems. In every engineering problem we encounter, the first step towards solution is to identify the signals and systems involved in the problem. The next comes the dealing/working with those identified signals and systems to achieve the desired goal. To develop a mastery over this, therefore, would really make DSP a fun. On the other hand, life without an intuition of signals and systems is really un-understandable. To start with, one may ask: “Where are the signals?”. The answer is simple: When we see lightening, listen to the music, or use any of your five senses to ‘perceive’ something, we are dealing with signals. Our mind is an example of a system. In DSP, we need to be more mathematical and objective to characterize the signals and systems. This is really trivial but extremely important. Making different signals, visualizing them, performing different operations on them and passing them through different systems would be a proper way to take a start In this lab… we shall use our MATLAB skills to generate some simple and then complicated signals, manipulate them and visualize them. Next, we’ll understand fundamental concepts of systems and the way they ‘transform’ signals. Part I: The Signals All the signals have to be either vectors (row or column), or matrices in MATLAB of finite length. The index of the vector usually corresponds to time, and it always has to be 1 to N, if N is assumed to be the length of the vector. MATLAB has the power to perform vector operations quite efficiently, implying that processing of signals is easy. As a general rule, discrete signals are viewed using ‘stem’ and indices must be plotted on the axis. It’s always a good habit to label all the axes and title the figures properly. Problem 1: Creation of Signals a) We will often need the functions for these general signals: a unit impulse: δ(n-n0) of desired length a unit step: u(n-n0) of desired length shifter: a function which gives the input signal an arbitrary shift of n0 b) Generate the following signals in MATLAB: x1[n] = 2 δ(n + 2) - δ(n-4), -5 n 5 x2[n] = n(u[n] – u[n-10]) + 10 exp(-0.3(n-10)) (u[n-10]-u[n-20]) 0 n 20 x3[n] = cos(0.04πn) + 0.02w[n], for 0 n 50,

Lab2

Embed Size (px)

DESCRIPTION

Lab2

Citation preview

  • MCS-EE Dept Signals & Systems

    Aug 2007 1

    Digital Signal Processing Signals & Systems ...Lab 2 After an introduction to MATLAB, we are in a position to explore different aspects of science, in general, and DSP in particular, by making the use of the environment of MATLAB--- ideal software for studying DSP. It has many functions to create and process signals, and the results can be readily plotted in many ways. Stepping towards DSP demands a strong foundation of signals and systems. In life, we can fearlessly say, are only two things: one is signals and the other is systems. In every engineering problem we encounter, the first step towards solution is to identify the signals and systems involved in the problem. The next comes the dealing/working with those identified signals and systems to achieve the desired goal. To develop a mastery over this, therefore, would really make DSP a fun. On the other hand, life without an intuition of signals and systems is really un-understandable. To start with, one may ask: Where are the signals?. The answer is simple: When we see lightening, listen to the music, or use any of your five senses to perceive something, we are dealing with signals. Our mind is an example of a system. In DSP, we need to be more mathematical and objective to characterize the signals and systems. This is really trivial but extremely important. Making different signals, visualizing them, performing different operations on them and passing them through different systems would be a proper way to take a start

    In this lab we shall use our MATLAB skills to generate some simple and then complicated signals, manipulate them and visualize them. Next, well understand fundamental concepts of systems and the way they transform signals.

    P a r t I : T h e S i g n a l s All the signals have to be either vectors (row or column), or matrices in MATLAB of finite length. The index of the vector usually corresponds to time, and it always has to be 1 to N, if N is assumed to be the length of the vector. MATLAB has the power to perform vector operations quite efficiently, implying that processing of signals is easy. As a general rule, discrete signals are viewed using stem and indices must be plotted on the axis. Its always a good habit to label all the axes and title the figures properly. Problem 1: Creation of Signals a) We will often need the functions for these general signals: a unit impulse: (n-n0) of desired length a unit step: u(n-n0) of desired length shifter: a function which gives the input signal an arbitrary shift of n0 b) Generate the following signals in MATLAB:

    x1[n] = 2 (n + 2) - (n-4), -5 n 5 x2[n] = n(u[n] u[n-10]) + 10 exp(-0.3(n-10)) (u[n-10]-u[n-20]) 0 n 20 x3[n] = cos(0.04n) + 0.02w[n], for 0 n 50,

  • MCS-EE Dept Signals & Systems

    Aug 2007 2

    where w[n] is a gaussian random signal x4[n] is signal of four periods of sequence [5,4,3,2,1], in the range -10 n 9 x5[n] =

    =

    1

    0][

    M

    ll lPnA where P = 5, and x5[n] has a length=50, start @ n=0.

    c) Sinusoids--- the most general category of signals. Yes, its true. Believe it or not, every signal in this universe contains nothing but sinusoids. Well explore this aspect in detail in our later labs, but for now, these signals are quite interesting and beautiful to be looked in detail.

    x1[n] = sin ( 17

    n), 0 n 25

    x2[n] = cos ( 17

    n), -15 n 15 x3[n] = sin (3 n), -10 n 10 x4[n] = cos (

    23

    n), 0 n 50 See the figures for each of the signals and comment about each with the aspect of even and odd, periodic and aperiodic etc. Can you think of representing x3[n] without trigonometric functions? We would be dealing with sinusoids quite frequently in future. Its a good idea if we can understand the mathematics of a sinusoidal signal and write a general function for it. (i) Write a function to generate a sinusoid of given specifications: it should take six parameters: Freq, Amplitude, Initial Phase, Sampling Freq., Start-Time, Stop Time. (ii) Generate: s(t) = 50cos(2pi*1200*t + pi/4), using the above function. If you are done with the simple practice session, Change the start and stop time in the above function to generate a cosine which appears to be a sine. (iii) Complex Exponentials: Generate x0[n] = exp(j*n/3), for some range and see its real and imaginary parts separately. Also make the following signals:

    x1[n] = e(-0.1+j0.3)n, -10 n 10 x2[n] = an u[n], where a=0.9, and 1.1 for -50 n 100 x3[n] = 3 sin (

    17

    n) + j 4 cos ( 17

    n), 0 n 25 You may like to listen to these sinusoids, or some of these. Use MATLABs sound to play your signal at the sound card. Whats fs in this sound ? Explore wavread, wavwrite also, and try to understand the phenomenon involved. Play some sinusoids of audible frequency range. What happens if we use our functions double, half, fliplr etc before playing the sinusoid? Signals can be images, videos, air pressure, and so on. To handle all these signals is just like we did with the simple signals today. Its just the matter of understanding the particular signal and representing efficiently. Problem 2: Manipulation of Signals a) Do the following: x1(n) = 2x(n-5) 3x(n+4) and x2(n) = x(3-n) + x(n) x(n-2) where x(n) = {1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1} b) Extract Even and Odd parts of a signal, by following the definition of Even/Odd.

    c) Write functions for y1[n] = x[Mn

    ], and y2[n] = x[Ln]; both L and M are integers.

  • MCS-EE Dept Signals & Systems

    Aug 2007 3

    d) Do you see any use of your functions double and half in the above question? e) Convolution: MATLAB has a built-in function for convolution. Explore that function. However, we would like to have an understanding of convolution, and this can be done efficiently by writing our own function for convolution. Lets do it!

    P a t r t I I : T h e S y s t e m s Problem 3: Systems a) What do we mean by a system? Isnt it just a mapping of input to output according to certain rule? Or is it just an application of a fixed transformation on x[n]? How do we characterize systems? Well, some of the ways are: Memoryless vs with memory, Linear vs Non-Linear, Time-Invariant vs Time-varying, Causal vs Non-causal (or Anti-causal), Stable vs Unstable, Invertibel vs Non-invertible. Give an example of each of them and show by implementing and getting the results. b) An LTI system can be completely characterized by its impulse response. The process of transforming an input signal by an LTI system into an output signal is known as Convolution. Can you answer why? or explain how we reach this convolution? [We have to think in both continuous and discrete-time domain, but the distinction between these domains will be clarified in the next lab, inshaAllah.] Write an efficient MATLAB function to convolve two sequences. (By efficiency we mean that we should not use any for loop). Problem 4: Example of a system Lets take an example of a system from the real world. Echo is a phenomenon known by almost all of us. Given a sampled signal contained in the vector x in MATLAB, write a MATLAB function to generate a vector that includes the original signal plus an echo occurring T seconds after the start of the original signal with a gain of a. Use vector operations to avoid time consuming loops. Use some wave file to create an echo signal using your original speech signal and a constant attenuation. You will need to create a signal that is a scaled version of the original and add it to the original with the desired offset in time. Experiment with different values for the time delay and attenuation. Listen to the resulting signals and note your observations. a) Generate a 0.25 sec echo effect. Let gain=0.65. b) Use a non-constant attenuation function, such as an exponential: a(t)=Ae-t/T.

    Determine values of A and T that make an interesting effect. c) Use several different delays and amplitudes to get a variety of echoes. d) Use an oscillatory attenuation function, such as a(t)=Acos(wt). Describe the impact that your choice of time delay and attenuation have on the resulting echo. What happens if the time delay, T changes during the echo generation process?