![]() |
![]() |
|
|
| <<Home | Lab 1 (Signal Generation and Processing) | |||
|
The MATLAB (Matrix Lab) signal processing Toolbox has a large variety of functions for generating continuous-time and discrete time signals. In this lab, we shall learn how to generate some commonly used signals. Generate triangular wave using sawtooth Example 1 Generate a triangular wave of amplitude =1 unit, a frequency of 10л radians per second and a width of 0.5 unit. Solution A=1 w0=10*pi; w=0.5; t=0:0.001:1; tr=A*sawtooth(w0*t+w); plot(t,tr) Result
Generate square wave
Example 2 Generate square wave with amplitude 1, fundamental frequency 10л radian per second and duty cycle =0.5 Solution A=1 w0=10*pi; rho=0.5; t=0:0.001:1; % you may also use linspace here sq=A*square(w0*t+rho); plot(t,sq) axis([0 1 -2 2]) % this is an optional command and helps in clear visualization of the signal Result
Generate discrete time square wave
Example 3 Generate a discrete time square wave, with frequency л /4 radians per second, duty cycle=0.5 and amplitude =1 unit. Solution A=1 w=pi/4; rho=0.5; n = -10:1:10; x=A*square(w*n+rho); stem(n,x) Result
Discrete time triangular wave
Exercise 1(a) Generate a discrete time triangular wave of unity amplitude with width 0.5 and frequency 10л radians per second. Solution A=1 w0=10*pi; w=0.5; t=0:0.001:1; tr=A*sawtooth(w0*t+w); stem(t,tr) Result
Sinusoidal waves
Exercise 1(b) Draw the following sinusoidal signals: (i) Acos(wt+Ø) (ii) Asin(wt+Ø) where A=4 w=20л and Ø = 30 degrees. Note convert degrees into radians. Solution %(i) Acos(wt+Ø) A=4 w0=20*pi; w=30*pi/180; t=0:0.01:2; tr=A*cos(w0*t+w); plot(t,tr) Result
Solution %(ii) Asin(wt+Ø) A=4 w0=20*pi; w=30*pi/180; t=0:0.01:2; tr=A*sin(w0*t+w); plot(t,tr) Result
Exponential signals
Exercise 2 Draw the following signals (a) x(t)=5e-6t (b) y(t)=3e5t (c) x[n] = 2(0.85)n (d) z(t) = 60sin(20л)e-6t (e) y[n] = 60sin(20 л n)e-6n Solution % 2 (a) x(t)=5e-6t z=5; a=-6; t=0:0.001:5; ex=z*exp(a*t); plot(t,ex) Result
Solution % 2 (b) y(t)=3e5t z=3; a=5; t=0:0.001:5; ex=z*exp(a*t); plot(t,ex) Result
Solution % 2 (c) x[n] = 2(0.85)n z=2; a=0.85; n=0:0.01:10; xn=z*a.^n; stem(n,xn) Result
Solution % 2 (d) z(t) = 60sin(20л)5e-6t B=60; a=20*pi; c=-6; t=0:0.001:2; x= B*sin(a*t).*exp(c*t); plot(t,x) Result
Solution % 2 (e) y(n)=60sin(20 л n)5e-6n B=60; a=20*pi; c=-6; n=0:0.1:2; xn= B*sin(a*n).*exp(c*n); stem(n,xn) Result
Ones function
Example 4 A Discrete time unit step function may be created as follows Solution n=0:1:20; x=ones(1,length(n)); stem(n,x) axis([-1 25 0 2]) % optional Result
Discrete time signals
Exercise 3a Draw the following discrete time functions a (i) x[n] = n (ramp function) a (ii) x[n] = δ[n] (impulse function) Solution % a (i) x[n] = n (ramp function) n = 0:1:20; x = n; stem(n,x) Result
Solution % a (ii) x[n] = δ[n] (impulse function) n = -2:1:2; x = [0 0 1 0 0]; stem(n,x) Result
Different signals
Exercise 3b Get help for the built -in function "sinc" and here plot sinc function (i.e. sin(x)/x) for x between -5 to 5. Solution % (sinc function) x = -5:1:5; y = sinc(x); plot(x,y) Result
Different signals
Exercise 3c Plot a rectangular function of width 3 units. (use built -in function "rectpuls". Solution % (rectpuls function) t = -5:1:5; w =3; y = rectpuls(t,w) stem(t,y) Result
Different signals
Exercise 3d Draw a discrete time triangular pulse using the built -in function "tripuls". Solution % (tripuls function) t = -5:1:5; w =3; y = tripuls(t,w) stem(t,y) Result
Different signals
Exercise 3e Find and plot u[n]-u[n-5], where u[n] is a discrete time unit step signal. Solution % (Unit step function) n=0:1:20; x=ones(1,length(n)-length(n-5)); stem(n,x) Result
Discrete time signals
Exercise 4 Plot the discrete time signal x[nT] = 4n/(2+n^2), T=2. On the same graph paper, plot the following: a. x[nT], T=3 b. x[nT] = 0.5 c. x[(n+4)T], T=2 d. x[(n-2)T], T=0.75 Solution A=4; B=2; n=-10:2:10; xn= A*n./( 2 + n.^2); stem(n,xn) Result
Solution % exercise 4a for T=3 A=4; B=2; n=-10:3:10; xn= A*n./( 2 + n.^2); stem(n,xn) Result
Solution % exercise 4b for T=0.5 A=4; B=2; n=-10:0.5:10; xn= A*n./( 2 + n.^2); stem(n,xn) Result
Solution % exercise 4c for x[(n+4)T, T=2 A=4; B=2; n=-10:2:10; xn= A*(n+4)./( 2 + (n+4).^2); stem(n,xn) Result
Solution % exercise 4d for x[(n-2)T, T=0.75 A=4; B=2; n=-10:0.75:10; xn= A*(n-2)./( 2 + (n-2).^2); stem(n,xn) Result
Continuous time signals
Exercise 5 Plot the continuous time signals x(t) = t/t2 + 4). On the same graph pager, plot the following: 1. x(1.5t) 2. x(0.8t) 3. x(t+3.6) 4. x(2t-1) Solution t=-10:1:10; x= t/(t.^2 +4); plot(t,x) Result
Solution % 1). x(1.5t) t = -10:1:10; x = 1.5* t/((1.5*t).^2 +4); plot(t,x) Result
Solution % 2). x(0.8t) t = -10:1:10; x = 0.8* t/((0.8*t).^2 +4); plot(t,x) Result
Solution % 3). x(t+3.6t) t = -10:1:10; x = (t + 3.6*t)/((t + 3.6*t).^2 +4); plot(t,x) Result
Solution % 4). x(2t -1) t = -10:1:10; x = (2*t - 1)/((2*t - 1).^2 +4); plot(t,x) Result
Continuous time signal
Exercise 6 A=1 w0=10*pi; w=2; t=-1:0.001:1; tr=A*sawtooth(w0*t+w); plot(t,tr)
HELP PLOT
PLOT Linear plot. STEM
STEM Discrete sequence or "stem" plot.
SAWTOOTH
SAWTOOTH Sawtooth and
triangle wave generation. SQUARE
SQUARE Square wave generation. ONES
ONES Ones array. SINC
SINC Sin(pi*x)/(pi*x) function. RECTPULS
RECTPULS Sampled aperiodic rectangle generator.
TRIPULS Sampled aperiodic triangle
generator. DSP Lab 1 DSP Lab2 DSP Lab 3 DSP Lab4 DSP Lab 5 DSP Lab 6 DSP Lab7 DSP Lab8 DSP Lab9 DSP Lab10 DSP Lab 11 Other material |
||||
| <<Home | ||||
|
||||||