0% found this document useful (0 votes)
16 views14 pages

MATLAB Signal Plotting Lab Guide

The document outlines an experiment focused on observing and plotting continuous and discrete time signals using MATLAB. It covers various types of signals including impulse, step, ramp, sinusoidal, triangular, sawtooth, and exponential sequences, providing examples of MATLAB code for generating and plotting these signals. The learning outcomes include understanding the differences between continuous and discrete signals and the use of plotting functions in MATLAB.

Uploaded by

Usama Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views14 pages

MATLAB Signal Plotting Lab Guide

The document outlines an experiment focused on observing and plotting continuous and discrete time signals using MATLAB. It covers various types of signals including impulse, step, ramp, sinusoidal, triangular, sawtooth, and exponential sequences, providing examples of MATLAB code for generating and plotting these signals. The learning outcomes include understanding the differences between continuous and discrete signals and the use of plotting functions in MATLAB.

Uploaded by

Usama Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXPERIMENT NO.

3
OBJECTIVE:
Observing continuous and discrete time signals and plotting basic sequences using MATLAB.

LEARNING OUTCOME:
In this lab, students will be able to understand:
• Plotting Continuous and Discrete Time signals
• Generation of Impulse Sequence
• Generation of Step Sequence
• Generation of Ramp Sequence
• Generation of Sinusoidal Sequence
• Generation of Triangular Sequence
• Generation of Saw tooth Sequence
• Generation of Exponential sequences.

1. INTRODUCTION:
In this lab we will study about two different types of signals Continuous-Time Signals and
Discrete-Time Signals. We will also study about Impulse, ramp, and step sequences. We will
see how we can plot Sine, Exponential, and Saw tooth signals.

2. SIGNALS AND THEIR TYPES:


Signals are represented mathematically as functions of one or more independent variables. Here
we focus attention on signals involving a single independent variable. For convenience, this
will generally refer to the independent variable as time.
There are two types of signals: Continuous-time signals and Discrete-time signals.

Continuous-time signal: the variable of time is continuous. A speech signal as a function of


time is a continuous-time signal.

Discrete-time signal: the variable of time is discrete. The weekly Dow Jones stock market
index is an example of discrete-time signal.
Example 1:
Plot continuous Sine wave using MATLAB:
Code:
n = [Link];
z = sin(n/4);
plot(n,z);
title('Continous Sinewave')
xlabel ('time')
ylabel ('sin(n/4)')
Output:

Example 2:
Plot discrete Sine wave using MATLAB:
Code:
n=[Link];
y=sin(n/6);
subplot(3,1,1)
stem(n,y)
title('Discrete-time function');
xlabel('n');
ylabel('sin(n/6)');
Output:
Example 3:
Explain the difference in terms of function and syntax in between Stem and Plot
command.
Function:
Plot display the continuous values of the curves.
Stem display the discrete values the points on the curves.
Plot creates a 2-D line plot of the data in Y versus the corresponding values in X.
Stem plots the data sequence, Y, at values specified by X.
Syntax:
Syntax of both plot and stem are same only the name difference mean keywords
>> Plot(X,Y)
>>Stem(X,Y)

3. UNIT IMPULSE SIGNAL:


The impulse response is generally a short duration time domain signal. A system’s impulse
response (often annotated as h(t) for continuous – time system ) or (h[n] for discrete – time
system ) is defined as the output signal that results in when impulse is applied. Impulse function
is a function that is zero everywhere but at the origin, where it is infinity high. However the
area of impulse is finite. The unit impulse has area = 1, which shows its height.
Example 4:
Generate a unit impulse sequence.
Code:
n = -5:10;
I =[zeros(1,5) 1 zeros(1,10)];
stem(n,I);
title('Unit Impulse Sequence')
xlabel('Time')
ylabel('Amplitude')
axis([-5 10 0 2])
Output:

4. UNIT STEP SEQUENCE:


The unit step function, usually denoted by u, is a discontinuous function whose value is zero
for negative argument and one for positive argument. The function is used in the mathematics
of control theory and signal processing to represent a signal that switches on at a specified time
and stays switched on indefinitely. Mathematically, a continuous time unit step function is
written as.

In discrete form, a unit step function can be mathematically written as

Graphically, unit step sequence is shown in figure below:


