3. Write a function, SqWave which generates a square wave of specified: duty- cy
ID: 3703616 • Letter: 3
Question
3. Write a 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 Outputs: Square Wave Do NOT use the Matlab function square to accomplish this task. Use the SqWave function to generate a unit amplitude, 440 Hz square-wave, ? 0.1, 0.2, 0.5, that lasts for 2 s. Use a sampling frequency of 44.1 kHz. Play back the tone over your speakers using the sound command. How does the perceived tone change as you vary a?Explanation / Answer
CODE:
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]);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.