clear max_bits=30; %maximum number of bits for allowing one to plot the signal and the eye diagram points=input('enter the number of points per symbol: '); bits=input('enter the number of bits: '); p0=input('enter the probability of 0: '); pulse_type=input('enter the pulse type (0: NRZ; 1:Raised Cosine; 2:Manchester): '); switch pulse_type case 0 pulse=nrz(points); case 1 alfa=input('enter the Roll Off factor (>0, <=1): '); if alfa<=0 || alfa >1 disp('error'); return end intervals=input('enter the number of T intervals for representing the pulse: '); pulse=square_root_raised_cosine(alfa,points,intervals); case 2 pulse=manchester(points); otherwise disp('error'); return; end info=2*(rand(1,bits)>p0)-1; if bits < max_bits individuals=input('do you want to build the individual bit signals (0/1)?: '); else individuals=0; end if individuals for i=1:bits, info1=zeros(1,bits); info1(i)=info(i); x1(i,:)=signal_build(info1,points); xt(i,:)=conv(x1(i,:),pulse); yt(i,:)=conv(xt(i,:),pulse); end r1=sum(yt,1); else x1=signal_build(info,points); xt=conv(x1,pulse); r1=conv(xt,pulse); end t=(1:length(r1))/points; [a,b]=find(abs(abs(r1)-1)<.01); if bits < max_bits sg=input('plot the signal (0/1)?: '); else sg=0; end if sg figure; plot(t,r1); hold on for i=1:bits, plot(t(b(1)+(i-1)*points)*ones(1,3),[-2 0 2],'k-.','LineWidth',2); end set(gca,'XLim',[t(max(1,b(1)-points)),t(min(b(1)+bits*points,length(t)))]); end snrdB=input('enter snr (dB): '); noisev=10^(-snrdB/10); noise=randn(1,length(t))*noisev^.5; r2=r1+noise; if sg plot(t,r2,'r'); end if bits < max_bits eye=input('plot the eye diagram (0/1)?: ') else eye=0; end if eye ploteye(r1,points,b(1)-points/2,bits) title('eye diagram without noise'); input('press a key to continue') ploteye(r2,points,b(1)-points/2,bits) title('eye diagram with noise'); end ber_eva=input('ber evaluation (0/1)?: '); while ber_eva==1 offset=input('enter a offset on synchronization: '); for i=1:bits, rec_values(i)=r2(b(1)+(i-1)*points+offset)>0; end ber=sum(xor(info>0,rec_values))/bits; str=sprintf('bers=%.2e bert%.2e\n',ber,1/2*erfc((1/(2*noisev))^.5)); disp(str); ber_eva=input('another offset value (0/1)? '); end po_sp=input('plot power spectrum (0/1)? '); if po_sp rl=input('how many realizations? '); Rm(1,:)=(abs(fft(r1))).^2; for i=2:rl info=2*(rand(1,bits)>0.5)-1; x1=signal_build(info,points); xt=conv(x1,pulse); r1=conv(xt,pulse); Rm(i,:)=(abs(fft(r1))).^2; end new_plot=input('new figure (0/1)? '); color=input('color (k,b,r,g) value between apexes: '); str=sprintf('%1s',color); plot_power_spectrum(mean(Rm),points,new_plot,str); end