0% found this document useful (0 votes)
37 views6 pages

DSP First Experiment

Uploaded by

OM NARAYAN SINGH
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)
37 views6 pages

DSP First Experiment

Uploaded by

OM NARAYAN SINGH
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
You are on page 1/ 6

EXPERIMENT – 1

AIM: Introduction to MATLAB.

THEORY: MATLAB stands for "MATrix LABoratory", which reflects its origins as a tool for matrix operations and linear
algebra. However, it has evolved into a much more powerful tool that supports a wide range of numerical and
computational tasks. It allows users to perform various computational tasks such as data analysis, signal processing, and
image and video processing. MATLAB also provides a variety of toolboxes that extend its capabilities for specific
application domains, such as control systems, statistics, and optimization.
MATLAB's programming language is designed to be easy to learn and use, and it supports a variety of programming
paradigms, including procedural, object-oriented, and functional programming. It also has a rich set of built-in functions
and commands, which can be used to perform common tasks and operations.
MATLAB's interactive environment allows users to enter commands and see immediate results, which makes it useful
for exploratory work and rapid prototyping. It also supports the creation of custom graphical user interfaces (GUIs) and
the development of standalone applications.
Overall, MATLAB is a powerful and versatile tool that has become an indispensable part of many scientific and
engineering workflows.

WINDOWS:

1. COMMAND WINDOW
The command window in MATLAB is a powerful
interactive interface that allows you to execute
commands, display and analyze data, and interact with
the MATLAB environment. It is the main window in
MATLAB, and it appears by default when you start
MATLAB.
You can use the command window to enter and execute
commands in MATLAB. This makes it a powerful tool for
exploring data, performing calculations, and testing code.
For example, you can use the command window to
create variables, define functions, load data from files,
and generate plots. The results of executed commands
are displayed in the command window, including any
error messages that may occur.
In addition to executing commands, the command
window also provides a number of other features that
make it a powerful tool for working with MATLAB. For example, the command history is stored in the command
window, allowing you to recall and execute previously executed commands. The command window also supports
command-line editing, which makes it easy to correct mistakes and modify previous commands. Another useful feature
of the command window is the ability to save commands and output to a file.
Overall, the command window in MATLAB is a powerful and flexible tool that is essential for working with MATLAB. It
allows you to interact with the MATLAB environment in a flexible and efficient manner, making it easier to perform data
analysis, modelling, and simulation tasks.
2. EDITOR WINDOW

The Editor window in MATLAB is a text editor that


allows you to create, edit, and save MATLAB code files.
It is a powerful tool for writing and editing MATLAB
code, as it provides many features that enhance
productivity and code quality. Some of the features of
the Editor window include syntax highlighting, auto-
indentation, code folding, and debugging tools.
Syntax highlighting is a feature that highlights different
elements of the code in different colors, making it
easier to read and understand the code. Auto-
indentation automatically indents code as you type,
making it easier to keep the code organized and
readable. Code folding allows you to collapse and
expand code sections, which is useful when working with long files. Debugging tools, such as breakpoints and variable
inspection, allow you to debug your code directly within the editor.
The Editor window also provides integration with other MATLAB tools, such as the Command Window and the
Workspace. You can execute code directly from the Editor window and see the results in the Command Window, and
you can access and modify variables in the Workspace. Additionally, the Editor window supports version control,
allowing you to manage your code files using Git, Subversion, or other version control systems. Overall, the Editor
window is an essential tool for writing and editing MATLAB code, providing many features that improve productivity and
code quality.

3. FIGURE WINDOW
The Figure window in MATLAB is a graphical window that
is used to display plots, graphs, and other visualizations.
It is the primary output mechanism for creating
visualizations in MATLAB.
You can create a Figure window using the "figure"
command in MATLAB. Once you have created a Figure
window, you can use MATLAB commands to create and
modify visualizations. This might include commands to
plot data, create bar charts, or generate scatter plots.
The Figure window can display multiple plots
simultaneously, each in its own axis or subplot.
The Figure window provides many customization options
to modify the appearance of visualizations. For example,
you can change the colours and styles of lines, add labels and titles to the plot, and adjust the size and layout of the plot.
You can also add other graphical elements, such as text annotations, arrows, and shapes.
In addition to modifying the appearance of visualizations, the Figure window provides interactive tools to explore and
analyze data. For example, you can use the data cursor tool to view the values of individual data points, or use the zoom
and pan tools to focus on specific parts of a plot.
The Figure window also supports saving plots in a variety of formats, including JPEG, PNG, PDF, and MATLAB figure files.
This allows you to share your visualizations with others or to include them in reports or presentations.
Overall, the Figure window in MATLAB is a powerful and flexible tool for creating visualizations of data. It provides a
wide range of customization and interactive options that allow you to create professional-quality plots and graphs, and
is an essential tool for anyone working with data in MATLAB.
COMMANDS:
There are several types of commands that you can give in MATLAB.
The most common types of commands include:

