%% Duty Cycle of Square Wave
% Generate a 30 Hz square wave sampled at 1 kHz for 70 ms. Specify a duty cycle of 37%. Add white Gaussian noise with a variance of 1/100.

t = 0:1/1e3:0.07;
y = square(2*pi*30*t,37)+randn(size(t))/10;

%
% Compute the duty cycle of the wave. Plot the waveform and annotate the duty cycle.

dutycycle(y,t)

% Copyright 2015 The MathWorks, Inc.