EE512 V6: Two bit Binary  Phase Shift Keying with BandPass Channel and Additive White Gaussian Noise :

advertisement
EE512V6:TwobitBinaryPhaseShift
KeyingwithBandPassChanneland
AdditiveWhiteGaussianNoise:
QuadratureModulationand
Demodulation
by Laurence G. Hassebrook
3-4-2015, updated 3-27-2015
We simulate Two Bit Binary Phase Shift Keying (BPSK) with amplitude modulation and mixer
based demodulation. The modulated signal is synthesized by using two independent upsampled
random bipolar bit streams, one stream modulates a cosine carrier wave and the other modulates
a sine wave carrier. The combined result is sent through a lowpass channel and corrupted by
Additive White Gaussian Noise (AWGN). Assuming no phase error, the modulated signal is
demodulated using a cosine (in-phase) and sine wave (quadrature) mixer configuration. Both
input and output signals are analyzed for bandwidth and noise distribution. The goal is to run the
baseline system and tweek the number of bits to a maximum number without causing any bit
errors. The students are then required choose their own “alias”to send the instructor
alias_createBsize.m, alias_modulator.m and alias_demodulator.m. NO WRITEUP is required.
The instructor will run their code and if they do not get any errors, will accept it and post the
results using their alias.
1. Baseline_createBsize.m
The student must insert their alias in place of “baseline” and choose the value of Nbit that they
want to use. Student should choose, Nbit, number of bits to send.
% generate groupname_Bsize.mat
clear all;
% INSERT GROUP NAME AND NUMBER OF BITS
groupname='ee51215V6'
Nbit=????
Nseq=2
% END OF INSERT
filename=sprintf('%s_Bsize.mat',groupname)
save(filename); % stores groupname, Nbit, Nseq in ee51215V6_Bsize.mat
% load filename.mat to retreive
1
2. Bgen15.m
The instructor “owns” Bgenxx.m. He must change the “baseline” name in his version to the alias
of the student. Bgen generates a random bit matrix that has Nseq rows and Nbit columns.
% generate bit matrix based on groupname_Bsize.mat
clear all;
groupname='ee51215V5' % instructor enters this name to select student project
filename=sprintf('%s_Bsize.mat',groupname);
load (filename) % retrieve matrix size
filename
Nbit
Nseq
B=rand(Nseq,Nbit);
B=binarize(B);
size(B)
filename=sprintf('%s_B.mat',groupname);
save(filename);
% save the active groupname
save 'activegroup' groupname;
3. Baseline_modulator.m
The student must change the “baseline” name at the beginning and end of Baseline_modulator.m
to be their alias in order to make this program their own. The modulator does two things, (1)
upsample the bit streams to pseudo-continuous time and (2) modulate the cosine and sine wave
carriers by the two bit streams, respectively.
% generate bit matrix based on groupname_Bsize.mat
clear all;
Nshowbits=8;
load 'ee51215V6_B.mat';
load 'ee51215V6_Bsize.mat';
% generate a real vector s, N=131072*8 or let N be less for debug process
N=131072*8 % N is set by instructor and cannot be changed
Nbit
Nseq
% CREATE THE MESSAGE SIGNAL
Nsample=floor(N/Nbit)
% form pulse shape
pulseshape=ones(1,Nsample);
% two bit sequences
b1(1:Nbit)=B(1,1:Nbit);
b2(1:Nbit)=B(2,1:Nbit);
stemp1=kron(b1,pulseshape); % form continuous time approximation of message
stemp2=kron(b2,pulseshape); % form continuous time approximation of message
sm1=-ones(1,N);
sm2=-ones(1,N);
if N > (Nsample*Nbit)
sm1(1:(Nsample*Nbit))=stemp1(1:(Nsample*Nbit));
sm2(1:(Nsample*Nbit))=stemp2(1:(Nsample*Nbit));
else
sm1=stemp1;
2
sm2=stemp2;
end;
size(sm1) % verify shape
% plot message signal or a section of the message signal
figure(1);
if Nbit<(Nshowbits+1)
n=1:N;
subplot(2,1,1);
plot(n,sm1);
axis([1,N,-1.1,1.1]);
xlabel('Message Signal 1');
subplot(2,1,2);
plot(n,sm2);
axis([1,N,-1.1,1.1]);
xlabel('Message Signal 2');
else
n=1:(Nsample*Nshowbits);
subplot(2,1,1);
plot(n,sm1(1:(Nsample*Nshowbits)));
axis([1,(Nsample*Nshowbits),-1.1,1.1]);
xlabel('Sample section of Message Signal 1');
subplot(2,1,2);
plot(n,sm2(1:(Nsample*Nshowbits)));
axis([1,(Nsample*Nshowbits),-1.1,1.1]);
xlabel('Sample section of Message Signal 2');
end;
print -djpeg Modulator_figure1
Fig. 3.1 shows sample sections from the two bit streams after upsampling to pseudo-continuous
time.
Figure 3.1: Samples of first few bits from input sequences.
The spectra of the two bit sequences are shown in Fig. 3.2.
% FT of message waveform
3
Sm1=abs(fft(sm1));
Sm2=abs(fft(sm2));
% suppress dc term
Sm1(1)=0;
Sm2(1)=0;
%
figure(2);
k=0:(N-1);
k=k-N/2;
subplot(2,1,1);
plot(k,fftshift(Sm1));
xlabel('DFT spectrum of Message Signal 1');
subplot(2,1,2);
plot(k,fftshift(Sm2));
xlabel('DFT spectrum of Message Signal 2');
print -djpeg Modulator_figure2
Notice how wide band they are but most of the information is contained in the mainlobe.
Figure 3.2: Spectra of input sequences with dc suppressed.
The modulator directly modulates the phase of the cosine and sine wave with message signals 1
and 2, respectively. The mathematical representation of this approach is:
s t   cosb1 t   2f c t   sin b2 t   2f c t 
(3.1)
4
% INSERT MODULATION
% INSERT MODULATION
% INSERT MODULATION
% create quadrature
t=0:(N-1);
kc=????
s=?????;
% END OF MODULATION
% END OF MODULATION
% END OF MODULATION
EQUATION:
EQUATION:
EQUATION: Inputs sm vector, kc, t and N
signal s
INSERT
INSERT
INSERT
The resulting waveform is shown for a sample section in Fig. 3.3.
% plot AM signal
figure(3);
if Nbit<(Nshowbits+1)
plot(s);
axis([1,N,-2.1,2.1]);
xlabel('quadrature Signal');
else
Ntemp=Nsample*Nshowbits;
plot(s(1:Ntemp));
axis([1,Ntemp,-2.1,2.1]);
xlabel('Sample section of quadrature Signal');
end;
print -djpeg Modulator_figure3
Notice the amplitude is constant. Using Eq. (3.1), can you show the amplitude is constant?
Figure 3.3: Sample from 2 bit modulated quadrature signal.
The resulting modulated signal spectrum is shown in Fig. 3.4.
5
Figure 3.4: Spectrum of modulated quadrature PSK signal.
The modulator is allowed to generate a “bitcheck” signal to be used later by the bitcheck.m
program for determining errors from the demodulated signal. This data is stored in
aliasname_Bcheck.mat file. The demodulator is not allowed to access this file. The bit check
values 1 and -1 are used to tell the bitcheck.m program to test the demodulated signal at those
locations for a “1” or “0”, respectively.
Figure 3.5: Sample section of bitcheck signals overlayed with the bit signals.
% create the bit check matrix to only be used by the Bcheckxx.m file
% YOU CANNOT PASS THIS INFORMATION TO YOUR DEMODULATOR!!
samplepulse=zeros(1,Nsample);
samplepulse(floor(Nsample/2))=1;
Bcheck=zeros(2,N);
% modulate first sequence to either +1 and -1 values
b1check(:,1:Nbit)=2*B(:,1:Nbit)-1;
bchecktemp=kron(b1check,samplepulse);
Bcheck=zeros(2,N);
if N > (Nsample*Nbit)
Bcheck(:,1:(Nsample*Nbit))=bchecktemp(:,1:(Nsample*Nbit));
else
Bcheck=bchecktemp;
end;
figure(5);
if Nbit<(Nshowbits+1)
n=1:N;
subplot(2,1,1);
plot(n,sm1,n,Bcheck(1,:));
6
axis([1,N,-1.1,1.1]);
xlabel('Bit Check Signal');
subplot(2,1,2);
plot(n,sm2,n,Bcheck(2,:));
axis([1,N,-1.1,1.1]);
xlabel('Bit Check Signal');
else
Ntemp=Nsample*Nshowbits;
n=1:Ntemp;
subplot(2,1,1);
plot(n,sm1(1:Ntemp),n,(0.9*Bcheck(1,1:Ntemp)));
axis([1,Ntemp,-1.1,1.1]);
xlabel('Sample Section of Bit Check Signal 1');
subplot(2,1,2);
plot(n,sm2(1:Ntemp),n,(0.9*Bcheck(2,1:Ntemp)));
axis([1,Ntemp,-1.1,1.1]);
xlabel('Sample Section of Bit Check Signal 2');
end;
print -djpeg Modulator_figure5
save 'ee51215V6_signal' s;
save 'ee51215V6_Bcheck' Bcheck;
4. Channel15.m
The instructor “owns” Channelxx.m. The channel first filters the modulated signal and then adds
Gaussian noise to it. The input signal spectrum is shown in Fig. 4.1.
Figure 4.1: Modulated signal in log scale.
The first operation that the channel does is filter the input signal. In this case, the channel is a
lowpass system represented by the spectrum shown in Fig. 4.2.
7
Figure 4.2: Spectrum of channel.
The output spectrum of the filtered signal is shown in Fig. 4.3.
Figure 4.3: Spectrum of Signal after being filtered by the channel.
A sample section of the input signal is shown in Fig. 4.4.
Figure 4.4: Sample of signal before entering the channel.
The same sample section as shown in Fig. 4.4 is passed through the channel filter and shown in
Fig. 4.5. Notice the boundaries where there was a drastic change in value are now suppressed.
These are the some of the transition boundaries.
8
Figure 4.5: Sample of signal after being filtered by the channel.
The filtered signal is evaluated for range and based on the range, a fractional amount of Gaussian
noise is added to the signal. The same sample section with the added noise is shown in Fig. 4.6
Figure 4.6: Sample of signal coming out of the channel after being filtered and corrupted by additive noise.
5. Baseline_demodulator.m
The demodulator uses two “legs” where one is the in-phase leg and the second is the quadrature
leg. The in-phase result is obtained by mixing with a cosine and the quadrature is determined by
mixing with a sine wave.
% generate bit matrix based on groupname_Bsize.mat
clear all;
load 'ee51215V6_Bsize'; % get number of bits and sequences
load 'ee51215V6_r';
[M,N]=size(r)
figure(12)
Nsample=floor(N/Nbit)
if Nbit<41
plot(r);
axis([1,N,-2.1,2.1]);
xlabel('Received quadrature Signal');
else
Ntemp=Nsample*40;
9
plot(r(1:Ntemp));
axis([1,Ntemp,-2.1,2.1]);
xlabel('Sample section of Received quadrature Signal with Noise');
end;
print -djpeg Demod_figure12
The input signal is shown in Fig. 5.1 and the demodulator is shown in Fig. 5.2.
Figure 5.1: Input signal to the demodulator.
Figure 5.2: Quadrature demodulator.
% INSERT DEMODULATION CODE:
% INSERT DEMODULATION CODE:
% INSERT DEMODULATION CODE: input cutoff fc and r
t=0:(N-1);
kc=????
si=cos(2*pi*kc*t/N)/2;
sq=sin(2*pi*kc*t/N)/2;
ri=-r.*si;
rq=-r.*sq;
10
% form reconstruction filter
% filter with some recommended parameters
Norder=8;K=1; % filter gain
[f H]=lp_butterworth_oN_dft15(kc,K,N,Norder);
% filter signal through channel via frequency domain
Si=fft(ri);Ri=Si.*H;
Sq=fft(rq);Rq=Sq.*H;
rni=real(ifft(Ri));
rnq=real(ifft(Rq));
rni=rni/max(abs(rni));
rnq=rnq/max(abs(rnq));
% END OF DEMODULATION INSERT: output real vector rn that is N long
% END OF DEMODULATION INSERT:
% END OF DEMODULATION INSERT:
The output of the quadrature demodulator for the first few bits is shown in Fig. 5.3.
Figure 5.3: Separated and demodulated bit signals.
The output of the demodulator must be scaled between 0 and 1 for bitcheckxx.m to process.
% normalize the output to be tested
% Bs must be scaled from about 0 to 1 so it can be thresholded at 0.5 by
% Bcheck
Bs=zeros(2,N);
bs=rni;
bs=bs/max(bs);bs=(bs+1)/2;
Bs(1,1:N)=bs(1:N);
bs=rnq;
bs=bs/max(bs);
bs=(bs+1)/2;
Bs(2,1:N)=bs(1:N);
figure(13)
if Nbit<41
subplot(2,1,1);
plot(Bs(1,:));
axis([1,N,-0.1,1.1]);
xlabel('Demodulated inphase Signal 1');
subplot(2,1,1);
plot(Bs(2,:));
11
axis([1,N,-0.1,1.1]);
xlabel('Demodulated quadrature Signal 2');
else
Ntemp=Nsample*40;
subplot(2,1,1);
plot(Bs(1,1:Ntemp));
axis([1,Ntemp,-0.1,1.1]);
xlabel('Sample section of Demodulated inphase Signal 1 with Noise');
subplot(2,1,2);
plot(Bs(2,1:Ntemp));
axis([1,Ntemp,-0.1,1.1]);
xlabel('Sample section of Demodulated quadrature Signal 2 with Noise');
end;
print -djpeg Demod_figure13
Using the in-phase response signal as “x” and the quadrature as “y” a signal space distribution
map can be formed as shown in Fig. 5.4.
%% make a signal space plot
Nx=512;My=512;
amap1=Nx/(2*max(abs(rni)));
amap2=My/(2*max(abs(rnq)));
xc=Nx/2;yc=My/2;
A=zeros(My,Nx);
for n=1:N
x=floor(xc+rni(n)*amap1);
if x<1
x=1;
end;
if x>Nx
x=Nx;
end;
y=floor(yc+rnq(n)*amap2);
if y<1
y=1;
end;
if y>My
y=My;
end;
A(y,x)=A(y,x)+1;
end;
figure(14);
A=-A; A=A-min(min(A));
imagesc(A);
title('Signal Space Response');
xlabel('In phase response');
ylabel('Quadrature phase response');
colormap gray;
print -djpeg Demod_figure14
%%
save 'ee51215V6_Bs' Bs;
12
Figure 5.4: Signal space mapping of entire PSK signal after demodulation.
6. Bitcheck.mDetectionandAnalysis
The bitcheck.m program takes in the demodulated and possibly decoded signals from the
demodulator. Bitcheck.m also has access to the bitcheck signal for evaluating the bit error
performance. Fig. 6.1 shows a sample section from the input signal superimposed with the
bitcheck signal. The threshold of the signal is 0.5 so if a bitcheck value is +1 then the input
signal should be a “1” and have a value above 0.5 to be correct. And when the bitcheck value is 1, then the input signal should be below 0.5 indicating a “0” is present.
13
Figure 6.1: Sample section overlayed bitcheck with input signal.
The data and bitcheck information comes to Bitcheck.m in matrix form where each row is a
different bit sequence in pseudo-continuous time. For simplicity, bitcheck.m converts the
matrices to vectors or a single sequence by lexicographical conversion as shown in Fig. 6.2.
Figure 6.2: Graphical representation of lexicographical conversion.
The distributions in Fig. 6.3 contain the histogram data from both sequences combined. The “1”
signal values and the “0” signal values have be separated at the bitcheck locations.
14
Figure 6.3: Distribution of "1s" and "0s" from both bit sequences.
The text output of bitcheck.m contains important information about the performance. A sample
output is below:
groupname = ee51213V6
filename =ee51213V6_Bsize.mat
Nbitsingle = 32768
NbitALL = 65536
Nseqnow = 2
N = 1048576
NALL = 2097152
ans = OK: bitcheck matrices consistant
nbsent = 65536
nbreceived = 65536
miss = 0
false = 0
Nerror = 0
mu1 = 0.7655
mu0 = 0.2344
STD1 =
STD0 =
0.0508
0.0504
15
SQRT of SNR1 =
SQRT of SNR0 =
Discriminate =
15.0652
4.6542
7.4252
The “miss” and “false” are error counts for missed “1” detection and incorrect “0” detections or
false alarms. The sum of misses plus false alarms is the total number of errors Nerror.
The mean values for the detected signals of “1” and “0” are mu1 and mu0 respectively. These
are found by taking the values at the bitcheck locations and averaging them together. They
should correspond to the peak locations in Fig. 6.3. The standard deviations, STD1 and STD0,
are calculated from the signal values at the bitcheck locations, just like the mean values are. The
discriminant measure is the absolute difference in the means divided by the square root of the
sum of the variances such that.
J 01 
1   0
 12   02
16
Download