Example 5:
Generate a unit step response sequence using MATLAB.
Code:
n = -5:10;
I =[zeros(1,5) 1 ones(1,10)];
stem(n,I);
title('Unit Impulse Sequence')
xlabel('Time')
ylabel('Amplitude')
axis([-5 10 0 2])
Output:

5. RAMP SEQUENCE:
The unit ramp function R(x), is a ramp function with a constant slope of 1. Widely used in
signal processing, the function forms a building block for more complex signals.

Graphically, unit step sequence is shown in figure below:


Example 6:
Generate a unit ramp response sequence using MATLAB.
Code:
n = -5:10;
ramp = n.* (n>=0);
stem(n,ramp, 'fill');
title('Unit Impulse Sequence')
xlabel('Time')
ylabel('Amplitude')
Output:

6. CREATION OF REAL EXPONENTIALS:


Another basic discrete-time sequence is the exponential sequence. Such a sequence can be
generated using the MATLAB.
Code:
n =0: 0.1:1;
x = -10*n;
stem(n,x);
title('Exponential Sequence');
xlabel('Time');
ylabel('Amplitude');
Output:

7. Creation of Complex Exponentials:


Code:
n=0:20
w=pi/6;
x=exp (j*w*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’);
Output:
Lab Task 1:
Write a program in MATLAB to generate Saw tooth Waveform.
Code:
n = 0:100;
z = sawtooth(n/2);
plot(n,z);
title(' Sawtooth wave')
xlabel ('time')
ylabel ('sawtooth(n/2)')
Output:

Lab Task 2:
Write a program in MATLAB to generate a Triangular Pulse
Code:
t=0:0.1:50;
x=sawtooth(t,0.5);
plot(t,x)
title(' Triangular pulse')
xlabel ('time')
Output:

Lab Task 3: Generate following signals:

Lab Task 3(a):


t=[Link];
x=sin((pi/17)*t);
subplot(312)
stem(t,x)
title(' Discrete time wave')
xlabel ('time')
ylabel('sin((pi/17)*t)')

Output:
Lab Task 3(b):
t=-[Link];
x=sin((pi/17)*t);
subplot(312)
stem(t,x)
title(' Discrete time wave')
xlabel ('time')
ylabel('sin((pi/17)*t)')

Output:
Lab Task 4:

a. Create 𝒙[𝒏] = 𝒆(𝒋∗𝒏/𝟑) for some range and see its real and imaginary parts
separately

Code for (a):


n=0:20
x=exp (j*(n/3))
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');
Output:
b. Make the following signals; plot their real and imaginary parts on the same figure.
What difference do you notice between the two signals?

Code for (b):

n=-10:0.1:10
x1=exp ((-0.1+j*0.3)*n)
subplot(2,2,1);
plot(n,real(x1));
xlabel('Time index n');
ylabel('Amplitude');
title('Real part of x1');
subplot (2,2,2);
plot (n,imag(x1));
xlabel('Time index n2');
ylabel('Amplitude');
title ('Imaginary part of x1');
x2=exp ((0.1+j*0.3)*n)
subplot(2,2,3);
plot(n,real(x2));
xlabel('Time index n');
ylabel('Amplitude');
title('Real partof x2');
subplot (2,2,4);
plot (n,imag(x2));
xlabel('Time index n');
ylabel('Amplitude');
title ('Imaginary part of x2');

Output:
Explanation:
In my opinion the only diff is the sign of the real part of the complex number in
the equation. Due to the changing in the real part the second graph is inverted and the imaginary
part is 90-degree phase shift. If the value of ‘i’ is negative then the phase shift will be -90-
degree.
Discussion and Conclusion:
In the lab, we discuss the concepts of the continuous and discrete
time signals and used the plot and stem keywords for wave graph.
stem is used for the plot the discrete time signal graph.
A continuous-time signal has values for all points in time in some (possibly infinite) interval.
It is an analog representation of natural signals. It is defined over a finite or infinite domain of
sequence. These are described by the differential equation. The value of signal can be
obtained at any arbitrary point of signal.
A discrete time signal has values for only discrete points in time. The value of signal can be
obtained at sampling instant of time. It is defined over a finite domain of sequence. The
discrete time signal is digital representation of a continuous time signal.

Common questions

Powered by AI

