Lecture-1 Introduction To Matlab
Lecture-1 Introduction To Matlab
Matlab
Course : Data Communication Sessional
1.Sinusoidal Signal[analog]
y(t) = A sin(2πft+ θ) clc; clear all; close all;
Fs = 1000;
t = 0:1/Fs:1;
f = 5;
A = 2;
x = A*sin(2*pi*f*t);
plot(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Sinusoidal Signal');
grid on;
In MATLAB, these three commands are used to clear the workspace and command window:
1.clc:
•Clears the Command Window, removing all text and output displayed there.
•This is useful for cleaning up the screen and improving readability.
2.clear all:
•Removes all variables from the workspace.
•This is helpful when you want to start a new session without any existing variables interfering
with your calculations.
3.close all:
•Closes all open figures.
•This is useful when you have multiple figures open and want to clear them all at once.
Parameter Definition:
•Fs: Sampling frequency determines how many samples are taken per second.
•t: Time vector, created using 0:1/Fs:1, spans from 0 to 1 second with steps of 1/Fs.
•f: Frequency of the sinusoidal signal.
•A: Amplitude of the sinusoidal signal.
Plotting the Signal:
•plot(t,x): Plots the signal x against time t.
•xlabel, ylabel, and title: Add labels to the x-axis, y-axis, and the
plot title, respectively.
•grid on: Turns on the grid lines for better readability.
2. Digital Signal in MATLAB
clc; clear all; close all;
x = [1 0 1 1 0 0 1];
n = 0:length(x)-1;
stem(n, x);
axis([0 12 0 12]);
grid on;
• Defining the Signal: We create a vector x to represent the digital
signal. Each element in x corresponds to a sample of the signal.
Creating the Time Vector: The n vector represents the sample
indices, starting from 0.
• Plotting the Signal: stem(n, x): This command creates a stem plot,
where the vertical lines represent the amplitude of each sample at
the corresponding time index.
• Adding Labels: xlabel, ylabel, and title are used to label the x-axis, y-
axis, and the entire plot, respectively.
subplot(2,1,1);
plot(t, x1);
xlabel('Time (s)');
ylabel('Amplitude');
title('Sine Wave');
subplot(2,1,2);
plot(t, x2, 'r--');
xlabel('Time (s)');
ylabel('Amplitude');
title('Cosine Wave');
Explanation:
•subplot(2,1,1); divides the figure into a 2x1 grid and selects the first subplot.
•subplot(2,1,2); selects the second subplot.
•The plot commands in each subplot plot the respective signals.
Task:
1. Draw 1 sine wave, 1 cos wave and 1 multiplication of these two-wave using subplot
2. Draw 1 sine wave, 1 cos wave and 1 division of these two-wave using subplot