% create square wave %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % x = square(t,duty cycle) % duty cycle = percentage of signal that's positive %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Fs = 44100; dur = 1; t = [0 : 1/Fs : dur-1/Fs]; freq = 400; %%%%%%%%% % square wave vector fsq = .2* square ( 2*pi * freq * t, 50 ); % sound(fsq,Fs) % plot 2 periods of square wave plot( t(1 : round(2*1/freq*Fs)) , fsq(1 : round(2*1/freq*Fs)) ) axis([0 dur/round(2*1/freq*Fs) min(fsq)-.1 max(fsq)+.1 ]) % plot spectrogram of square wave figure(2) specgram(fsq,256,Fs)