You are on page 1of 4

Experiment - 3

Title: - Implement algorithm to perform sin, cos, and exponential on single graph.

NAME: Akshay Dhawale

Div.: ET-B

Roll no. 7

Problem Statement:
To generate:
1)Sin wave form
2)Cos wave form
3)Exponential wave form when alpha value is less than one
4)Exponential wave form when alpha value is greater than one

Software used for stimulation:

 MATLAB is a high-performance language for technical computing. It integrates computation,


visualization, and programming in an easy environment where problems and solutions are
represented in simple mathematical notation. MATLAB is a software that can be used for a
range of applications, including signal processing, communications, image, and video
processing, etc. In this tutorial, we will show you how to plot a sine or cosine wave in
MATLAB. The code for plotting both the functions is almost similar.
 The plot function in MATLAB can be used to create a graphical representation of data. It is one
of the most important functions in MATLAB, which also happens to be one of the easiest
functions to learn how to use. These plots can be in 2-D or 3-D as lines, surfaces, or meshes.
You can create plots in Cartesian or polar coordinates. You also can create animated plots.

Theory:

The plot function in MATLAB usually takes two arguments, the first is the X values of the points to plot,
and the second is the Y value of the points to plot. The values of X for both the graphs will be the same,
we will only change the values of Y by changing the equation for each wave. The maximum amplitude of
the wave is set to 7 on the Y-axis. On the X-axis we will plot time and the maximum time. we have
assigned is 10 seconds.

“X label” and “Y label” command will provide labels to the axis of the graph. The “title” command will
provide a title for the graph. Similarly, if you want to put a checker grid over the graph to make it easier
to see values then use the “Grid” command in the code.
Procedure
1) Open MATLAB Software, go to the “NEW” option on the Toolbar and then select
“SCRIPT”. A new window will open where you can write the code.
2) As a good coding practice, clear the command window (CLC), the workspace (Clear all)
& any external operative window (Close all).
3) Define the time period/axis of the signal. Here we have taken a time period of 10 sec (0-
10) with a step size of 0.01ms.
4) Set the amplitude & frequency of the signal.
5) Enter sine wave equation (a*sine(2πft)) with all the set variables.
6) Enter Cosine wave equation (a*cos(2πft)) with all the set variables.
7) Enter exponential wave equation with all the set variables.
8) Enter plot function (plot (x-axis variable ,y- axis variable)) & click RUN.
9) Additionally, you can create subplots using the subplot( m, n, p ) command to view both
functions in a single figure.

Code:
%sin, cos, expo.. wave forms
clc;
clear all;
close all;
F=5;
Fs=1000;
Ts=1/Fs;
t=0:Ts:1;
x=sin(2*pi*F*t);
subplot(2,2,1)
plot(x);
xlabel('Time');
ylabel('Amplitude');
title('Sin Wave');
y=cos(2*pi*F*t);
subplot(2,2,2)
plot(y);
xlabel('Time');
ylabel('Amplitude');
title('Cos Wave');
%Continue…
n=-10:10;
alpha =0.9;
xn=alpha.^n;
subplot(2,2,3)
plot(n,xn)
xlabel('Time');
ylabel('Amplitude');
title('Exponential(alpha<1)');
n=-10:10;
alpha =1.5;
xn=alpha.^n;
subplot(2,2,4)
plot(n,xn)
xlabel('Time');
ylabel('Amplitude');
title('Exponential(alpha>1)');

Result:
Application:

 We can plot the graph of other functions in this software.


 We can alter the values in the code to see the effect it will have on the graph.
 Perfect for introducing beginners to the concept of plots in MATLAB.

Conclusion:
In this lab we studied about different sin, cos and exponential waves to generate in MATLAB.
We also learned about how to generate the graphs on single frame using subplot functions. We
also seen varying exponential equation by changing the alpha values from 0 to 1.5 and seen the
varying graphs.

You might also like