0% found this document useful (0 votes)
31 views

Experiment 1 Basic Signal

This document describes MATLAB code to generate continuous and discrete time sinusoidal signals (sine and cosine waves) through plotting functions like plot(), stem(), and subplot(). It includes code to generate a continuous sine wave, discrete sine wave, plot them together using hold on/off, or separately using subplot(). Similar code is provided for continuous and discrete cosine waves. The aim is to familiarize the user with generating and visualizing different time domain signal representations in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Experiment 1 Basic Signal

This document describes MATLAB code to generate continuous and discrete time sinusoidal signals (sine and cosine waves) through plotting functions like plot(), stem(), and subplot(). It includes code to generate a continuous sine wave, discrete sine wave, plot them together using hold on/off, or separately using subplot(). Similar code is provided for continuous and discrete cosine waves. The aim is to familiarize the user with generating and visualizing different time domain signal representations in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

EXPERIMENT 1

AIM : To Generate continuous time and Discrete time sinusoidal signal, cosine signal.
Requirements : Computer with MATLAB software

% Program for generation Continuous time sinusoidal signal


t = 0:0.01:2; % sample points from 0 to 2 in steps of 0.01
x = sin(2*pi*t); % Evaluate sin(2 pi t) , here amplitude=1
plot(t,x,’b’); % Create plot with blue line
xlabel(’t in sec’);
ylabel(’x(t)’); % Label axis
title(’Plot of sin(2\pi t)’); % Title plot

Figure1.1

In figure 1.1 t= 0:0.01:2 , It shows that curve stars from zero and end at 2 with values at interval of
0.01

The time period and amplitude of the generated sine wave can be changed by changing the
corresponding parameters as shown in figure 1.2.

Figure 1.2

In figure 1.2, t=0:0.05:4 It shows that curve stars from zero and end at 4 with values at interval of
0.05

Generation of discrete time sinusoidal signal


For plotting a set of discrete numbers (or discrete-time signals), we will use the stem command
which displays data values as a stem, that is, a small circle at the end of a line connecting it to the
horizontal axis. The circle can be open (default) or filled (using the option ’filled’). Using Handle
Graphics (MATLAB’s extensive manipulation of graphics primitives), we can resize circle markers. The
following set of commands displays a discrete-time sine function using these constructs.

% Program for generation of discrete time sinusoidal signal. (Results – Figure 1.3.)
n = 0:0.05 :2 ; % sample index from 0 to 2
x = sin(2*pi*n); % Evaluate sin(0.2 *pi*n)
y=stem(n,x,'b','filled'); % Stem-plot with handle y
set(y,'markersize',4); % Change circle size
xlabel('n'); ylabel('x(n)'); % Label axis
title('discrete time plot of sin 2\pin'); % Title plot
Figure1.3.

MATLAB provides an ability to display more than one graph in the same figure window. By means of
the hold on command, several graphs can be plotted on the same set of axes. The hold off command
stops the simultaneous plotting. The following MATLAB fragment (Figure 1.4) displays graphs in
Figures 1.1 and 1.3 as one plot, depicting a “sampling” operation that we will study later.

% Program for generation of continuous and discrete time sinusoidal signal simultaneously.
t=0:0.05:2;
x= sin(2*pi*t);
plot(t,x,'b');
hold on
n=0:0.05:2;
x=sin(2*pi*n);
y=stem(n,x,'b','filled');
set(y,'markersize',4);
xlabel('t/n');
ylabel('x(t)/x(n)');
title('simultaneous plot of sin(2\pit)and its samples');

Figure1.4
Another approach is to use the subplot command, which displays several graphs in each individual
set of axes arranged in a grid, using the parameters in the subplot command. The following fragment
(Figure 1.5) displays graphs in Figure 1.1 and 1.3 as two separate plots in two rows. ...

subplot(2,1,1); % Two rows, one column, first plot


plot(t,x,’b’); % Create plot with blue line ...
subplot(2,1,2); % Two rows, one column, second plot
Hs = stem(n,x,’b’,’filled’); % Stem-plot with handle Hs

% Program for simultaneous generation of continuous and discrete time sinusoidal signal. (Results
– figure 1.5)
t=0:0.05:2;
x= sin(2*pi*t);
subplot(2,1,1);
plot(t,x,'b');
xlabel('t in sec');
ylabel('x(t)');
title(' continuous time Plot of sin(2\pit)');

n=0:0.05:2;
x=sin(2*pi*n);
subplot(2,1,2);
y=stem(n,x,'b','filled');
set(y,'markersize',4);
xlabel('n');
ylabel('x(n)');
title('discrete time plot of sin2\pit');

Figure 1.5.
% Generation of continuous time cosine wave (Figure 1.6.)
t=0:0.05:2;
x=cos(2*pi*t);
plot(t,x,'b');
xlabel('t in sec');
ylabel('x(t)');
title('continuous time plot of cos(2\pit)');

Figure 1.6.

% Generation of discrete time cosine wave (Figure 1.7.)

n=0:0.05:2;
x=cos(2*pi*n);
y= stem(t,x,'b',’filled’);
set(‘y,’ markersize’,4’)
xlabel('n');
ylabel('x(n)');
title('plot of discrete time cos(2\pin)');

Figure 1.7.

You might also like