Professional Documents
Culture Documents
Title: - Implement algorithm to perform sin, cos, and exponential on single graph.
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
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:
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.