You are on page 1of 6

pulse spreading and bandlimited channel.

clc
clear all
close all
d=[1 0 1 1 0];
d(d==0)=-1;
l=length(d);
fs=100;
t=0:0.01:l;
for i=1:l
dw((i-1)*100+1:(i*100))=d(i);
end
plot(dw)
f=5;
fc=f/fs;
b1=fir1(30,fc);
z=filter(b1,1,dw);
hold all
plot(z,'k');
legend('original baseband signal','received signal ')

%%%%%%%%%%%%%%%% BASEBAND ALL PULSE GENERATION %%%%%%%%%%%%%%%%%


clc
clear all
close all
T=1;
delta_f=1/(100*T);
f=-3/T:delta_f:3/T;
beta=0.5*f;
sgma_a=2;
Sv=sgma_a^2*sinc(f*T);%.^2;
%sinc pulse
sv1=sgma_a^2*sinc(f*T);
% using raised cosine spectrum
k1=cos(2*pi*beta*T);
k2=((1-(4*beta*T).^2));
sv2=sgma_a^2*(k1./k2).*sinc(f*T);
% Plotting command follows.
% plot(f,Sv,'k');
hold on;
plot(f,sv1,'r');
plot(f,sv2,'g');
grid;

Baseband complete program


% program to obtain the baseband waveform for an arbitrary input sequence
clear all;
close all;
clc;
b = input('Enter the bit Stream : ');
n = length(b);
%tb=10e-4;
%tbn=(n*tb)
t = 0:0.01:n;
x = 1:1:(n+1)*100;
for i = 1:n
if(b(i)==0)
b_p(i) = -1;
else
b_p(i) = 1;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
set(0,'DefaultAxesColorOrder',[1 0 0;0 1 1;0 0 1;1 0 1],...
'DefaultAxesLineStyleOrder','-|--|:')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5555
for j = 1:0.1:i+1
bw(x(i*100:(i+1)*100)) = b_p(i);
end
end
bw = bw(100:end);
plot(t,bw,'k','LineWidth',2);
hold all;
T=1;
delta_f=1./(100*T);
f=(-(n+5)/T):delta_f:((n+5)/T);
sgma_a=1;
mn=0;
mnm=0;
%sv=b_p(2)*sgma_a^2*sinc((f-(2-0.5))*(T));
for k=1:n
sv=b_p(k)*sgma_a^2*sinc((f-(k-0.5))*(T));
%mm=mm+sv;
mnm=mnm+sv;
figure(1)
plot(f,sv,'LineWidth',1.5);
grid on;
axis([-10 15 -2 +2]);
title(' BaseBand Modulation With SINC Pulses')
%%%%%%%%%%%%%%%%%%%%%%%%%%%
iint=0:delta_f:1;
himp=0.01*(exp((-1*iint/20)));
hout=conv(sv,himp);
hoo=hout+(0.01*randn(1,length(hout)));
mn=mn+hoo;
f1=(-(n+5)/T):delta_f:((n+6)/T);
%figure(2)
% plot(f1,(hoo),'r');
%hold;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot(f,sv,'LineWidth',1.5);

end;
figure(2)
sound(mnm,5000)
plot(f,mnm,'b-')%,'LineWidth',5);
grid;
hold
%figure(2)
plot(f1,mn,'r-')%,'LineWidth',5);f1,
%grid
axis([-10 15 -2 +2]);
legend('transmitted signal','received signal with ISI and noise');
title('Transmitted and Received Signals');
%%%%%%%%%%%%%%%%%%%%%%%%%% references
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%http://stackoverflow.com/questions/2028818/automatically-plot-different-co
%lored-lines-in-matlab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%
mnmf=mnm(length(mnm)/2:end); %%%%%%%%% mnm is signal without corruption mn is signal corrupted with
ISI AND NOISE%%%
length(mnm)
%%%%%%%%%%%%%%%%%%%%%% matched filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fhm=-1:0.01:1;
hm=sinc((fhm-(0.5))*(T));
hml=length(hm)
mnmfl=length(mnmf)
diff=abs(mnmfl-hml);
if hml>mnmfl
mnmf=fliplr(mnmf);
mnmf=[mnmf zeros(1,diff)];
else
hm=fliplr(hm);
hm=[hm zeros(1,diff)];
end
hmf=fft(hm);
mnmf_f=fft(mnmf);
corr_f=hmf.*mnmf_f;
cor=ifft(corr_f);
% mfo=xcorr(hm,mnmf);
figure
plot(cor);
%%%%%%%%% generating sampling wave
s=100; %%%% THIS SPECIFIES THE SAMPLE AT Which sampling is done if the signal is ISI+NOISE
s=135
for ld=1:length(b)
sam(s)=1;
s=s+100;
end;
dip=cor(1:length(sam));
demod=dip.*sam;
hold all
plot(demod)
% plot(mnmf,'k');
%%%%%%%%%%%%%%%%%%%%%%% data reconstruction %%%%%%%%%%%%%%%%%%%%%

