Matlab program to generate a sinusoidal waveform

Program Code
%sinusoidal waveform generation
clc;
clear all;
close all;
f=1000;
t=0:1/(f*1000):2/f;
y=sin(2*pi*f*t);
plot (t,y);
xlabel ('Time');
ylabel ('Amplitude');
title ('Sinusoidal Waveform');
grid on;




Output

Explanation of Program Code 
clc;
It clears all input and output from the Command Window display giving clean screen. It removes items from workspace, freeing up system memory. After using clc, the scroll bar cannot be used to see the history of functions, but still the up arrow can be used to recall statements from the command history.

clear all;
It removes all variables from the workspace. This frees up system memory.

close all;
It deletes all figures whose handles are not hidden.

f=1000;
It stores the value 1000 in variable f.

t=0:1/(f*1000):2/f;
This command creates a vector t.
The first element of vector t is 0. 
The next element of vector t is created by adding (1/1000f) to the previous element. This goes on by creating new elements till one element in the vector t has the value 2/f. The element with the value 2/f becomes the last element in vector t. 
Here f is already given as 1000. 
So here, 
1000f = 1000 X 1000 = 1000000
So, (1/1000f) = 1/1000000 = 0.000001
2/f = 2/1000=0.002
So, from the second element onward, each element of vector t is created by adding (1/1000f), that is 0.000001 with the previous element. This goes on by creating new elements till one element in the vector t has the value 2/f  that is 0.002. The element with the value 0.002 becomes the last element of the vector t.
Here this vector t is used as time axis(x axis) while plotting sinusoidal waveform.

y=sin(2*pi*f*t);
It is used to create sinusoidal waveform.
It multiplies each element of vector t with (2x 3.14x1000) and returns the circular sine of the elements of resulting vector.
Here f=1000. pi is always 3.14 approximately(constant).
That is why 2*pi*f*t = (2x 3.14x1000).

plot (t,y);
It plots all the lines defined by t versus y pairs.

xlabel ('Time');
It labels the x-axis as 'Time'. Each axes graphics object can have one label for the x-, y-, and z-axis. The label appears beneath its respective axis in a two-dimensional plot.

ylabel ('Amplitude');
It labels the y-axis as ' Amplitude. '

title ('Sinusoidal Waveform');
It outputs the phrase  'Sinusoidal Waveform' above the figure at the top.

grid on;
It adds major grid lines to the current axes.

__________________

4 comments:

  1. it is sooooooooooooooo useful, thank u so...... much

    ReplyDelete
    Replies
    1. Respected madam,

      Thank you for spending your valuable time to visit my humble blog. You are always welcome to visit this blog.

      I am happy to know that you found my blog useful.

      I am always at your service. Wish you and your dear and near ones all success and happiness

      Delete
  2. it is sooooooooooooooo useful, thank u so...... much

    ReplyDelete
    Replies
    1. Respected Madam
      Thank you for spending your valuable time to visit my humble blog. You are always welcome to visit this blog.

      I am happy to know that you found my blog useful.

      I am always at your service. Wish you and your dear and near ones all success and happiness

      Delete

Please write your opinion about this MATLAB program here, only in English.