You are on page 1of 2

clc ; %clear the command window

clear all; %clear the workspace


close all; %clear the windows previously used in matlab (any graphs)

fs=4000; %sampling frequency


ts=1/fs;
%t=0:5 ; %start from 0 to 5 (increment 1)
t = (0:ts:1); %from 0 to 1 (increment by Ts)
f = 4; %analog frequency

x = sin(2*pi*f*t); %define a sine function to output x


hold on
subplot(1,2,1) % 1 row ,2 coloumns , first position
plot (t,x,'r --') %continuos blue line
%plot(t,x,'r--') red and dashed
xlabel('time in seconds') %label of x axis
ylabel('amplitude') %label of y axis
title('sinewave') %title of whole graph
hold on
legend ('sinewave') %to show a box that contain the title , color of each function
%to plot the two functions on one window (cos , sin)
%we define y variable and assign cos into y
axis ([0 1 0 1])
y=cos(2*pi*f*t);
%the program will plot the last plot (over write)
%so we have to use hold on function before first plot function
subplot(1,2,2) % 1 row ,2 coloumns , second position
%to draw two plots separately on one window we use before the plot
%subplot(m,n,p)m: rows , n :coloumns , p : position fisrt or second
plot (t,y)
xlabel('time in seconds') %label of x axis
ylabel('amplitude') %label of y axis
title('cosinewave')%title of whole graph
%we will define each curve by color
hold on
legend ('cosinewave') %to show a box that contain the title , color of each function
%to define the start , end of axis domaim
% we use axis([xmin xmax ymain ymax])
% or to determine the range of values of x axis and y axis
% from 0 to 1
axis ([0 1 0 1])

1
2

You might also like