s=100; %%% if the signal is ISI+NOISE s=135


for ld=1:length(b)
samd=demod(s);
if samd>0.5
rc(ld)=1;
elseif samd< -0.5
rc(ld)=0;
else
rc(ld)=1;
end
rec((ld-1)*100+1:ld*100)=rc(ld);
s=s+100;
end
figure
plot(rec)
%%%%%%%%%%%%%% matched filter demo %%%%%%%%%%%%%%%%%%%%%
clc
clear all
close all
b=[1 0];
b(b==-1)=0;
n = length(b);
t = 0:0.01:n;
x = 1:1:(n+1)*100;
for i = 1:n;
for j = 1:0.1:i+1;
bw(x(i*100:(i+1)*100)) = b(i);
end
end
bw = bw(100:end);
plot(t,bw);
%%%%%%%%%%%%%%%%%%%%%% impulse response of matched filter %%%%%%%%%%%
himp=ones(1,100);
%%%%%%%%%%%%%%%%%%%%%%% matched filter implementation %%%%%%%%
diff=length(bw)-length(himp);
bwf=fft(bw);
himpf=fft([himp zeros(1,diff)]);
mfof=bwf.*himpf;
mfo=ifft(mfof);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%
plot(10*bw);
hold on
plot(mfo)
%%%%%%%%%%%%%%%%%%%%%%%%EYE PATTERN IDEAL %%%%%%%%%%%%%%%%%
clc;
clear all;
close all;
k=3;
for i=0:((2^k)-1)
p=i;
for j=(k):-1:1

r(i+1,j)=rem(p,2);
p=(p-r(i+1,j))/2;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
T=1;
delta_f=1./(100*T);
f=(-(k+5)/T):delta_f:((k+5)/T);
sgma_a=1;
mn=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:2^k
b=r(i,:);
b(b==0)=-1;
mnm=0;
for j=1:k
sv=b(j)*sgma_a^2*sinc((f-((j)-0))*(T));
mnm=mnm+sv;
end
ln=floor(length(mnm)/2);
op(i,:)=mnm(ln+2:ln+((k+1)*100+1));
end
hold all
xa=-(k-1):0.01:(k-1);
for i=1:2^k
fop=op(i,:);
figure(1)
plot(fop)
end
grid on

%%%%%%%%%%%%%%%%%%%%%% INTEGRATE AND DUMP CKT %%%%%%%


clc
clear all
close all
t=0:0.01:2;
% x=triang(2*pi*t);
% x=[0:10 10:-1:0];
x=ones(1,10)'
plot(x)
sum=0;
for i=1:length(x)
y(i)=x(i)+sum;
sum=y(i);
end
hold on
plot(y)

%%%%%%%% OPTIMUM FILTER USING CORRELATOR%%%%%%%%%%%%%%%%


clc
clear all
close all
% s=5*[ones(1,100)];
s=[1:100];
s1=s%+2*randn(1,100);
s2=-s%+2*randn(1,100);
x=s1.*(s1-s2);
sum=0;
for i=1:length(x)
y(i)=x(i)+sum;
sum=y(i);
end
plot(y);
% the output of the above is equal to the correlator op when the impulse
% response of the matched filter is 2v.
%%%%%%%%%%%%%%%%% actual correlation using dft %%%%%%%%%%%%%%%%%%%%%%%%%
s1f=fft(s1);
rf=fft(2*s1);
opf=s1f.*rf;
op=ifft(opf);
figure
plot(op);
hold on
plot(y)
%%%%%%%%%%

You might also like