0% found this document useful (0 votes)
2 views4 pages

Matlab Basic Programs

The document contains MATLAB programs for plotting various types of waveforms including Sine, Cosine, Tangent, Square, Sawtooth, Triangular, Exponential, and Damped Sine Waves. It also includes programs for plotting multiple waves on the same graph and displaying different waveforms using subplots. Each section provides code to generate the respective waveforms with appropriate labels and titles.

Uploaded by

abhishek.sharma
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)
2 views4 pages

Matlab Basic Programs

The document contains MATLAB programs for plotting various types of waveforms including Sine, Cosine, Tangent, Square, Sawtooth, Triangular, Exponential, and Damped Sine Waves. It also includes programs for plotting multiple waves on the same graph and displaying different waveforms using subplots. Each section provides code to generate the respective waveforms with appropriate labels and titles.

Uploaded by

abhishek.sharma
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

1.

Sine Wave
% Program to plot a Sine Wave

x = 0:0.01:2*pi;
y = sin(x);

plot(x,y,'b','LineWidth',2);
grid on;

xlabel('Time');
ylabel('Amplitude');
title('Sine Wave');

2. Cosine Wave
% Program to plot a Cosine Wave

clc;
clear;
close all;

x = 0:0.01:2*pi;
y = cos(x);

plot(x,y,'r','LineWidth',2);
grid on;

xlabel('Time');
ylabel('Amplitude');
title('Cosine Wave');

3. Tangent Wave
% Program to plot a Tangent Wave

clc;
clear;
close all;

x = -pi:0.01:pi;
y = tan(x);

plot(x,y,'m','LineWidth',2);
grid on;
ylim([-10 10]);

xlabel('Time');
ylabel('Amplitude');
title('Tangent Wave');

4. Square Wave
% Program to plot a Square Wave

clc;
clear;
close all;

t = 0:0.001:1;
y = square(2*pi*5*t);

plot(t,y,'LineWidth',2);
grid on;

xlabel('Time');
ylabel('Amplitude');
title('Square Wave');

5. Sawtooth Wave
% Program to plot a Sawtooth Wave

clc;
clear;
close all;

t = 0:0.001:1;
y = sawtooth(2*pi*5*t);

plot(t,y,'LineWidth',2);
grid on;

xlabel('Time');
ylabel('Amplitude');
title('Sawtooth Wave');

6. Triangular Wave
% Program to plot a Triangular Wave

clc;
clear;
close all;

t = 0:0.001:1;
y = sawtooth(2*pi*5*t,0.5);

plot(t,y,'LineWidth',2);
grid on;

xlabel('Time');
ylabel('Amplitude');
title('Triangular Wave');

7. Exponential Wave
% Program to plot an Exponential Function
clc;
clear;
close all;

x = 0:0.1:5;
y = exp(x);

plot(x,y,'g','LineWidth',2);
grid on;

xlabel('x');
ylabel('e^x');
title('Exponential Curve');

8. Damped Sine Wave


% Program to plot a Damped Sine Wave

clc;
clear;
close all;

t = 0:0.01:10;
y = exp(-0.2*t).*sin(2*pi*t);

plot(t,y,'LineWidth',2);
grid on;

xlabel('Time');
ylabel('Amplitude');
title('Damped Sine Wave');

9. Multiple Waves on the Same Graph


% Program to plot Sine and Cosine Waves

clc;
clear;
close all;

x = 0:0.01:2*pi;

plot(x,sin(x),'b','LineWidth',2);
hold on;
plot(x,cos(x),'r','LineWidth',2);

grid on;
legend('Sine','Cosine');

xlabel('Time');
ylabel('Amplitude');
title('Sine and Cosine Waves');
10. Subplots of Different Waveforms
% Program to display multiple waveforms

clc;
clear;
close all;

x = 0:0.01:2*pi;

subplot(2,2,1)
plot(x,sin(x));
grid on;
title('Sine Wave');

subplot(2,2,2)
plot(x,cos(x));
grid on;
title('Cosine Wave');

subplot(2,2,3)
plot(x,tan(x));
grid on;
ylim([-10 10]);
title('Tangent Wave');

subplot(2,2,4)
plot(x,sin(x)+cos(x));
grid on;
title('Sine + Cosine');

You might also like