Analyzing complex exponential signals involves understanding both amplitude variations and phase shifts, which can complicate waveform interpretation. MATLAB aids this process by allowing separate visualization of real and imaginary parts: `n=0:20; x=exp(j*(n/3))`. Using 'stem', separate plotting of real `(real(x))` and imaginary `(imag(x))` components helps clarify their individual contributions, enabling deeper understanding of how these elements affect signal behavior over time. MATLAB's ability to manipulate and plot complex numbers intuitively simplifies analysis of such multifaceted signals .

The impulse response is vital in signal processing as it characterizes a system's response to a very short input, effectively making it possible to understand the system's behavior. For a discrete-time system, the impulse response is illustrated as h[n], representing output when an impulse input is applied. In MATLAB, an impulse sequence can be generated by defining a vector with zeros except for a single one at a desired index. Using the 'stem' function, this sequence is plotted to visualize its discrete nature, which is fundamental for analyzing the system's response characteristics .

The 'sawtooth' waveform in MATLAB is generated using the code: `n = 0:100; z = sawtooth(n/2); plot(n,z);`. This employs the 'sawtooth' function to create a waveform with a 360-degree phase transition repeating every cycle specified by `(n/2)`. This waveform is significant in various applications, including audio synthesis and testing signal processing systems due to its linear rise and quick fall, simulating conditions closer to natural signals and providing useful test signals for system analysis .

The 'stem' function in MATLAB is used for plotting discrete-time signals, displaying them as sequences of stems originating from discrete data points. This is in contrast to the 'plot' function, which is used for continuous data, connecting data points with lines to represent signals over a continuous interval. The 'stem' function highlights the individual discrete values crucial for discrete-time signals, while 'plot' visualizes changes over continuous intervals, ideal for continuous-time signals .

To analyze the real and imaginary parts of complex exponential sequences in MATLAB, create a sequence: `n=0:20; x=exp(j*(n/3));`. Use the 'stem' function for separate plots: `subplot(2,1,1); stem(n,real(x));` for the real part, and `subplot(2,1,2); stem(n,imag(x));` for the imaginary part. This approach allows one to observe how the real and imaginary components evolve, crucial for understanding signal modulation and phase characteristics, as the real part typically affects amplitude while the imaginary part affects phase shift, revealing insights into signal dynamics .

A continuous-time signal is one where the time variable is continuous, allowing it to be defined for all time instances. This type is often used as an analog representation, as in a speech signal, which is naturally continuous. Conversely, a discrete-time signal is defined only at discrete time intervals and cannot represent values between those intervals, making it suitable for digital representations. An example is the weekly Dow Jones stock market index which is recorded at discrete intervals .

The appearance difference in plotting real and imaginary parts of two complex signals can be primarily attributed to the sign of the real component. In MATLAB, use the code: `n=-10:0.1:10; x1=exp((-0.1+j*0.3)*n); x2=exp((0.1+j*0.3)*n);` and plot using `subplot`. The real parts determine amplitude growth (positive) or decay (negative), while imaginary parts cause phase shifts. Consequently, changing the sign in the real component results in one signal being inverted relative to the other, demonstrating their contrast during phase alignments, which is crucial for modulation analysis .

Altering the sign of the real part of a complex exponential equation results in the inversion of its magnitude in the time domain graph. For example, a positive real part signifies exponential growth, while a negative real part results in exponential decay. In practical terms, this change in the real part affects signal attenuation or amplification, impacting its stability and sustainability. It is critical in signal processing to determine whether signals are amplifying towards undesired saturation or diminishing too rapidly affecting signal detection and analysis .

A unit ramp sequence can be generated in MATLAB using the code: `n = -5:10; ramp = n.* (n>=0); stem(n,ramp, 'fill')`. This code creates a vector `n` from -5 to 10 and generates the ramp by zeroing out negative indices and applying a linear increase from zero onwards. The 'stem' function is used to plot the sequence, emphasizing its discrete nature. The significance of the ramp function lies in its role as a building block for creating more complex signals and analyzing response over time, particularly useful in control systems and signal analysis .

Unit step sequences hold significance in control theory and signal processing by representing signals that turn on at a specific time and remain active indefinitely, thereby modeling switching systems or changes in state. In MATLAB, this can be generated using: `n = -5:10; I =[zeros(1,5) 1 ones(1,10)]; stem(n,I);`. This code defines a step sequence from -5 to 10, starting with zeros, transitioning to one, which is plotted using the 'stem' function, visualizing its characteristic step change at zero. Such sequences are used often to analyze system stability and time-response .

You might also like