1) Assignment commands: Used to assign values to variables. For example, x = 5.

2) Arithmetic commands: Used to perform mathematical operations on variables or values. For example, x + y or
sin(x).

3) Control flow commands: Used to control the flow of execution in a program. This includes commands like "if",
"for", "while", and "switch".

4) Input/output commands: Used to read or write data to and from files, or to interact with the user. For example,
input() or fprintf().

5) Graphics commands: Used to create plots and visualizations. This includes commands like plot(), scatter(), and
imshow().

6) Function commands: Used to create user-defined functions that can be called from other parts of a program.
For example, function [y] = myfunction(x).

7) System commands: Used to interact with the operating system, such as running external programs or accessing
system variables. This includes commands like system() or getenv().

These are just some of the most common types of commands that you can use in MATLAB. Depending on your specific
use case, there may be other types of commands that you need to use as well.

PLOTS:
MATLAB provides a wide variety of plot types for creating visualizations of data. Here are some of the most common
types of plots in MATLAB:

1. Line plots: These plots show data as a series of points connected by lines. The plot function is used to create line
plots in MATLAB.
2. Scatter plots: These plots show data as a collection of points, with each point representing a single observation.
The scatter function is used to create scatter plots in MATLAB.
3. Bar plots: These plots show data as bars of different heights, with each bar representing a category or group.
The bar function is used to create bar plots in MATLAB.
4. Histograms: These plots show the distribution of a set of values by grouping them into bins and counting the
number of values in each bin. The histogram function is used to create histograms in MATLAB.
5. Pie charts: These plots show the relative proportions of different categories in a dataset as wedges of a pie. The
pie function is used to create pie charts in MATLAB.
6. Heatmaps: These plots show the intensity of data values as a color map, with each color representing a
different range of values. The heatmap function is used to create heatmaps in MATLAB.
7. Contour plots: These plots show the contours of a function of two variables, with each contour representing a
particular level of the function. The contour function is used to create contour plots in MATLAB.

These are just a few examples of the types of plots that can be created in MATLAB. Depending on your specific needs,
there may be other plot types or variations of these plot types that you can use as well.
EXPERIMENT – 2

AIM: Plotting basic signals using MATLAB.


THEORY: In communication engineering, signals are physical quantities or variations in a physical quantity that carry
information. Signals are used to convey information from a sender to a receiver over a communication channel.

Signals can be of various types, including analog and digital signals. Analog signals are continuous-time signals that vary
continuously over time, while digital signals are discrete-time signals that take on only specific values at specific points
in time. Signals can also be periodic or non-periodic, deterministic or stochastic, and can be represented in various
forms such as sine waves, square waves, pulses, and more.

In communication systems, signals are often modified or processed to improve their quality or to extract information
from them. This can involve operations such as filtering, modulation, demodulation, and encoding/decoding. The choice
of signal processing techniques depends on the specific communication system and the nature of the signals being
transmitted.

SIGNALS:

1. SINE WAVE
A sine wave is a mathematical function that describes a smooth, repetitive oscillation. It has a shape that
resembles a wave, with peaks and valleys that repeat over a period of time. The mathematical equation for a
sine wave is y(t) = A sin(2πft + φ), where A is the amplitude of the wave, f is the frequency, t is time, and φ is the
phase shift.

CODE:
t = 0:0.01:2*pi;
% time values (from 0 to 2*pi, in steps of 0.01)

y = sin(t); % sine wave values

plot(t,y); % plot the sine wave


xlabel('Time (s)'); % label the x-axis
ylabel('Amplitude'); % label the y-axis
title('Sine Wave'); % add a title to the plot

