% simulates a either a square wave or random bit stream % through a low pass channel. Choose by commenting out w=.... % Nb,Nft, and Hbw are parameters to control the simulation % H can be either an ideal LP or a passive 4th order, % choose by commenting out the appropriate H=... Nb=128; % number of bit values Nft=16; % samples per bit %Hbw=3*Nb/4; % filter bandwidth %Hbw=4*Nb; % filter bandwidth w=rand(1,Nb); % generate random sequence w=pulsetrain(0:1:(Nb-1),2); % pulse train representing alternating bit values b=2*binarize(w)-1; % binarize and make into bipolar signal bft=flattop1(b,Nft); % flat top to simulate continuous time Ebb=(bft*bft')/(Nb*Nft); % inner product of row vector times column vector Bft=fft(bft); % get spectra of bit stream % if bits were alternating, like a square wave, there would be % Nb/2 cycles per the window size of Nb*Nft. Thus the fundamental % harmonic should be at k=Nb/2 H=irect(1,Hbw+1,1,(Nb*Nft)); % use ideal Low Pass Filter %H=lp_t1_o1_dft(Hbw/2,(Nb*Nft)/2,(Nb*Nft)); H=H.*H.*H.*H; % make 1st order Low Pass then cascade for 4th order cutoff br=real(ifft(fft(bft).*H)); % received signal be=2*binarize(br)-1; %reconstructed binary signal zoom1(1:(Nb*Nft)/4)=bft(1:(Nb*Nft)/4); % look at a section closer zoom2(1:(Nb*Nft)/4)=br(1:(Nb*Nft)/4); % look at a section closer zoom3(1:(Nb*Nft)/4)=be(1:(Nb*Nft)/4); % look at a section closer zoom4(1:(Nb*Nft)/4)=abs(Bft(1:(Nb*Nft)/4)); % look at a section of the fft zoom5(1:(Nb*Nft)/4)=abs(H(1:(Nb*Nft)/4)); % look at a section of the fft Ebbre=[(bft*br')/(Nb*Nft),(bft*be')/(Nb*Nft)] % average cross correlation energy figure(1); plot(zoom1); axis([1,(Nft*Nb)/4,-2,2]); figure(2); plot(zoom2); axis([1,(Nft*Nb)/4,-2,2]); figure(3); plot(zoom3); axis([1,(Nft*Nb)/4,-2,2]); figure(4); plot(zoom4); axis([1,(Nft*Nb)/4,min(min(zoom4)),max(max(zoom4))]); figure(5); plot(zoom5); axis([1,(Nft*Nb)/4,-2,2]);