% problem 9.8
%
% @Kefu Xue, Ph.D., Mar. 2002
%
fs=8000;
T=1/fs;
t=0:T:1.2-T;
L=length(t);
indxs=find(t>=0 & t<0.5);
indxh=find(t>=0.5);
x1=[cos(2*pi*600*t(indxs)) zeros(1,length(indxh))];
indxs=find(t>=0.3 & t<0.7);
indxh=find(t>=0.7);
indxl=find(t<0.3);
x2=[zeros(1,length(indxl)) sin(2*pi*1100*t(indxs)) zeros(1,length(indxh))];
indxs=find(t>=0.4 & t<1.2);
indxl=find(t<0.4);
x3=[zeros(1,length(indxl)) cos(2*pi*500*t(indxs))];
indxs=find(t>=0.4 & t<0.45);
indxh=find(t>=0.45);
indxl=find(t<0.4);
x4=[zeros(1,length(indxl)) cos(2*pi*700*t(indxs)-pi/4) zeros(1,length(indxh))];
indxs=find(t>=0.35 & t<1);
indxh=find(t>=1);
indxl=find(t<0.35);
x5=[zeros(1,length(indxl)) sin(2*pi*800*t(indxs)) zeros(1,length(indxh))];
figure;subplot(6,1,1);plot(x1);axis tight;title('signal 1');
subplot(6,1,2);plot(x2);axis tight;title('signal 2');
subplot(6,1,3);plot(x3);axis tight;title('signal 3');
subplot(6,1,4);plot(x4);axis tight;title('signal 4');
subplot(6,1,5);plot(x5);axis tight;title('signal 5');
x=x1+x2+x3+x4+x5;
subplot(6,1,6);plot(x);axis tight;title('sum of all signals');
%
fr=fs/length(x);
f=0:fr:fs-fr;
Xf=fft(x);
figure;plot(f, abs(Xf));title('spectrum of the sum');
%
% (a)
%
D=0.05;
N=D/T;
figure;specgram(x,N,8000,ones(N,1),0);
%
% (b)
%
N=256;
figure;specgram(x,N,8000,hanning(N),0);
