# Matlab Square Wave Signal Generation

## What is Square Wave signal Generator?

A “square wave” is a sort of non-sinusoidal waveform, most normally experienced in gadgets and sign preparing. An optimal square wave substitutes consistently and momentarily between two levels. Its stochastic partner is a two-state direction.

*Function generator:** **The generator which is gear or gadget used to produce the powerful electrical form or waveforms over a wide scope of frequencies. The waveforms created by the capacity generator are a three-sided wave, square wave, sine-wave, and saw-tooth wave.*

Uses of square wave signal generator?

- Square waves are portrayed as far as period, recurrence and adequacy.
*The square wave generator is characterized as an oscillator that gives the yield with no contribution, with no contribution to the sense we should give contribution inside zero seconds that implies it should be a drive input.**This generator is utilized in advanced sign preparing and electronic applications.**The square wave generator is otherwise called Astable Multivibrator or free-running and the recurrence of the square wave generator is autonomous of the yield voltage.*

*Why are square waves treated as dangerous?*

*The square waves can be amazing and captivating to look however, they are hazardous for swimmers and boats. At the point when two arrangements of wave frameworks slam into one another it brings about structure or wave designs that resemble squares across the sea.*

## The benefits of the square wave signals are listed below

- It has a very simple architecture.
- The Maintenance cost is affordable and it is easy to manage.
- Overall Low cost.
- Flexible in nature.
- Easy built design.
- Not so tricky and complex.

## Generic Steps to build program logic of square wave signal generation:

**Step 1:**

Take inputs from the users like Amplitude of the square wave A1, frequency of the square wave F1, duty cycle of the wave Dc1.

**Step 2:**

Find f1(frequency) with the help of formula à f1 = f1 * 2 * pi;

**Step3:**

Now that we are done with taking inputs from the users and calculating the values of required dimensions, next step is to use square() and stem() functions, followed by axis() function to get the desired output that is to generate square wave signals.

**MATLAB Code as follows:**

```
clear all;
a1 = input('Enter amplitude of the square wave A1- - - - - - >');
f1 = input('Enter the frequency of the square wave F1- - - - - - >');
dc1 = input('enter the duty cycle of the wave Dc1- - - - - - >');
f1 = f1 * 2 * pi;
t1 = - 10 : 0.01 : 10;
y1=a1 * square(f1 * t1 , dc1);
stem(t1, y1);
axis([0 1 -6.7 2.2])
```

**Output: Command prompt of MATLAB asking users to enter input values.**

```
Enter amplitude of the square wave A1- - - - - - >
56
Enter the frequency of the square wave F1- - - - - - >
55
enter the duty cycle of the wave Dc1 - - - - - - >
3
```

The below screenshot shows how the above piece of code had generated the signal waves with the given input dimensions by the users.