Professional Documents
Culture Documents
Experiment No. 5: Function
Experiment No. 5: Function
EXPERIMENT NO. 5
Aim of Experiment: To generate a discrete square wave using sine and cosine
function.
Theory:
A square wave is a non-sinusoidal periodic waveform in which the amplitude alternates
at a steady frequency between fixed minimum and maximum values, with the same
duration at minimum and maximum. Although not realizable in physical systems, the
transition between minimum and maximum is instantaneous for an ideal square wave.
The square wave is a special case of a pulse wave which allows arbitrary durations at
minimum and maximum. The ratio of the high period to the total period of a pulse wave
is called the duty cycle. A true square wave has a 50% duty cycle (equal high and low
periods).
Code:
n=0:1:24;
N=8;
fn=1/2;
i=0+i;
for k=1:N-1
fn=fn+(1/N)*((1-exp(-i*pi*k))/(1-exp(-
2*i*pi*k/N)))*exp(2*pi/N*k*n*i);
end
stem(n,fn);
axis([0 21 0 2]);
title('SQUARE WAVEFORM 15102088');
xlabel('SAMPLE');
ylabel('AMPLITUDE');
Derivation: