# How to generate and plot a waveform in MATLAB

Previously we discussed about,

**How to write your first MATLAB program**, Now we will discuss how to generate and plot a waveform in MATLAB.
For simplicity, We are generating a sinusoidal waveform of

**5 Hz frequency**having**amplitude 10**. The screen capture of matlab program for this problem in editor window has been shown in**figure.1**.
Figure.1 - Screen capture of MATLAB program.

This program is written in seven lines from line 6 to 12 with brief description about each line. The line by line detailed description of commands is as below:

**Line-6:**Generate the time values between 0 and 1 in interval of 0.0001 and saved into t.

**Example:**

**t = 0, 0.0001, 0.0002, 0.0003, . . . . . . . . upto 1.**

**Line-7:**Compute the values of y at each value of t using inbuilt

**'sin'**function.

**Line-8:**Plot a graph between t and y axis using inbuilt

**'plot'**function.

**Line-9:**Write the desired title in the top of graph with using inbuilt

**'title'**function. Example:

**Sinusoidal Waveform**.

**Line-10:**Write the desired label on x axis with using inbuilt

**'xlabel'**function. Example:

**Time**.

**Line-11:**Write the desired label on y axis with using inbuilt

**'ylabel'**function. Example:

**Amplitude**.

**Line-12:**Bound both (x axis and y axis) between predefined values using inbuilt

**'axis'**function. In this line first value is lower limit of x axis, second value is upper limit of x axis, third value is lower limit of y axis and fourth value is upper limit of y axis.

Plot of sinusoidal waveform has been shown in figure.2 which is generated using above written matlab program.

Figure.2 - Screen capture of plot generated using MATLAB program.

The plot is showing the sinusoidal waveform of 5 Hz i.e. five cycles per second. In next post, we will discuss about, how to generate multiple waveform and plot them on single plot window in MATLAB.

**Video Tutorial:**How To Generate and Plot a Waveform in MATLAB

## Post a Comment