2. COSINE WAVE
A cosine wave is similar to a sine wave, but is shifted in phase by 90 degrees (or π/2 radians) relative to the sine
wave. The mathematical equation for a cosine wave is y(t) = A cos(2πft + φ).

CODE:
t = 0:0.01:2*pi; % time values (from 0 to 2*pi, in steps of 0.01)
y = 2*cos(2*t); % cosine wave values

plot(t,y); % plot the cosine wave


xlabel('Time (s)'); % label the x-axis
ylabel('Amplitude'); % label the y-axis
title('Cosine Wave'); % add a title to the plot
3. EXPONENTIAL WAVE
An exponential wave, also known as an exponential function, is a signal that grows or decays exponentially over
time. Mathematically, an exponential function is represented as y(t) = A e^(αt), where A is the amplitude of the
signal, α is a constant called the growth or decay rate, t is time, and e is the base of the natural logarithm.
If α is positive, the signal grows exponentially, increasing in amplitude over time. If α is negative, the signal
decays exponentially, decreasing in amplitude over time.

CODE:
t = 0:0.01:5; % Generate time vector

A = 1; % Calculate exponential
wave
tau = 0.5;
y = A * exp(-t/tau);

plot(t, y); % Plot wave


title('Exponential Wave');
xlabel('Time (s)');
ylabel('Amplitude');

4. UNIT IMPULSE SIGNAL


A unit signal is a signal that has a value of 1 at a specific instant of time and is zero elsewhere. A unit signal is
often used as a building block for constructing more complex signals.
There are different types of unit signals, depending on the type of signal being considered. For example, in a
continuous-time signal, a unit impulse is a signal that has infinite amplitude and zero duration, except at the
point where it takes the value of 1. In a discrete-time signal, a unit sample is a signal that has a value of 1 at a
specific time instant and is zero elsewhere.
Unit signals are important in signal processing because they
can be used to represent more complex signals as a sum of
scaled and shifted unit signals.

CODE:
n = 0:9; % Generate unit signal
x = [zeros(1,4),1,zeros(1,5)];

stem(n, x); % Plot signal


title('Unit Impulse Signal');
xlabel('Sample');
ylabel('Amplitude');

5. UNIT STEP SIGNAL


A unit step signal, also known as the Heaviside step function or simply step function, is a mathematical function
that has a value of zero for negative inputs and a value of one for non-negative inputs.

CODE:
n = -10:10; % Define the range of values for signal
u = n >= 0; % Generate the unit step signal
stem(n,u); % Plot the signal using the stem function
xlabel('n');
ylabel('u[n]');
title('Unit Step Signal');
6. RAMP WAVE
In signal processing, a ramp signal is a type of signal that has linearly increasing or decreasing amplitude over
time. It is also known as a slope or linear signal. Mathematically, a ramp signal can be defined as:

ramp(t) = at + b

where a is the slope or rate of change of the signal, and b is the initial value of the signal at t = 0.

A ramp signal with a positive slope increases in amplitude over time, while a ramp signal with a negative slope
decreases in amplitude over time. The slope of the ramp signal determines the rate at which the amplitude
changes.

CODE:
t = 0:0.1:10; % Generate time vector

m = 0.5; % Calculate ramp signal


b = 0;
y = m*t + b;

plot(t, y); % Plot signal


title('Ramp Signal');
xlabel('Time (s)');
ylabel('Amplitude');

7. SINC WAVE
The sinc waveform is a periodic function that has a main lobe centered at x = 0 and smaller side lobes on either
side of the main lobe. The amplitude of the sinc waveform is highest at x = 0 and decreases as x moves away
from zero. The width of the main lobe and the amplitude of the side lobes depend on the length of the
waveform and the sampling rate used to generate it.
Formula for sinc signal is: sinc(x) = sin(x) / x

CODE:

clc
clear all
close all

t=-5:0.001:5;

xct=(t>=-1)-(t>=1); %square pulse


plot (t, xct);
figure;

w=-4*pi:0.01:4 pi;
for i=1:length (w)
xcw(i)=trapz (t, xct. *exp(-li*w(i).*t)); %fourier transform
end
plot(w, abs (xcw));
xlabel('w');
ylabel('absolute of sinc waveform');
grid on;

RESULT:

Basic signals used in signal processing such as sine, cosine, exp. signals were plotted on MATLAB.

You might also like