Write a MATLAB function SqWave which generates a square wave

Write a MATLAB function, SqWave which generates a square wave of specified: duty-cycle, total time for which the wave is generated, and sampling frequency. The function should have the following inputs and outputs:

Inputs: • Duty-cycle • Total time for which the square wave is defined • Sampling Frequency • Fundamental Frequency

Outputs: • Square Wave

Solution

%Program to generate a continuous time square wave


clc;
clear all;

a=input(\'Enter the amplitude of the square wave A = \');
f= input(\'Enter the frequency of the square wave F = \');
dc=input(\'Enter the duty cycle of the wave DC = \');
x=input(\'Enter starting time period of square wave = \');
y = input(\'Enter ending time period of square wave = \');

f=f*2*pi;
t=x:.001:y;
y=a*square(f*t,dc);
plot(t,y);
axis([0 1 -2.2 2.2]);

%Program to generate a discrete time square wave

clc;
clear all;

a=input(\'Enter the amplitude of the square wave A = \');
f= input(\'Enter the frequency of the square wave F = \');
dc=input(\'Enter the duty cycle of the wave DC = \');

f=f*2*pi;

t=-10:.01:10;

y=a*square(f*t,dc);

stem(t,y);

axis([0 1 -2.2 2.2]);

Write a MATLAB function, SqWave which generates a square wave of specified: duty-cycle, total time for which the wave is generated, and sampling frequency. The

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site