function output=gen_square(ampl, freq, sample_rate, duration)
%generate a discrete square wave
%ampl: amplitude
%freq: frequency
%sample_rate: the number of samples per second
%duration: the time in seconds that the signal will last
%output: the generated square wave signal

n=[0:1/sample_rate:duration-1/sample_rate]; %time sequence
output=ampl.*square(2*pi*freq*n);