%%%% In this m file we demostrate the effect of ISI and the benefit of
%%%% using Raised cosine pulse shape to eliminate ISI
echo off;clear;clc;close all;warning off all
sitil = ['-k  ';'--k ';':k  ';'-.k ';'-*k ';'--sk';':ok ';'-.^k';'-sk ';'--sk';':sk ';'-.sk'];linwid = [2 3 3 2 2 2 1 2 2 2 2 2];
%gTt = [ones(1,50) ones(1,50) zeros(1,50) zeros(1,50) ones(1,50) zeros(1,50) ones(1,50) ones(1,50) ones(1,50) ones(1,50)]; %%% Transmitted message signal
gTt = [zeros(1,20) ones(1,5) zeros(1,20)]; %%% Transmitted message signal
%gTt = [ones(1,5) zeros(1,40)]; %%% Transmitted message signal
Eps = sum(gTt.^2); %%% Energy in transmitted signal
t = 1:length(gTt);figure(1)
plot(t,gTt,'-k ','LineWidth',2);
set(gcf,'Color','w');set(gca,'FontSize',16)
axis([0 max(t) -0.05 1.05]);
xlabel('\itt','FontSize',18,'FontWeight','bold'); 
ylabel('\itg_T \rm( \itt \rm) - Transmitted ASK message signal in time domain','FontSize',14,'FontWeight','bold'); 
NFFT = 2^nextpow2(length(t) + 4000); Fs = 1;
figure(2)
GTf = fft(gTt,NFFT)/Fs;f = Fs/2*linspace(0,1,NFFT/2);fT = Fs*linspace(0,1,NFFT);
%semilogy(f,2*abs(GTf(1:NFFT/2)),sitil(2,:),'LineWidth',linwid(2));set(gcf,'Color','w');
plot(f,abs(GTf(1:NFFT/2)),sitil(2,:),'LineWidth',linwid(2));set(gcf,'Color','w');set(gca,'FontSize',16)
xlabel('\itf','FontSize',18,'FontWeight','bold'); 
ylabel('\itG_T \rm( \itf \rm) - Transmitted ASK message signal in frequency domain','FontSize',14,'FontWeight','bold'); 
%%%% Types of channel 
Cf1 = ones(1,NFFT); %%% Unlimited channel
%Cf1 = [ones(1,NFFT/2) zeros(1,NFFT/2)]; %%% Rectangular bandlimited channel (quite wide) 
%Cf1 = [ones(1,NFFT/4) zeros(1,3*NFFT/4)]; %%% Rectangular bandlimited channel (wide)  
%Cf1 = [ones(1,NFFT/8) zeros(1,7*NFFT/8)]; %%% Rectangular bandlimited channel (narrow)
%Cf1 = 1./(1 + j*10*(fT)); %%% Low pass channel
% f = 0:8/NFFT:4;alfa = 0.9;t0 = 0.1;
% Cf1 = [1 + alfa*cos(2*pi*f*t0) zeros(1,NFFT/2 - 1)];
% GTf = [ones(1,NFFT/2) zeros(1,NFFT/2)];    
Cf = Cf1*1;figure(3);
plot(fT,abs(Cf(1:NFFT)),sitil(2,:),'LineWidth',linwid(2));set(gcf,'Color','w');set(gca,'FontSize',16);axis([0 max(fT) -0.05 2]);
xlabel('\itf','FontSize',18,'FontWeight','bold'); 
ylabel('\itC \rm( \itf \rm) - Channel response','FontSize',14,'FontWeight','bold');
Hf = GTf(1:NFFT).*Cf;figure(4)
plot(f,abs(Hf(1:NFFT/2)),sitil(2,:),'LineWidth',linwid(2));set(gcf,'Color','w');set(gca,'FontSize',16);
xlabel('\itf','FontSize',18,'FontWeight','bold'); 
ylabel('\itH \rm( \itf \rm) - Received signal spectrum ','FontSize',14,'FontWeight','bold');
ht = ifft(Hf); figure(5)
plot(t, ht(t));set(gcf,'Color','w');set(gca,'FontSize',16);axis([0 max(t) -0.05 1.05]);
xlabel('\itt','FontSize',18,'FontWeight','bold'); 
ylabel('\ith \rm( \itf \rm) - Received signal in time domain','FontSize',14,'FontWeight','bold');
Eph = sum(abs(ht(t)).^2); %%% Energy in received signal
Eph / Eps