fs=1000;
t=0:1/fs:2.0-1/fs;
Z=length(t);
f1=20;
f2=30;
f3=40;
x=3*cos(2*pi*f1*(t)+0.2)+cos(2*pi*f2*(t)-0.3)+2*cos(2*pi*f3*(t)+2.4);
subplot(3,3,1);
plot(t,x);
title(['inputwave']);
xlabel('time');
ylabel('amplitude');
f=fft(x);
m=length(f);
xmag=abs(f);
subplot(3,3,2);
plot(xmag);
title(['fft of input']);
xlabel('hz');
ylabel('magnitude');
fs1=1000; %sampling frequency
T=0.2; %width of the rectangule pulse in seconds
m=-1:1/fs1:1-1/(fs1); %time base
z=length(m);
r=rectpuls(m-(T)/2,T); %generating the square wave
subplot(3,3,3);
plot(m,r,'k');
title(['Rectangular Pulse width=', num2str(T),'s']);
xlabel('Time(s)');
ylabel('Amplitude');
s=transpose(r)*(m);%multiplying both waves
subplot(3,3,4);
plot(t,s);
title(['multiplied output']);
xlabel('time(s)');
ylabel('amp');
k=fft(s);%fft of the windowed signal
kmag=abs(k);
subplot(5,1,5);
plot(kmag);
title(['fft of output']);
xlabel('frquency');
ylabel('amplitude');
spectrum of input and output
subplot(3,3,5);
title('spectro gram of input ');
spectrogram(x)
subplot(3,3,6);
title('spectro gram of output or product siganl');
spectrogram(s)