LAB - 07 - 7th Semester Notes

advertisement
Laboratory 7: Cover Sheet
Laboratory Objectives:


Familiarization with the Common Sequences: Unit Impulse, Unit Step, and Unit
Ramp
To understand generation of sinusoidal and exponential sequence

To understand the periodicity property of Digital frequency (frequency of discrete
time sinusoid)

To understand Amplitude Modulation using Square Wave with a Cosine Wave
Place a check mark in the Assigned column next to the exercises your instructor has
assigned to you. Attach this cover sheet to the front of the packet of materials you submit
following the laboratory.
Activities
Remarks
Signature
Pre-lab Exercises
In-lab Exercises
Take Home Exercises
Any Other
74 | P a g e
Discrete-Time (DT) Signals Time Domain
Representation
A signal can be broadly defined as any dependent quantity that varies as a function of some
independent variable (e.g. time, frequency, space, etc.) and both has a physical meaning and
has the ability to convey information.
Examples

Electrical signals (Radio communications signals, audio and video etc).

Mechanical signals (vibrations in a structure, earthquakes).

Biomedical signals (EEG, lung and heart monitoring, X-ray etc).
A system can be represented mathematically as a transformation between two signal sets, as
in x[n] ∈S1 → y[n] = T{x[n]} ∈ S2
Depending on the nature of the signals on which the system operates, different basic types
of systems may be identified:
-
Analog or continuous-time system: the input and output signals are analog in nature.
-
Discrete-time system: the input and output signals are discrete.
-
Digital system: the input and outputs are digital.
-
Mixed system: a system in which different types of signals (i.e. analog, discrete
and/or digital) coexist.
Signals can be either continuous-time (CT) or Discrete-time (DT). Signals normally
occurring in nature (e.g. speech) are continuous in time as well as amplitude. Such signals
are called Analog signals. DT signals have values defined at only discrete instants of time.
These time instants need not be equidistant, but in practice, they are usually taken at equally
spaced intervals for computational convenience and mathematical tractability. If amplitude
of DT signal is also made discrete through process of quantization or rounding off, then this
becomes a Digital Signal. Digital Signal Processing (DSP) is concerned with digital
processing of signals.
75 | P a g e
An analog signal is denoted as x(t). To emphasize its discrete time nature, a DT signal is
denoted as x(n), instead of x(t).
A discrete-time signal x(n) is a function of an independent variable n, which is an integer. A
discrete-time signal is not defined at instants between two successive samples. A discretetime signal is represented as a sequence of numbers, called samples. A sample value of a
typical discrete-time signal or sequence {x[n]} is denoted as x[n] with the argument n being
an integer in the range −∞ and ∞. The following methods are in use to illustrate the Digital
signals
where the bar on top of symbol 1 indicates origin of time (i.e. n = 0)
Graphical Representation
Mathematical expression:
Sequence Representation
Tabular Representation
𝒏
𝟎 𝟏 𝟐𝟑
𝟏𝟏𝟏
𝒙(𝒏) 𝟏
𝟐𝟒𝟖
A set of rules that transforms one discrete signal into another is known as an algorithm and
this transformation is what we call Discrete-time signal processing or Digital signal
processing (DSP).
76 | P a g e
Section A
GENERATION OF UNIT SAMPLE AND UNIT SEPT SIGNALS
Unit Sample Sequence
Unit Sample Sequence is often called the discrete time impulse or the unit impulse. It is
denoted by δ[n] and is defined as
Generation of Unit Sample Sequence
% Generation of a Unit Sample Sequence
clf; %Clear current figure window
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) 1 zeros(1,20)];
% Plot the unit sample sequence
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 20 0 1.2])
s= (n==0); %Following command will also generate unit sample sequence
Generation of Unit Sample Sequence using user input option
% Generation of a Unit Sample Sequence
clf; %Clear current figure window
% Generate a vector from -10 to 20
n = -10:30;
% Generate the unit sample sequence
u = [zeros(1,10) .8 zeros(1,30)];
subplot(211); stem(n,u)
k=input('Give the number of places to shift the signal right (delay) or
left (advance) i.e. +ve or -ve (number has to be within the range of -10
to 30)=');
subplot(212);% Plot the unit sample sequence
stem(n+k,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
77 | P a g e
axis([-10 20 0 1.2])
s=(n==0); %Following command will also generate unit sample sequence
Matlab Notes:

K=input(‘text’) Request user input and it prompt the use in the text string and then
waits for input from the keyboard. The value entered by the user is assigned to k.

B=zeros(n) return an n-by-n matrix of zeros similarly for ones.
Unit Step Sequence:
The unit step function is one of the most important functions used by mathematicians and
engineers in the analysis and design of continuous-time systems. In addition to being useful,
step functions also provide a way to “turn on” and “turn off” other functions as well, due to
its “on-off” characteristics. Thus, we can think of step functions as mathematical switches.
The unit step sequence , denoted by µ[n], is defined by
Generation of Unit Step Sequence
% Generation of a Unit Step Sequence
clf;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit step sequence
s = [zeros(1,10) ones(1,21)];
% Plot the unit step sequence
stem(n,s);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Step Sequence');
axis([-10 20 0 1.2])
u=(n>=0)% Following command will also generate unit step sequence
78 | P a g e
Unit Ramp
The ramp function, denoted by ur( n) is a signal whose amplitude increases proportionally
as time increases
Generation of a Unit Ramp
% Generation of a unit ramp signal
clf;
m=0:1:10;
% Generate the unit ramp signal
x5=m;
stem(m,x5);
xlabel('Time index n');ylabel('Amplitude');
legend('ramp')
title('Unit Ramp Signal');
u=m % Following command will also generate unit ramp signal
Exponential Sequence
Another basic discrete-time sequence is the exponential sequence. Such a sequence can
begenerated using the MATLAB operators .^ and exp.
The exponential sequence is a signal whose amplitude exponentially increases or
exponentially decreases, depending on the value of a, as time approaches infinity.
x(n)  a n for n  0
79 | P a g e
Generation of a Real Exponential Sequence
% Generation of a real exponential sequence
clf;
n = 0:35; a = 1.2; K = 0.2;
x = K*a.^n;
stem(n,x);
xlabel('Time index n');ylabel('Amplitude');
legend('Real Exponential')
title('Real Exponential Sequence');
when,
a  re j 2f  
then the complex exponentia l signal becomes :
x(n)  r n cos2f   n  j sin 2f   n
such that,
xR (n)  r n cos2f   n
xI (n)  r n sin 2f   n
and we can plot the m both seperately
Also,
x(n)  A(n)  r n
is the magnitude
Angx(n)   (n)  2f   n
is the phase function
function
of the complex signal
of the complex signal
Generation of a Complex Exponential Sequence
% Generation of a complex exponential sequence
clf;
c = -(1/12)+(pi/6)*i;
K = 2;
n = 0:40;
x = K*exp(c*n);
subplot(2,1,1);
stem(n,real(x));
xlabel('Time index n');ylabel('Amplitude');
title('Real part');
subplot(2,1,2);
stem(n,imag(x));
xlabel('Time index n');ylabel('Amplitude');
title('Imaginary part');
80 | P a g e
Sinusoidal Sequence
Another very useful class of discrete-time signals is the real sinusoidal sequence.
Such sinusoidal sequences can be generated in MATLAB using the trigonometric operators
cos and sin
x[n] = A cos[(ω0 + 2π r )n + φ]
= A cos(ω0n + φ).
Generation of a Sinusoidal Sequence
% Generation of a sinusoidal sequence
n = 0:40;
f = 0.1;
phase = 0;
A = 1.5;
arg = 2*pi*f*n - phase;
x = A*cos(arg);
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 40 -2 2]);
grid
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
81 | P a g e
Periodicity Property of Digital Frequency (frequency of
discrete time sinusoid)
Digital Frequency (that of DT sinusoid) has the range 0 to 2 pi and starts repeating itself
after 2 pi. This is different from Analog frequency which is unique from 0 till
repetition.
∞ without
n=[0:1023] %1024 samples
freq1=pi/4; %frequency
x1=2*sin(freq1*n) %sine wave of 1024 samples, pi/4 radian/sample frequency
and amplitude of 2
figure(1);stem(n(1:30),x1(1:30)); grid
freq2=9*pi/4; %(2*pi+freq1)condition of periodicity
x2=2*sin(freq2*n); %sine wave of 1024 samples, 9*pi/4 radian frequency
figure(2);
subplot(2,1,1);
stem(n(1:30),x1(1:30)); ylabel('x1');grid
subplot(2,1,2);
stem(n(1:30),x2(1:30)); ylabel('x2');grid; %compression of x1 & x2
xlabel('n');
Amplitude Modulation using Square Wave with a Cosine Wave
n=0:199;
f=0.1;
phase=0;
a=1.5;
arg=2*pi*f*n+phase;
x=a*cos(arg);
s1=[zeros(1,20) ones(1,20) zeros(1,20) ones(1,20) zeros(1,20) ones(1,20)
zeros(1,20) ones(1,20) zeros(1,20) ones(1,20)];
%'s1' is a square wave sequence of unit amplitude
% Another command square can also be used to generate s1
z=x.*s1; %modulation is achieved by point to point multiplication
subplot(3,1,1); stem(n,x); grid
subplot(3,1,2); stem(n,s1); grid
subplot(3,1,3); stem(n,z); grid
axis([0 200 -2 2])
xlabel('time index n'); ylabel('Modulated Signal');
title('Amplitude Modulation Sequence');
82 | P a g e
LAB Assignments
1.
Practice all the examples in the Lab Manual
2.
Generate a delayed unit sample sequence ud[n] with adelay of 11 samples. Run the
modified program and display the sequence generated.
3.
Generate a delayed unit step sequence sd[n] with an advance of 7 samples. Run the
modified program and display the sequence generated.
4.
Create a simple m-file that creates a unit sample, unit step, and unit ramp function
for a sequence of length 15. Use a for loop to generate the ramp sequence. Then
plot them all on the same axes with a stem plot. Add a legend. The final result
should be as shown below. Note that the legend command for a stem plot is given as:
legend('sample', 'step', 'ramp')
5. Generate the complex-valued exponential sequence. Which parameter controls the
rate of growth or decay of this sequence? Which parameter controls the amplitude of
this sequence? What will happen if the parameter c is changed to (1/12)+(pi/6)*i
6. Generate a sinusoidal sequence of length 50, frequency 0.08, amplitude 2.5, and
phase shift 90 degrees and display it. What is the period of this sequence?Now
display result using stem, plot and stairs commands. Comment on your results.
7. What is the difference between the arithmetic operators ^and. ^?
8. What are the purposes of these commands:
legend
real
imag
83 | P a g e
9. Plot the figure shown below and explain what is happening.
84 | P a g e
Download