Académique Documents
Professionnel Documents
Culture Documents
Audio Channel
Dag Björklund
1
Contents
1 Introduction 3
1.1 Using the Modem . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Channel Characteristics 4
3 Modulation 4
4 Error Coding 7
6 Protocol 9
6.1 Reliable Transmission . . . . . . . . . . . . . . . . . . . . . . . . 9
A Main Files 12
B Modulate, Demodulate 14
C Noise Calculation 15
D OFDM 17
E CRC 17
2
1 Introduction
This report describes an implementation of a OFDM modem using PC sound cards
and Matlab
c
[2]. Currently the system can be used to transmit files from a com-
puter running Matlab to another. It would take some amount of trivial work to
be able to generate C code and a standalone application. To achieve a more real
modem, would take some C programming, so that e.g. program would fork hav-
ing one process listening for messages over the channel and another listening for
input from the local user.
The system was developed on a Pentium III laptop with a cable looping back
the speaker connector to the microphone. This channel was very poor, and thus the
modem performance is modest. On other systems one could perhaps achieve a lot
better transmission. It would be very difficult to create a modem, that could nego-
tiate all parameters so that it would work on any PC/sound card etc. combination.
Therefore, this system is mainly intended to work on my specific computer.
Figure 1 shows the basic blocks of the system. The convolutional and cyclic
coding will be described in Section 4 and the OFDM blocks in Section 3. The
labels on the connections show the size of the message, Mt is a binary message of
size n, the convolutional coding currently in use will double it etc. (probably not
good). The OFDM modulator will leave the message length about the same with
a QAM constellation of four points, QAM-16 would result in half the length of
the vector.
cyclic conv Mr
A/D OFDMr
decode decode
3
receive to start receiving, whereafter the sender calls send( filename ),
where filename is the file to be sent.
2 Channel Characteristics
An important question associated with a communication channel is the maximum
rate at which it can transfer information.
The spectrum of the noise for a received message Si is Ni = Si − S, where S
was the original signal. The average standard deviation of the noise in M trans-
mitted messages becomes:
M
1 X
σN = σN
M i=1 i
I use chirp signals to obtain experimental results for σN , the Matlab code for this
is included in Appendix C.
The error probability Pe can now be calculated using:
j−1 d
Pe = 2 Q j = 2i
j σN
Where i is the number of levels and d is the signal level. For my channel I obtained
σN ≈ 17. With two levels and a signal level of 2 the error probability would
become ≈ 0.69, which is very high (the value for Q(x) was obtained from a table).
On my computer I only seem to be able to use sampling rates of 8000Hz, so
the maximum bandwidth would be B=Fs/2=4000Hz. The theoretical maximum
bitrate can now be calculated using:
For my channel I obtained the bitrate 3Kb/s. This theory sets the upper limit for
the transmission rate; however, it does not say anything about how to achieve it.
3 Modulation
The serial digital data signal is modulated using orthogonal frequency division
multiplexing (OFDM), which was introduced by Robert W. Chang in [1]. The
OFDM transmitter block from section 1 is refined as depicted in Figure 3, the
receiver is implemented in the reversed order. OFDM can be considered a sum of
4
Mt n conv. 2n cyclic 2n+k 2n+k+1
OFDMt D/A
encode encode
QAM IFFT CP
encoder
3 13 9 8 12
1 1 0
1 5 1 0 4
Quadrature
Quadrature
−1 7 3 2 6
−1 3 2
−3 15 11 10 14
−1 1 −3 −1 1 3
In−phase In−phase
(a) (b)
Figure 3: (a) 4-symbol QAM constellation (b) 16-symbol QAM constellation
5
Eye Diagram
1
0.8
0.6
0.4
0.2
Amplitude
−0.2
−0.4
−0.6
−0.8
−1
−6 −4 −2 0 2 4 6
Time −5
x 10
can be overcome by attaching a copy of the OFDM symbol in front of the trans-
mitted symbol as depicted in Figure 3. When this cyclic prefix is longer than the
channel impulse response, the received signal is a cyclic convolution of the trans-
mitted signal and the channel response, which maintains the orthogonality of the
subcarriers over a dispersive channel. The Matlab code for the OFDM transmitter
and receiver can be found in appendix 3. The OFDMt function accepts a matrix of
binary values as input, as do the modulate, demodulate etc. functions. Each
row in the matrix is modulated separately, so the widht of the matrix, becomes the
N points in the OFDM. This is because the more points we have for the OFDM,
the better performance is required from the channel. The sender would split the
message to be sent into this matrix format, so that we can have larger frames;
however, because of some problems sending longer messages over the channel on
my computer, I do not use this capability, but it is still implemented in the modem.
Cyclic
prefix
Time
6
That is, I only send vectors.
4 Error Coding
The modem uses convolutional and cyclic coding for error correction, and CRC
coding for error detection. The convolutional coding uses the trellis in the figure
below.
00 00
00
00
01 01
01
10
01 01
00
11
01 01
The convolutional coding doubles the length of the message. Both convolu-
tional and cyclic coding improve the bit error rate; however, they produce a lot of
overhead which is particularly bad since the frame length is very restricted.
The modem is lacking a data scrambling block, which should be added to
avoid long sequences of 1’s or 0’s.
The CRC coding is descring in section 6.
7
0.8
0.6
0.4
0.2
−0.2
−0.4
−0.6
−0.8
Poll signal
Chrip Message
−1
0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Figure 7: Synchronization
actual message, a chirp pilot signal resides. The Matlab code below is used by
the transmitter to send the poll signals. So the distance between the poll signals
in the figure is actually the loop overhead from this for loop. This overhead is
essentially the thing that makes the synchronization so difficult.
for k=1:10
wavplay( poll_sig, TxFs, ’sync’ )
end
The receiver reads input, e.g. 5 times longer sequences from the sound card, and
checks if there is a poll signal within this input, if so, it tries to read a message. The
chirp signal is then used to synchronize exactly to the first value of the message,
by detecting the peak of correlation between the read vector, and a chirp.
8
transmission parameters. The handshaket function very simply tries to send
a message using the 16-symbol QAM constellation (see section 3), if it receives
acknowledgement from the receiver, it will return the value 4, denoting 16-symbol
QAM, otherwise it returns 2. The hanshaker function analogically returns 4, if
it receives a message.
6 Protocol
The modem uses a very simple protocol.
9
Sender Receiver Sender Receiver
Fram Fram
Timeout e e
Timeout
Time
ACK ACK
(a) (b)
Figure 8: Timeline showing two different scenarios (a) The ACK is received be-
fore the timer expires; (b) the ACK is lost
Frame Format
The format of the frames now simply becomes as in figure 6.1. The CRC takes up
8 bits.
16 8
Body CRC
There is some problem with the channel that makes the signal die out when
sending longer messages. This limits the length of the frames I am able to send
very brutally. Figure 6.1 shows a signal obtained by the receiver, the signal should
fill out the whole figure, but dies out too soon. As seen in Figure 6.1, I am using
only 16 bits body in the frame.
10
1
0.8
0.6
0.4
0.2
−0.2
−0.4
−0.6
−0.8
−1
0 0.005 0.01 0.015 0.02 0.025
values from the signal. Naturally this again doubles the vector to be sent, which
is a bad thing.
11
received errorfree message
received errorfree message
error
error
received errorfree message
received 12 bytes in 32 s (3 b/s)
It can sometimes take seconds between received error free frames, and since
the frames are only 16 bits long, the data rate is low. I believe that it is impos-
sible to achieve fast synchronization on my system, so the first goal should be to
increase the frame sizes. Currently I giving
References
[1] Robert W. Chang. Synthesis of bandlimited orthogonal signals for multichan-
nel data transmission. Bell System Tech. Journal, pages 1775–1796, Decem-
ber 1966.
Appendix
The appendix contains some of the matlab files implementing the modem.
A Main Files
send.m
function send( filename )
% this is the main file for the transmitter
CommSetup
fid=fopen( filename );
sentm=[];
NoMsgQAM=NoMsgCyclic/(const/2)+2+(mod(NoMsgCyclic,2)~=0); %+2;
NoMsgQAMCP=NoMsgQAM+PreFixNo;
NoMsgWinQAM=NoMsgQAMCP;
NoMsgOS=2*NoMsgWinQAM;
12
% loop till end of file
eof=0;
while eof==0
b=[];
for k=1:2
if feof(fid)==0
b=[b fread(fid,1,’uchar’)];
end
end
sentm=[sentm b];
if feof(fid)
fprintf(’end of file encoutered\n’)
eof=1;
b=EOF;
else
b=iv2bv(b);
end
while 1
%connect(sig, TxFs)
for k=1:11
wavplay( [sig sig sig ],TxFs,’sync’)
end
wavplay(m,TxFs,’sync’);
if connection
fprintf(1,’Got ACK\n’)
pause(0.2)
break;
end
end
end
sentm
fclose(fid);
receive.m
% this is the main function for the receiver
CommSetup;
msg=[];
fprintf(1,’Answering...\n’)
tic
NoMsgQAM=NoMsgCyclic/(const/2)+2+(mod(NoMsgCyclic,2)~=0);
NoMsgQAMCP=NoMsgQAM+PreFixNo;
NoMsgWinQAM=NoMsgQAMCP;
NoMsgOS=2*NoMsgWinQAM;
in=0;
rows=1;
NoFrames=0;
eof=0;
while eof==0
gotit=0;
while gotit ~= 1
mat=0;
% try to ’answer’
if answer(1, RxFs, sig )
13
mat=1;
end
if mat==1 %connection
y = wavrecord((rows*NoMsgOS+2*NoChirp+NoDelayRx),RxFs)’;
if max(y) > 0.3
t=round(toc);
fprintf(1,’received %d bytes in %d s (%d b/s)’,NoFrames*2,t,round(NoFrames*2*8/t) )
msg
B Modulate, Demodulate
modulate.m
function m=modulate( Msg, Chirp, NoMsgWinQAM, PreFixNo,
RcosSyncLevel,r,tblen,const )
Win = kaiser(NoMsgWinQAM+1,r)’;
for k=1:size(Msg,1)-1
Win=[Win ; Win];
end
Msg2=CRCencode(Msg);
Msg6=linearmap1(Msg5,RcosSyncLevel,-RcosSyncLevel);
Msg7=[Chirp Msg7];
m=Msg7;
14
demodulate.m
function [m,err]=demodulate( rows, Chirp, y,NoMsgOS,
RcosSyncLevel,PreFixNo,tblen,const )
A=[];
Xc=conv(Chirp(end:-1:1),y);
[Max,Ind]=max(Xc);
if length(y)>rows*NoMsgOS+Ind
A=y(Ind+1:Ind+rows*NoMsgOS+1); %(rows-1)*5);
% downsample
downsample=[];
k=1;
while 1
downsample=[downsample A(:,k+1)];
k=k+2;
if k>length(A)
break;
end
end
A=downsample;
A=linearmap1(A*sum((Chirp).^2)/Max,RcosSyncLevel,-RcosSyncLevel);
A=A(:,tblen+1:end);
[A,err]=CRCdecode(A);
else
fprintf(’Transmission error: Could not synchronize with pilot’)
err=1;
end
m=reshape(A’,1,size(A,1)*size(A,2));
C Noise Calculation
send.m
RxFs=11025;
TxFs=11025;
Td=0.1;
NoChirp=2^10;
Chirp=chirp(linspace(0,Td,NoChirp),200,Td,RxFs/12); %/2);
15
save TxSync;
fid=-1;
fprintf(1,’Syncing on Rx ...\n’);
while(fid==-1)
fid=fopen(’RxSync.mat’,’r’);
end
fclose(fid);
wavplay(Msg,TxFs,’sync’);
rec.m
RxFs=11025;
TxFs=11025;
Td=0.1;
NoChirp=2^10;
Chirp=chirp(linspace(0,Td,NoChirp),200,Td,RxFs/12); %/2);
save RxSync;
y = wavrecord(15*NoChirp,RxFs);
delete(’RxSync.mat’)
for k=1:length(y)
if abs(y(k))+abs(y(k+1))>0.2
k
y=y(k-50:end);
break;
end
end
sync=[];
for k=1:length(y)
if mod(k,51) ~= 0 %51
sync=[sync y(k)]; %o1=[o1 y1(k)];
end
end
y=sync;
y=linearmap1(y,-1,1);
Ss=zeros(9,NoChirp);
for k=1:9
Xc=conv( Chirp(end:-1:1), y(1:NoChirp+50) );
[Max,Ind]=max(Xc)
yc=y(Ind+1-NoChirp:Ind);
%y=y(Ind-50:end);
%figure,plot(yc),hold on, plot(Chirp,’r’)
Ss(k,:)=yc;
N(k,:)=abs(fft(yc))-abs(fft(Chirp));
%figure,plot(abs(fft(yc))),hold on, plot(abs(fft(Chirp)),’r’), hold off
%figure,plot(N(k,:))
end
%s=sum(Ss)/9;
%S=fft(s);
vars=[];
for k=1:9
N(k,:)
vars(k)=var(N(k,:))
%vars(k)=var( abs(fft(s(k))-S) );
end
power=sum(vars)/9
16
D OFDM
OFDMt.m
function y = OFDMt( x, const )
%if mod(length(x),2) ~= 0
% x = [x 0];
%end
x = [x zeros( size(x,1), ceil(length(x)/const)*const-length(x) )];
%y=zeros(size(x,1),size(x,2)/(const/2) +2);
for m=1:size(x,1)
dec=bi2de(reshape(x(m,:),const,length(x)/const)’)’;
y(m,:)=real(ifft(comp));
end
OFDMr.m
function X = OFDMr( x, const )
% function that implements a OFDM receiver. If x is matrix
% it will be OFDM ’encoded’ row by row
CommSetup
X=zeros(size(x,1),NoMsgCyclic ); %size(x,2)-3);
for m=1:size(x,1)
comp=fft(x(m,:));
comp=comp(2:length(x)/2);
dec=demodmap([real(comp); -imag(comp)]’ ,1,1,’qask’,2^const);
bi=de2bi(dec);
E CRC
CRCencode.m
function code=CRCencode( msg )
% function for row by row CRC encoding of msg
% generator polynomial
generator=[1 0 0 0 0 0 1 1 1];
for k=1:size(msg,1)
17
multip=conv(c,msg(k,:));
[divid,remainder]=deconv(multip,generator);
divid=mod(divid,2);
remainder=mod(remainder,2);
code(k,:)=xor(multip,remainder);
end
CRCdecode.m
function [msg,error]=CRCdecode( code )
% function for checking for errors row by row in tht matrix code
% where each row should be a CRC encoded message, and decoding the
% messages i.e. removing the CRC field from the back
% generator polynomial
generator=[1 0 0 0 0 0 1 1 1];
error=0;
for k=1:size(code,1)
[m,r]=deconv(code(k,:), generator );
error=error | sum(mod(r,2));
end
msg=code(:,1:end-length(generator)+1);
18