Binary Phase Shift Keying with BandPass Channel and Additive White Gaussian Noise : Modulation and Demodulation by Laurence G. Hassebrook 2-27-2013 We simulate Binary Phase Shift Keying (BPSK) with amplitude modulation and mixer based demodulation. The modulated signal is synthesized by using an upsampled random bipolar bit stream, modulated by a carrier wave and then sent through a bandpass channel and corrupted by Additive White Gaussian Noise (AWGN). Assuming no phase error, the modulated signal is demodulated using a mixer configuration. Because the binary signal is bipolar, the resulting modulation is equivalent to phase modulation by 0 or . Both input and output signals are analyzed for bandwidth and noise distribution. The goal is to reproduce the figures and processing presented in this document using MATLAB. The signal length is N; number of bits is Nbit; Standard Deviation is STD and carrier frequency is kc. clear all; N=10000; Nbit=8;%300; Nsample=floor(N/Nbit); STD=0.1;%0.5; kc=4*Nbit; kcutoff=kc/4; Nbin=100; n=1:Nbin; Note that there are “Nsample” sample values for each bit. Hence the system is upsampled by Nsample to simulate continuous time or what we call pseudo-continuous time. The noise level is controlled by STD which is effectively the standard deviation of the Gaussian noise. The carrier frequency is “kc” and “kcutoff” is used for both the channel bandwidth and the demodulator lowpass filter cutoff frequency. We separate the received “1” and “0” values and estimate their probability density functions for two experiments: Case 1: Use Nbit=8 and STD=0.1. Case 2: Use Nbit=300 and STD=0.5. 1. Binary Sequence Synthesis Generate Nbit random bits using a the pseudo-random generater rand() such that 1 % Random Binary Signal wb=rand(1,Nbit); bits=binarize(wb); The vector wb is has only one sample per bit which is not a good model for continuous time so we upsample using a kronecker product such that. ub=ones(1,Nsample); bk=kron(bits,ub); where bk is length Nb = Nsample x Nbit which might be less than N. So to make sure we have a signal N long we first generate a zero vector N long and then we move bk into it which effectively zero pads any mismatch in length. b=zeros(1,N); Nb=Nsample*Nbit; t=1:N; b(1:Nb)=bk(1:Nb); %Force signal to be N samples long % turn signal into a bipolar non-return to zero signal b=2*(b-0.5); The result along with the BPSK modulation is shown in the next section. 2. BPSK Modulation for shift. BPSK modulation with phase shift is achieved by first generating a discrete cosine wave and then elementwise multiplying it by the upsampled bipolar binary signal sequence b such that % modulate sc=cos(2*pi*kc*t/N); % carrier signal s=b.*sc; To plot out both the binary signal and the modulated signal in the same plot, and store a jpeg image of this result, the matlab code is: figure(1); plot(t,b,t,s); title('BPSK Modulation'); xlabel('n'); ylabel('s(n) and b(n)'); axis([1,N,-1.5,1.5]); legend('binary message','BPSK'); print -djpeg Fig1_BPSKSignal; The resulting figures for is 2 Figure 2.1: Case 1 binary signal and modulated signal. The mathematical representation of the BPSK modulated signal is st bt cos2 f c t (1) where t is an integer index for sequence of length N and carrier frequency fc = kc/N. 3. Channel Model and Signal Analysis The channel is a lowpass model with Additive White Gaussian Noise (AWGN) on its output. The lowpass component forces a bandlimited “baseband” onto the otherwise infinite bandwidth BPSK signal. The model is shown in Fig. 3.1. 3 Figure 3.1: Bandpass AWGN channel model. The MATLAB code to perform the bandpass component is: % form bandpass filter Norder=10; % filter order fmax=N/2; % required variable K=1; % filter gain % kcutoff is the bandwidth of the bandpass filter % where kc is center frequency % band pass filter [f Hchannel]=bp_butterworth_oN_dft(kc,kcutoff,K,fmax,N,Norder); % filter signal through channel S=fft(s); R=S.*Hchannel; r0=real(ifft(R)); k=t; figure(2); SUBPLOT(2,1,1); plot(k,Hchannel,k,abs(S)/(2*max(abs(S)))); title('BPSK and Channel Spectra'); xlabel('k'); ylabel('H(f) and S(f)'); SUBPLOT(2,1,2); plot(k,Hchannel,k,abs(R)/(2*max(abs(R)))); title('Channel Filtered BPSK and Channel Spectra'); xlabel('k'); ylabel('H(f) and R(f)'); print -djpeg Fig2_BPSKSpectra; For a low number of bits, the input and output spectra are difficult to see because they are so low frequency as shown in Fig. 3.2. 4 Figure 3.2: (top) Channel input BPSK spectrum. (bottom) Bandlimited output spectrum of BPSK. To generate the pseudo-random AWGN sequence we use randn() in MATLAB and add to the signal r0(t) such that ~t r0 t st w (2) The MATLAB code for the AWGN is %% Gaussian distributed noise w=STD*randn(1,N); r=r0+w; figure(3) plot(t,r); title('BPSK Modulation with Noise'); xlabel('n'); ylabel('r(n)=s(n)+w(n)'); print -djpeg Fig3_BPSKPlusNoise; The noisey signal is shown in Fig. 3.3. 5 Figure 3.3: Signal output of channel with noise. 4. Demodulation and Signal Analysis We will use a mixer followed by a low pass filter to demodulate the BPSK signal as shown in Fig. 4.1. Only one mixer is needed because the phase modulation is which means that a “1” bit will demodulate to a 1 and a “0” bit will demodulate to -1. A mixer multiplies the received signal with a replica of the carrier signal which must be in phase with the modulated carrier. The multiplication creates what is known as a baseband and two frequency translated replicas of the baseband centered at +/- 2kc frequencies. So to reconstruct the signal we simply low pass filter the multiplier output with a cutoff around kcutoff. Mathematically this is rb t r t cos2 k c t N * hLP t (3) 6 Figure 4.1: Mixer based demodulator. The MATLAB code for the demodulator is %% DEMODULATION USING A MIXER sref=sc; % reference signal % mix the reference with the input r1=r.*sref; % form reconstruction filter % filter with some recommended parameters Norder=8;fmax=N/2;K=8; % filter gain [f H]=lp_butterworth_oN_dft(kcutoff,K,fmax,N,Norder); % filter signal through channel via frequency domain R1=fft(r1);R=R1.*H; rb=real(ifft(R)); To detect “0” and “1” bits separately, we do not want to sample the bit boundaries else we would get errors from the transitions. So we define binary windows within the bit boundaries, one for the “1” detection and the other for the “0” detection. % define sampling region for detector ueye=zeros(1,Nsample); ueye(1,floor(Nsample/4):floor(3*Nsample/4))=1; bkeye=kron(bits,ueye); bkeyenot=kron((1-bits),ueye); beye=zeros(1,N); beyenot=zeros(1,N); beye(1:Nb)=bkeye(1:Nb); %Force signal to be N samples long beyenot(1:Nb)=bkeyenot(1:Nb); %Force signal to be N samples long where beye is within the one boundaries and beyenot is within the zero boundaries. All these signals are shown in Fig. 4.1 7 Figure 4.2: Demodulated signal with the detection windows superimposed. Using the window sequences we estimate pdfs for the “0” and “1” signals separately as %% seperate out the two noise distributions J0=find(beyenot>0.5); J1=find(beye>0.5); rb0=rb(J0); rb1=rb(J1); % [f0 n0] = PDFestimator(rb0, Nbin); [f1 n1] = PDFestimator(rb1, Nbin); % figure(5); plot(n0,f0,n1,f1); title('Demodulated PDF Estimation'); xlabel('r'); ylabel('f(r)'); legend('Detected Zeros','Detected Ones'); print -djpeg Fig5_DemodulatedSignalPDFestimation; 8 Figure 4.3: Estimated pdfs within the "0" and "1" detection windows with case 1 5. Case 2 Results Rerun your simulation with Nbit=300 and STD=0.5 and re-plot Figs. 3.2 and 4.3 as Figs. 5.1 and 5.2, respectively. 9 Figure 5.1: (top) Channel input BPSK spectrum. (bottom) Bandlimited output spectrum of BPSK. Blue line is bandpass filter envelope. 10 Figure 5.2: Estimated pdfs within the "0" and "1" detection windows with case 2. 11