OFDM Final Report
OFDM Final Report
Final Report
Study by:
Alan C. Brooks
Stephen J. Hoelzer
Department:
Electrical and Computer Engineering
Advisors:
Dr. Thomas L. Stewart
Dr. In Soo Ahn
Abstract:
A MATLAB program has been written to investigate Orthogonal Frequency Division
Multiplexing (OFDM) communication systems. This program is valuable for future researchers
simulating systems that are too theoretically complex to analyze. Single-carrier QAM and multi-
carrier OFDM are compared to demonstrate the strength of OFDM in multipath channels. Two
graphical user interface demonstrations show some of the basic concepts of OFDM.
1
Introduction
The Electrical Engineering Senior Capstone Project is intended to give each student
experience in completing a sophisticated design project that spans most of the senior year.
the results are integrated with the technical design task. The students work with one or two
faculty advisors who have expertise in the project research area. The student is fully responsible
for the design project, with the advisor(s) acting as guide and mentor. Each student is expected to
work an eight-hour lab period each week from October through May.
(ISI). ISI occurs when a transmission interferes with itself and the receiver cannot decode the
transmission correctly. For example, in a wireless communication system such as that shown in
Because the signal reflects from large objects such as mountains or buildings, the receiver sees
more than one copy of the signal. In communication terminology, this is called multipath. Since
the indirect paths take more time to travel to the receiver, the delayed copies of the signal
Theory
research and simulation. OFDM is especially suitable for high-speed communication due to its
resistance to ISI. As communication systems increase their information transfer speed, the time
for each transmission necessarily becomes shorter. Since the delay time caused by multipath
remains constant, ISI becomes a limitation in high-data-rate communication [1]. OFDM avoids
this problem by sending many low speed transmissions simultaneously. For example, Figure 2
shows two ways to transmit the same four pieces of binary data.
Suppose that this transmission takes four seconds. Then, each piece of data in the left picture has
a duration of one second. On the other hand, OFDM would send the four pieces simultaneously
as shown on the right. In this case, each piece of data has a duration of four seconds. This longer
3
duration leads to fewer problems with ISI. Another reason to consider OFDM is low-complexity
implementation for high-speed systems compared to traditional single carrier techniques [2].
Significance
With the rapid growth of digital communication in recent years, the need for high-speed
data transmission has increased. New multicarrier modulation techniques such as OFDM are
currently being implemented to keep up with the demand for more communication capacity.
Multicarrier communication systems “were first conceived and implemented in the 1960s, but it
was not until their all-digital implementation with the FFT that their attractive features were
unraveled and sparked widespread interest for adoption in various single-user and multiple
access (MA) communication standards” [2]. The processing power of modern digital signal
processors has increased to a point where OFDM has become feasible and economical.
Examining the patents, journal articles, and books available on OFDM, it is clear that this
technique will have an impact on the future of communication. See the references section
(starting on page 21) for a condensed bibliography and list of patents related to this topic. Since
many communication systems being developed use OFDM, it is a worthwhile research topic.
Some examples of current applications using OFDM include GSTN (General Switched
Telephone Network), Cellular radio, DSL & ADSL modems, DAB (Digital Audio Broadcasting)
(High Performance Local Area Network standard), and the wireless networking standard IEEE
Simulation Design
The transmitter first converts the input data from a serial stream to parallel sets. Each set of data
contains one symbol, Si, for each subcarrier. For example, a set of four data would be [S0 S1 S2
S3]. Before performing the Inverse Fast Fourier Transform (IFFT), this example data set is
This symmetrical arrangement about the vertical axis is necessary for using the IFFT to
manipulate this data. An inverse Fourier transform converts the frequency domain data set into
samples of the corresponding time domain representation of this data. Specifically, the IFFT is
useful for OFDM because it generates samples of a waveform with frequency components
satisfying orthogonality conditions. Then, the parallel to serial block creates the OFDM signal by
such as noise, multipath, and clipping [5]. By adding random data to the transmitted signal,
simple noise is simulated. Multipath simulation involves adding attenuated and delayed copies of
the transmitted signal to the original. This simulates the problem in wireless communication
when the signal propagates on many paths. For example, a receiver may see a signal via a direct
path as well as a path that bounces off a building. Finally, clipping simulates the problem of
amplifier saturation. This addresses a practical implementation problem in OFDM where the
The receiver performs the inverse of the transmitter. First, the OFDM data are split from
a serial stream into parallel sets. The Fast Fourier Transform (FFT) converts the time domain
samples back into a frequency domain representation. The magnitudes of the frequency
6
components correspond to the original data. Finally, the parallel to serial block converts this
parallel data into a serial stream to recover the original input data.
Results
The MATLAB simulation accepts inputs of text or audio files as well as binary,
sinusoidal, or random data. It then generates the corresponding OFDM transmission, simulates a
channel, attempts to recover the input data, and performs an analysis to determine the
transmission error rate. In order to compare OFDM to a traditional single carrier communication
system, a 16-QAM simulation can be performed. These simulations are dynamic, allowing the
user to set parameters determining the characteristics of the communication system. Two simple
demonstrations of OFDM communication were developed with a graphical user interface (GUI)
following the style of MATLAB toolbox demonstrations. These allow someone to quickly learn
The first demonstration, basicgui (or basicgui_win), introduces the process of creating an
OFDM symbol. It shows a simple example of using the Fourier transform to send binary data on
four frequencies. The following screenshots show the demo sequence with explanations in the
text box.
7
8
9
10
The second demonstration, soundgui (or soundgui_win), gives a more technical example.
It compares OFDM to 16-QAM in a multipath channel. The user can choose no, small, or large
amount of multipath. The following screenshots show the demo sequence with explanations in
The two GUI demonstrations utilize the complete simulation code, but not all of its
capabilities. By modifying the setup.m m-file, users can adjust parameters such as the fft_size,
num_carriers, input types, and channel characteristics. It also allows detailed analysis of the
communication system. Plots showing OFDM input and output, 16-QAM input and output, and
the received 16-QAM signal constellation are generated. See Figures 5, 6, and 7 for examples of
these plots.
16
Depending on the input type chosen, appropriate output files are created. This enhances the
numerical error analysis by showing how the errors degrade the data being transmitted. For one
test, the preamble of the US constitution was transmitted. Figure 8 shows the results.
OFDM transmission had a very low bit error rate of 0.0699% so only four errors were caused by
the multipath channel. 16-QAM incurred a 23.0% bit error rate. Since a character is represented
by eight bits, every character had two bits in error on average. This resulted in unintelligible
received text.
20
A second test using an audio file produced similar results. The difference is that users can
see and hear the degradation caused by binary errors. Figure 9 shows plots of the audio files.
In this case, the original sound is a guitar plucking a chord. The OFDM sound contains audible
“clicks” due to bit errors and the waveform is similar to that of the original sound. The 16-QAM
sound’s waveform does not resemble the original and listening to the 16-QAM sound confirms
this. The original guitar chord is barely discernable underneath loud static noise.
Conclusion
This MATLAB simulation proves that OFDM is better suited to a multipath channel than
a single carrier transmission technique such as 16-QAM. This program is available on the
http://cegt201.bradley.edu/projects/proj2001/ofdmabsh/.
Future research may be based on this project. These extensions may include channel
phase shift detection and correction, error correction by coding, adaptive transmission, peak to
References
Bibliography
[4] Van Nee, Richard, and Ramjee Prasad. OFDM for Wireless Multimedia
Communications. Boston: Artech House, 2000.
[5] Naguib, Ayman F., Nambi Seshadri, and A. R. Calderbank. “Increasing Data Rate
over Wireless Channels.” IEEE Signal Processing Magazine (May, 2000): 76-92
[9] Lawrey, Eric. OFDM Wireless Technology. 11 May 2000. 7 Nov. 2000.
http://www.eng.jcu.edu.au/eric/thesis/Thesis.htm
22
References (cont.)
Patent History
Class/Subclass
Historical
Current
370/208
6,125,124 Synchronization and sampling frequency in an apparatus receiving OFDM
modulated transmissions (Sept 26, 2000)
6,021,110 OFDM timing and frequency recovery system (Feb 1, 2000)
708/404
6,115,728 Fast fourier transforming apparatus and method, variable bit reverse
circuit, inverse fast fourier transforming apparatus and method, and
OFDM receiver and transmitter (Sept 5, 2000)
23
Appendix
May 1, 2001
24
break
clf
subplot(211), plot(W/(2*pi),mag)
subplot(212), plot(W/(2*pi),phase)
break
% Design filter using MATLAB command 'fir1'
nn = 8; % order of filter
wl = 0.134; % low cutoff of stopband
wh = 0.378; % high cutoff of stopband
num = fir1(nn, 2*[wl, wh], 'stop');
den = 1;
clf
subplot(211), plot(W,mag), hold on, plot(wl*2*pi,0,'o'), plot(wh*2*pi,0,'o')
subplot(212), plot(W,phase), hold on, plot(wl*2*pi,0,'o'), plot(wh*2*pi,0,'o')
hold off
break
% Design filter by specifying delay in units and looking at mag and phase response
n = 512;
d1 =4;
a1 = 0.2;
25
d2 = 5;
a2 = 0.3;
mag = 20*log10(abs(H));
% phase = angle(H * 180/pi);
phase = angle(H);
clf
subplot(211), plot(W,mag), hold on, plot(0.17*pi,0,'o'), plot(0.34*pi,0,'o')
subplot(212), plot(W,phase), hold on, plot(pi/2,0,'o')
hold off
break
% Design filter by specifying mag response at particular frequencies
n = 2;
f = [0, 0.25, 0.5];
mag = [1, .05, 1];
mag = 20*log10(abs(H));
phase = angle(H * 180/pi);
clf
subplot(211), plot(W,mag)
subplot(212), plot(W,phase)
% a_run_demo.m
setup
QAM
OFDM
analysis
% analysis.m
% Analysis
figure(1), clf
if (input_type == 1) & (test_input_type == 1)
subplot(221), stem(data_in), title('OFDM Binary Input Data');
subplot(223), stem(output), title('OFDM Recovered Binary Data')
else
subplot(221), plot(data_samples), title('OFDM Symbol Input Data');
subplot(223), plot(output_samples), title('OFDM Recovered Symbols');
end
subplot(222), plot(xmit), title('Transmitted OFDM');
subplot(224), plot(recv), title('Received OFDM');
% dig_x_axis = (1:length(QAM_tx_data))/length(QAM_tx_data);
% figure(4), clf, subplot(212)
% freq_data = abs(fft(QAM_rx_data));
% L = length(freq_data)/2;
dig_x_axis = (1:length(xmit))/length(xmit);
figure(2), clf
if channel_on ==1
num = [1, zeros(1, d1-1), a1, zeros(1, d2-d1-1), a2];
den = [1];
[H, W] = freqz(num, den, 512);
26
mag = 20*log10(abs(H));
phase = angle(H) * 180/pi;
subplot(313)
freq_data = abs(fft(recv));
L = length(freq_data)/2;
plot(dig_x_axis(1:L), freq_data(1:L))
xlabel('FFT of Received OFDM')
axis_temp = axis;
subplot(311),
freq_data = abs(fft(xmit));
plot(dig_x_axis(1:L), freq_data(1:L)), axis(axis_temp)
title('FFT of Transmitted OFDM')
subplot(312)
plot(W/(2*pi),mag),
ylabel('Channel Magnitude Response')
else
subplot(212)
freq_data = abs(fft(recv));
L = length(freq_data)/2;
plot(dig_x_axis(1:L), freq_data(1:L))
xlabel('FFT of Received OFDM')
axis_temp = axis;
subplot(211),
freq_data = abs(fft(xmit));
plot(dig_x_axis(1:L), freq_data(1:L)), axis(axis_temp)
title('FFT of Transmitted OFDM')
end
% if file_input_type == 4
% figure(5)
% subplot(211)
% image(data_in);
% colormap(map);
% subplot(212)
% image(output);
% colormap(map);
% end
figure(3), clf
if (input_type == 1) & (test_input_type == 1)
subplot(221), stem(data_in), title('QAM Binary Input Data');
subplot(223), stem(QAM_data_out), title('QAM Recovered Binary Data')
else
subplot(221), plot(data_samples), title('QAM Symbol Input Data');
subplot(223), plot(QAM_output_samples), title('QAM Recovered Symbols');
end
subplot(222), plot(QAM_tx_data), title('Transmitted QAM');
subplot(224), plot(QAM_rx_data), title('Received QAM');
dig_x_axis = (1:length(QAM_tx_data))/length(QAM_tx_data);
figure(4), clf
if channel_on ==1
subplot(313)
freq_data = abs(fft(QAM_rx_data));
L = length(freq_data)/2;
plot(dig_x_axis(1:L), freq_data(1:L))
xlabel('FFT of Received QAM')
axis_temp = axis;
subplot(311),
freq_data = abs(fft(QAM_tx_data));
plot(dig_x_axis(1:L),freq_data(1:L)), axis(axis_temp)
title('FFT of Transmitted QAM')
subplot(312)
plot(W/(2*pi),mag)
ylabel('Channel Magnitude Response')
else
subplot(212)
freq_data = abs(fft(QAM_rx_data));
L = length(freq_data)/2;
plot(dig_x_axis(1:L), freq_data(1:L))
title('FFT of Received QAM')
27
axis_temp = axis;
subplot(211),
freq_data = abs(fft(QAM_tx_data));
plot(dig_x_axis(1:L),freq_data(1:L)), axis(axis_temp)
title('FFT of Transmitted QAM')
end
hold off
title('16-QAM Received Signal Constellation and Decision Boundarys')
binary_err_bits_QAM = 0;
for i = 1:length(data_in)
err = abs(data_in(i)-QAM_data_out(i));
if err > 0
binary_err_bits_QAM = binary_err_bits_QAM + 1;
end
end
BER_QAM = 100 * binary_err_bits_QAM/data_length;
end
figure(6), clf
if channel_on == 1
subplot(211), plot(W/(2*pi),mag),title('Channel Magnitude Response')
xlabel('Digital Frequency'),ylabel('Magnitude in dB')
subplot(212), plot(W/(2*pi),phase),title('Channel Phase Response')
xlabel('Digital Frequency'),ylabel('Phase in Degrees')
else
title('Channel is turned off - No frequency response to plot')
end
if (do_QAM == 1)
disp(strcat('QAM: BER=', num2str(BER_QAM,3), ' %'))
disp(strcat(' Number of error bits=', num2str(binary_err_bits_QAM)))
end
% Listen to sounds
if (input_type == 2) & (file_input_type == 3)
do_again = '1';
while ( ~(isempty(do_again)) )
disp(' ')
disp('Press any key to hear the original sound'), %pause
sound(data_samples,11025)
disp('Press any key to hear the sound after OFDM transmission'), %pause
sound(output_samples,11025)
28
if do_QAM == 1
disp('Press any key to hear the sound after QAM transmission'), %pause
sound(QAM_output_samples,11025)
end
do_again = '';
do_again = input('Enter "1" to hear the sounds again or press "Return" to end ', 's');
end
end
% BasicGUI.m
function BasicGUI()
% This is the machine-generated representation of a MATLAB object
% and its children. Note that handle values may change when these
% objects are re-created. This may cause problems with some callbacks.
% The command syntax may be supported in the future, but is currently
% incomplete and subject to change.
%
% To re-open this system, just type the name of the m-file at the MATLAB
% prompt. The M-file and its associtated MAT-file must be on your path.
load BasicGUI
'Units','points', ...
'CameraUpVector',[0 1 0], ...
'CameraUpVectorMode','manual', ...
'Color',[1 1 1], ...
'ColorOrder',mat2, ...
'Position',[44 130 294 235], ...
'Tag','AxesMain', ...
'Visible','off', ...
'XColor',[0 0 0], ...
'YColor',[0 0 0], ...
'ZColor',[0 0 0]);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[0.5 -0.0662393 0], ...
'Tag','Text1', ...
'VerticalAlignment','cap', ...
'Visible','off');
set(get(c,'Parent'),'XLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[-0.0767918 0.502137 0], ...
'Rotation',90, ...
'Tag','Text2', ...
'VerticalAlignment','baseline', ...
'Visible','off');
set(get(c,'Parent'),'YLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','right', ...
'Position',[-0.151877 1.08333 0], ...
'Tag','Text3', ...
'Visible','off');
set(get(c,'Parent'),'ZLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[0.5 1.0235 0], ...
'Tag','Text4', ...
'VerticalAlignment','bottom', ...
'Visible','off');
set(get(c,'Parent'),'Title',c);
% bin2eight.m
function y = bin2eight(x)
% bin2eight
%
% Converts binary data to an eight bit form
% Accepts 1x8 array and returns the corresponding decimal
y = 0;
k = 0;
for i = 1:8
y = y + x(8-k)*2^k;
k = k+1;
end
% bin2pol.m
function y = bin2pol(x)
% bin2pol
% Converts binary numbers (0,1) to polar numbers (-1,1)
% Accepts a 1-D array of binary numbers
y = ones(1,length(x));
for i = 1:length(x)
if x(i) == 0
y(i) = -1;
end
end
30
% ch.m
% ch
if channel_on == 1
disp('Simulating Channel')
ch_clipping
ch_multipath
ch_noise
end
% ch_clipping.m
% ch_clipping
for i = 1:length(recv)
if recv(i) > clip_level
recv(i) = clip_level;
end
if recv(i) < -clip_level
recv(i) = -clip_level;
end
end
% ch_multipath.m
% ch_multipath
copy1=zeros(size(recv));
for i=1+d1:length(recv)
copy1(i)=a1*recv(i-d1);
end
copy2=zeros(size(recv));
for i=1+d2:length(recv)
copy2(i)=a2*recv(i-d2);
end
recv=recv+copy1+copy2;
% ch_noise.m
% ch_noise (operate on recv)
% random noise defined by noise_level amplitude
if already_made_noise == 0 % only generate once and use for both QAM and OFDM
noise = (rand(1,length(recv))-0.5)*2*noise_level;
already_made_noise = 1;
end
recv = recv + noise;
31
% ComputeChannelGUI.m
% ComputeChannelGUI.m plots the current channel
popupHnd1=findobj('Tag','PopupMenuMultipath');
noChannel = 0;
if get(popupHnd1,'Value') == 3 % Large
d1 = 6;
a1 = 0.4;
d2 = 10;
a2 = 0.3;
elseif get(popupHnd1,'Value') == 2 % Small
d1 = 6;
a1 = 0.25;
d2 = 10;
a2 = 0.20;
else % None
noChannel = 1;
channel_on = 0;
break
end
num = [1, zeros(1, d1-1), a1, zeros(1, d2-d1-1), a2];
den = [1];
[H, W] = freqz(num, den);
mag = 20*log10(abs(H));
phase = angle(H) * 180/pi;
% plot(W/(2*pi),mag) % comment me out normally
% eight2bin.m
function y = eight2bin(x)
% eight2bin
%
% Converts eight bit data (0-255 decimal) to a binary form for processing.
y = zeros(1,8);
k = 0;
while x > 0
y(8-k) = rem(x,2);
k = k+1;
x = floor(x/2);
end
% OFDM.m
% Run OFDM simulation
tx
ch
rx
% OFDMguiFn.m
function OFDMguiFn(action)
% Consolidates all of the GUI callbacks into one main function
stringArray = [...
% Slide 1
'Welcome to the basic OFDM (Orthogonal Frequency '...
'Division Multiplexing) demo. Please click the Next '...
'button to get started. '...
' '...
' '...
' '...
' ';...
% Slide 2
'Assume that we want to transmit the following binary '...
'data using OFDM: [0 0 0 1 1 0 1 1]. '...
'The plot shows this binary data. '...
' '...
' '...
' '...
' ';...
% Slide 3
'In OFDM an IFFT (Inverse Fast Fourier Transform) is '...
'used to put the binary numbers onto many frequencies. '...
'Due to the math involved in an IFFT, these '...
'frequencies do not interfere with eath other (in '...
'communication terms, this is called "Orthogonality"). '...
'The plot shows that each group of 2 blue data points '...
'under a red hump will be put onto one frequency. ';...
% Slide 4
'The IFFT math is now complete. It has generated an '...
'OFDM signal that corresponds to the binary data. '...
'The plot shows the signal generated by the IFFT. '...
' '...
' '...
' '...
' ';...
% Slide 5 - same plot
'Now, this OFDM signal can be transmitted through a '...
'media and then received. This media (or "Channel" in '...
'communication) could be wired or wireless. Once the '...
'signal is received, the reverse process is done to '...
'recover the original binary data. '...
' '...
' ';...
% Slide 6
'Finally, an FFT (Fast Fourier Transform) is used to '...
'recover the binary data as shown in the plot. Note '...
'that the FFT is the opposite of the IFFT used to '...
'generate the OFDM signal. As long as the Channel does '...
'not distort the OFDM signal too much, the original '...
'binary data can be recovered. '...
' '];
switch(action)
case 'next' %---------------------------------------
textHnd1=findobj('Tag','StaticTextFeedback');
nextHnd1=findobj('Tag','PushbuttonNext'); % handler for the Next button
axisHnd1=findobj('Tag','Axes1');
global COUNTER
if isempty(COUNTER)
COUNTER = 0; % initialize COUNTER if doesn't exist
end
COUNTER = COUNTER + 1;
[r c]=size(stringArray);
if COUNTER > r
COUNTER = 0;
close(gcf)
basicGUI % set to file name in future!
else
set(textHnd1,'String',stringArray(COUNTER,:))
switch(COUNTER)
case 1
% disp('Slide 1')
case 2
% disp('Slide 2')
33
% OFDMguiFnSound.m
function OFDMguiFnSound(action)
% Consolidates all of the GUI callbacks into one main function
% Alan Brooks the man wrote this
stringArray = [...
% Slide 1
'Welcome to the Sound OFDM demo. This simulates QAM '...
'and OFDM using a sound file as input to demonstrate '...
'the advantages of using OFDM with a multipath '...
'channel. '...
'Choose the strength of multipath present in the '...
'channel and the plot will show the current channels '...
'frequency response. ';...
% Slide 2
'Here is a frequency domain (FD) representation of the '...
'QAM data to be transmitted. '...
'Press any key to continue. '...
' '...
' '...
' '...
' ';...
% Slide 2b
'For QAM (single-carrier) transmission, this plot '...
'shows the channel frequency response (black) and the '...
'received data (light blue) overlayed on the original '...
'data (blue). Note that the received data is slightly '...
'distorted due to the fading channel caused by '...
'multipath. '...
'Press any key to continue. ';...
% Slide 2c
'Here is a frequency domain (FD) representation of the '...
34
switch(action)
case 'next' %---------------------------------------
textHnd1=findobj('Tag','StaticTextFeedback');
nextHnd1=findobj('Tag','PushbuttonNext'); % handler for the Next button
% axis handlers
axisHnd1=findobj('Tag','Axes1'); % main
axisHnd2=findobj('Tag','AxesOriginal'); % original
axisHnd3=findobj('Tag','AxesQAM'); % QAM
axisHnd4=findobj('Tag','AxesOFDM'); % OFDM
% multipath handlers
textHnd2=findobj('Tag','StaticTextMultipath');
popupHnd1=findobj('Tag','PopupMenuMultipath');
% Generated Sounds handlers
textHnd3=findobj('Tag','StaticTextGenSounds');
OriginalHnd1=findobj('Tag','PushbuttonOriginal');
QAMHnd1=findobj('Tag','PushbuttonQAM');
OFDMHnd1=findobj('Tag','PushbuttonOFDM');
% Long Sounds handlers
textHnd4=findobj('Tag','StaticTextLongSounds');
OriginalLongHnd1=findobj('Tag','PushbuttonOriginalLong');
QAMLongHnd1=findobj('Tag','PushbuttonQAMLong');
OFDMLongHnd1=findobj('Tag','PushbuttonOFDMLong');
% BER handlers
textHnd5=findobj('Tag','StaticTextBER1'); % label
textHnd6=findobj('Tag','StaticTextBER2'); % label
textHnd7=findobj('Tag','StaticTextBERQAM'); % OFDM BER field
textHnd8=findobj('Tag','StaticTextBEROFDM'); % QAM BER field
global COUNTER
if isempty(COUNTER)
COUNTER = 0; % initialize COUNTER if doesn't exist
end
COUNTER = COUNTER + 1;
[r c]=size(stringArray);
if COUNTER > r
COUNTER = 0;
close(gcf)
SoundGUI % set to file name in future!
else
set(textHnd1,'String',stringArray(COUNTER,:))
switch(COUNTER)
case 1
% disp('Slide 1')
% Show/Hide the GUI
set(nextHnd1,'String','Next')
% show multipath controls
set(textHnd2,'Visible','on')
set(popupHnd1,'Visible','on')
% enable multipath controls
set(textHnd2,'Enable','on')
set(popupHnd1,'Enable','on')
% show main axis
set(axisHnd1,'Visible','on'),axes(axisHnd1)
% hide other axis's
set(axisHnd2,'Visible','off')
35
set(axisHnd3,'Visible','off')
set(axisHnd4,'Visible','off')
% hide generated sounds stuff
set(textHnd3,'Visible','off')
set(OriginalHnd1,'Visible','off')
set(QAMHnd1,'Visible','off')
set(OFDMHnd1,'Visible','off')
% hide long sounds stuff
set(textHnd4,'Visible','off')
set(OriginalLongHnd1,'Visible','off')
set(QAMLongHnd1,'Visible','off')
set(OFDMLongHnd1,'Visible','off')
% hide the BER displays
set(textHnd5,'Visible','off')
set(textHnd6,'Visible','off')
set(textHnd7,'Visible','off')
set(textHnd8,'Visible','off')
set(popupHnd1,'Value',1) % no channel by default
% default plot
plot(0:.05:.5,zeros(1,11)),axis([0 0.5 -12 6]),title('Channel Magnitude
Response')
xlabel('Digital Frequency'),ylabel('Magnitude (dB)')
case {2, 3, 4, 5}
% disp('Slide 2')
% disble multipath controls
set(textHnd2,'Enable','off')
set(popupHnd1,'Enable','off')
setupSoundGUI % sets up the Sound GUI variables
set(textHnd1,'String','QAM Simulation... Please Wait')
QAM
set(textHnd1,'String',stringArray(COUNTER,:))
fft_temp = abs(fft(QAM_tx_data));
fft_temp = fft_temp(1:floor(0.5*length(fft_temp))); % truncate (+ spectrum)
dig_x_axis = (1:length(fft_temp)) / (2*length(fft_temp));
plot(dig_x_axis, fft_temp)
title('FFT of Transmitted QAM')
% calculate the BER and store for slide 6
global BER_QAM_TEMP;
binary_err_bits_QAM = 0;
for i = 1:length(data_in)
err = abs(data_in(i)-QAM_data_out(i));
if err > 0
binary_err_bits_QAM = binary_err_bits_QAM + 1;
end
end
BER_QAM_TEMP = 100 * binary_err_bits_QAM/data_length;
COUNTER = COUNTER + 1;
pause
% disp('Slide 2b')
set(textHnd1,'String',stringArray(COUNTER,:))
hold on
% QAM Plotting
fft_temp = abs(fft(QAM_rx_data));
fft_temp = fft_temp(1:floor(0.5*length(fft_temp))); % truncate
plot(dig_x_axis, fft_temp,'c'),title(' ')
% channel display
if channel_on == 1
ComputeChannelGUI
size_mag=max(mag)-min(mag); % for scaled channel plot
plot(W/(2*pi),(0.5*max(fft_temp)/size_mag)*(mag +
abs(min(mag))) + 0.5*max(fft_temp),'k')
end
hold off
COUNTER = COUNTER + 1;
pause
% disp('Slide 2c')
set(textHnd1,'String','OFDM Simulation... Please Wait')
OFDM
set(textHnd1,'String',stringArray(COUNTER,:))
fft_temp = abs(fft(xmit));
fft_temp = fft_temp(1:floor(0.5*length(fft_temp))); % truncate
dig_x_axis = (1:length(fft_temp)) / (2*length(fft_temp));
plot(dig_x_axis, fft_temp)
title('FFT of Transmitted OFDM')
% calculate the BER and store for slide 6
global BER_OFDM_TEMP;
binary_err_bits_OFDM = 0;
36
for i = 1:length(data_in)
err = abs(data_in(i)-output(i));
if err > 0
binary_err_bits_OFDM = binary_err_bits_OFDM +1;
end
end
BER_OFDM_TEMP = 100 * binary_err_bits_OFDM/data_length;
COUNTER = COUNTER + 1;
pause
% disp('Slide 2d')
set(textHnd1,'String',stringArray(COUNTER,:))
hold on
% OFDM Plotting
fft_temp = abs(fft(recv));
fft_temp = fft_temp(1:floor(0.5*length(fft_temp))); % truncate
plot(dig_x_axis, fft_temp,'c'),title(' ')
% channel display
if channel_on == 1
plot(W/(2*pi),(0.5*max(fft_temp)/size_mag)*(mag +
abs(min(mag))) + 0.5*max(fft_temp),'k')
end
hold off
case 6
% disp('Slide 3')
setupSoundGUI
% hide main axis
plot(0) % clear the plot
axis off
% set(axisHnd1,'Visible','off')
% show other axis's
set(axisHnd2,'Visible','on')
set(axisHnd3,'Visible','on')
set(axisHnd4,'Visible','on')
% hide multipath controls
set(textHnd2,'Visible','off')
set(popupHnd1,'Visible','off')
% show generated sound buttons
set(textHnd3,'Visible','on')
set(OriginalHnd1,'Visible','on')
set(QAMHnd1,'Visible','on')
set(OFDMHnd1,'Visible','on')
% show long sounds stuff
set(textHnd4,'Visible','on')
set(OriginalLongHnd1,'Visible','on')
set(QAMLongHnd1,'Visible','on')
set(OFDMLongHnd1,'Visible','on')
% show the BER displays
set(textHnd5,'Visible','on')
set(textHnd6,'Visible','on')
set(textHnd7,'Visible','on') % QAM
set(textHnd8,'Visible','on') % OFDM
% Display the BERs
global BER_QAM_TEMP;
global BER_OFDM_TEMP;
set(textHnd7,'String',strcat(num2str(BER_QAM_TEMP,3),' %'))
set(textHnd8,'String',strcat(num2str(BER_OFDM_TEMP,3),' %'))
clear global BER_QAM_TEMP; % clean up the globals
clear global BER_OFDM_TEMP;
% Plot the Sounds
% Note: axes(handle) sets to plot on the handle axis
axes(axisHnd2)
plot(wavread(file_name)),title('Original sound')
axes(axisHnd3)
plot(wavread('QAM_out.wav')),title('QAM sound')
axes(axisHnd4)
plot(wavread('OFDM_out.wav')),title('OFDM sound')
set(nextHnd1,'String','Start Over') % repeat if desired
otherwise
disp('error')
COUNTER = 0;
end
end
% pol2bin.m
function y = pol2bin(x)
% pol2bin
%
% Converts polar numbers (-1,1) to binary numbers (0,1)
% Accepts a 1-D array of polar numbers
% Removes trailing zeros, since they are not valid data
y = ones(1,length(x));
for i = 1:length(x)
if x(i) == -1
y(i) = 0;
end
end
38
% QAM.m
% QAM.m compares OFDM (multicarrier) to multi-level QAM (single carrier)
% when they transmit the same # of bits in a given time period
if do_QAM == 1
tic % Start stopwatch to calculate how long QAM simulation takes
% read.m
% read
if file_input_type == 1
%binary file input
end
if file_input_type == 2
%text file input
file = fopen(file_name,'rt');
data_samples = fread(file,'char');
fclose(file);
data_in = zeros(1,8*length(data_samples));
for i = 1:length(data_samples)
data_in(1 + (i-1)*8:(i-1)*8 + 8) = eight2bin(data_samples(i));
end
end
40
if file_input_type == 3
%sound file input
data_samples=wavread(file_name);
%needs to be normalized from -1:1 to 0:255 for 8 bit conversion
data_samples_resized = round(128*data_samples +127);
data_in = zeros(1,8*length(data_samples_resized));
for i = 1:length(data_samples_resized)
data_in(1 + (i-1)*8:(i-1)*8 + 8) = eight2bin(data_samples_resized(i));
end
end
if file_input_type == 4
%image file input
[data_in,map]=imread(file_name); % read image and corresponding color map for display
end
end
% rx.m
% rx
disp('Receiving')
rx_chunk
rx_dechunk
write
% rx_chunk.m
% rx_chunk
% rx_dechunk.m
% rx_dechunk
% setup.m
% setup
disp(' '), disp('------------------------------------------------------------')
disp('Simulation Setup')
if input_type == 1
if test_input_type == 1
%specify BINARY input bit-by-bit
data_in = binary_data;
end
if test_input_type == 2
%random input defined by parameters
num_levels = 255; %number of possible levels of a symbol
%must be integer between 1-255
data_samples = round(rand(1,num_symbols)*(num_levels-1));
data_in = zeros(1,8*length(data_samples));
for i = 1:length(data_samples)
data_in(1 + (i-1)*8:(i-1)*8 + 8) = eight2bin(data_samples(i));
end
end
if test_input_type == 3
%data stream represents sine wave samples
t = linspace(0,1,num_symbols); %evenly space number of samples
%take 8-bit samples of sine wave
data_samples = round(127.5*sin(frequency*2*pi*t) +127.5);
data_in = zeros(1,8*length(data_samples));
42
for i = 1:length(data_samples)
data_in(1 + (i-1)*8:(i-1)*8 + 8) = eight2bin(data_samples(i));
end
end
end
% SetupGUI.m
% SetupGUI.m sets up the basicGUI variables
% SetupSoundGUI.m
% SetupSoundGUI.m sets up the SoundGUI variables
% SoundGUI.m
function SoundGUI()
% This is the machine-generated representation of a MATLAB object
% and its children. Note that handle values may change when these
% objects are re-created. This may cause problems with some callbacks.
% The command syntax may be supported in the future, but is currently
% incomplete and subject to change.
%
% To re-open this system, just type the name of the m-file at the MATLAB
% prompt. The M-file and its associtated MAT-file must be on your path.
load SoundGUI
c = line('Parent',b, ...
'Color',[0 0 1], ...
'Tag','Line1', ...
'XData',1, ...
'YData',0);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[0.997222 -1.37349 0], ...
'Tag','Text13', ...
'VerticalAlignment','cap');
set(get(c,'Parent'),'XLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[-0.141667 2.22045e-16 0], ...
'Rotation',90, ...
'Tag','Text14', ...
'VerticalAlignment','baseline');
set(get(c,'Parent'),'YLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','right', ...
'Position',[-0.286111 1.80723 0], ...
'Tag','Text15', ...
'Visible','off');
set(get(c,'Parent'),'ZLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[0.997222 1.13253 0], ...
'Tag','Text16', ...
'VerticalAlignment','bottom');
set(get(c,'Parent'),'Title',c);
b = axes('Parent',a, ...
'Units','points', ...
'Box','on', ...
'CameraUpVector',[0 1 0], ...
'CameraUpVectorMode','manual', ...
'Color',[1 1 1], ...
'ColorOrder',mat3, ...
'Position',[51 249 363 82], ...
'Tag','AxesQAM', ...
'XColor',[0 0 0], ...
'YColor',[0 0 0], ...
'ZColor',[0 0 0]);
c = line('Parent',b, ...
'Color',[0 0 1], ...
'Tag','Line2', ...
'XData',1, ...
'YData',0);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[0.997238 -1.38272 0], ...
'Tag','Text9', ...
'VerticalAlignment','cap');
set(get(c,'Parent'),'XLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[-0.140884 0 0], ...
'Rotation',90, ...
'Tag','Text10', ...
'VerticalAlignment','baseline');
set(get(c,'Parent'),'YLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','right', ...
'Position',[-0.28453 4.69136 0], ...
'Tag','Text11', ...
'Visible','off');
set(get(c,'Parent'),'ZLabel',c);
45
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[0.997238 1.1358 0], ...
'Tag','Text12', ...
'VerticalAlignment','bottom');
set(get(c,'Parent'),'Title',c);
b = axes('Parent',a, ...
'Units','points', ...
'Box','on', ...
'CameraUpVector',[0 1 0], ...
'CameraUpVectorMode','manual', ...
'Color',[1 1 1], ...
'ColorOrder',mat4, ...
'Position',[51 138 360 78], ...
'Tag','AxesOFDM', ...
'XColor',[0 0 0], ...
'YColor',[0 0 0], ...
'ZColor',[0 0 0]);
c = line('Parent',b, ...
'Color',[0 0 1], ...
'Tag','Line3', ...
'XData',1, ...
'YData',0);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[1 -1.4026 0], ...
'Tag','Text5', ...
'VerticalAlignment','cap');
set(get(c,'Parent'),'XLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[-0.091922 0 0], ...
'Rotation',90, ...
'Tag','Text6', ...
'VerticalAlignment','baseline');
set(get(c,'Parent'),'YLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','right', ...
'Position',[-0.286908 7.87013 0], ...
'Tag','Text7', ...
'Visible','off');
set(get(c,'Parent'),'ZLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[1 1.14286 0], ...
'Tag','Text8', ...
'VerticalAlignment','bottom');
set(get(c,'Parent'),'Title',c);
b = axes('Parent',a, ...
'Units','points', ...
'Box','on', ...
'CameraUpVector',[0 1 0], ...
'CameraUpVectorMode','manual', ...
'Color',[1 1 1], ...
'ColorOrder',mat5, ...
'Position',[30 120 396 335], ...
'Tag','Axes1', ...
'XColor',[0 0 0], ...
'YColor',[0 0 0], ...
'ZColor',[0 0 0]);
c = line('Parent',b, ...
'Color',[0 0 1], ...
'Tag','Line4', ...
'XData',1, ...
'YData',0);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[1 -1.09281 0], ...
46
'Tag','Text1', ...
'VerticalAlignment','cap');
set(get(c,'Parent'),'XLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[-0.129114 0.00299401 0], ...
'Rotation',90, ...
'Tag','Text2', ...
'VerticalAlignment','baseline');
set(get(c,'Parent'),'YLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','right', ...
'Position',[-0.15443 1.15269 0], ...
'Tag','Text3');
set(get(c,'Parent'),'ZLabel',c);
c = text('Parent',b, ...
'Color',[0 0 0], ...
'HandleVisibility','callback', ...
'HorizontalAlignment','center', ...
'Position',[1 1.03293 0], ...
'Tag','Text4', ...
'VerticalAlignment','bottom');
set(get(c,'Parent'),'Title',c);
b = uicontrol('Parent',a, ...
'Units','points', ...
'BackgroundColor',[0.733333 0.733333 0.733333], ...
'FontWeight','bold', ...
'Position',[489 162 129 18], ...
'String','Longer Sounds', ...
'Style','text', ...
'Tag','StaticTextLongSounds', ...
'Visible','off');
b = uicontrol('Parent',a, ...
'Units','points', ...
'BackgroundColor',[0.733333 0.733333 0.733333], ...
'Callback','OFDMguiFnSound PlayQAMLong', ...
'FontSize',14, ...
'Position',[491 92 107 28], ...
'String','QAM', ...
'Tag','PushbuttonQAMLong', ...
'Visible','off');
b = uicontrol('Parent',a, ...
'Units','points', ...
'BackgroundColor',[0.733333 0.733333 0.733333], ...
'Callback','OFDMguiFnSound PlayOFDMLong', ...
'FontSize',14, ...
'Position',[491 58 107 28], ...
'String','OFDM', ...
'Tag','PushbuttonOFDMLong', ...
'Visible','off');
b = uicontrol('Parent',a, ...
'Units','points', ...
'BackgroundColor',[0.733333 0.733333 0.733333], ...
'Callback','OFDMguiFnSound PlayOriginalLong', ...
'FontSize',14, ...
'Position',[491 126 107 28], ...
'String','Original', ...
'Tag','PushbuttonOriginalLong', ...
'Visible','off');
b = uicontrol('Parent',a, ...
'Units','points', ...
'BackgroundColor',[0.9 0.9 0.9], ...
'Position',[414 284 36 15], ...
'String','BER=', ...
'Style','text', ...
'Tag','StaticTextBER2', ...
'Visible','off');
b = uicontrol('Parent',a, ...
'Units','points', ...
'BackgroundColor',[0.9 0.9 0.9], ...
'Position',[414 176 36 15], ...
'String','BER=', ...
'Style','text', ...
'Tag','StaticTextBER1', ...
'Visible','off');
b = uicontrol('Parent',a, ...
47
'Units','points', ...
'BackgroundColor',[1 1 1], ...
'HorizontalAlignment','left', ...
'Position',[418 263 48 20], ...
'Style','text', ...
'Tag','StaticTextBERQAM', ...
'Visible','off');
b = uicontrol('Parent',a, ...
'Units','points', ...
'BackgroundColor',[1 1 1], ...
'HorizontalAlignment','left', ...
'Position',[419 157 49 17], ...
'Style','text', ...
'Tag','StaticTextBEROFDM', ...
'Visible','off');
% tx.m
% tx
disp('Transmitting')
read
tx_chunk
tx_dechunk
% tx_chunk.m
% tx_chunk
if r ~= 0
for i = 1:num_carriers*2-r
data_in_pol(data_length+i) = 0; %pad input with zeros to complete last data set
end %speed improve possible
end
%compute zeros_between
48
% tx_dechunk.m
% tx_dechunk
% write.m
% write
% ******************TEST OUTPUT*********************************
if input_type == 1
if test_input_type == 1
%already binary - do nothing
end
if (test_input_type == 2) | (test_input_type == 3)
%random input OR sine wave samples
output_samples = zeros(1,floor(length(output)/8)); %extra zeros are not original data
for i = 1:length(output_samples)
output_samples(i) = bin2eight(output(1 + (i-1)*8:(i-1)*8 + 8));
end
if do_QAM == 1
QAM_output_samples = zeros(1,floor(length(QAM_data_out)/8));
for i = 1:length(QAM_output_samples)
QAM_output_samples(i) = bin2eight(QAM_data_out(1 + (i-1)*8:(i-1)*8 + 8));
end
end
end
end
% ******************FILE OUTPUT*********************************
if input_type == 2
if file_input_type == 1
%binary file output - not implemented
end
if file_input_type == 2
%text file output
output_samples = zeros(1,floor(length(output)/8)); %extra zeros are not original data
for i = 1:length(output_samples)
output_samples(i) = bin2eight(output(1 + (i-1)*8:(i-1)*8 + 8));
end
file = fopen('OFDM_text_out.txt','wt+');
fwrite(file,output_samples,'char');
fclose(file);
if do_QAM == 1
QAM_output_samples = zeros(1,floor(length(QAM_data_out)/8)); %extra zeros are not original data
for i = 1:length(QAM_output_samples)
QAM_output_samples(i) = bin2eight(QAM_data_out(1 + (i-1)*8:(i-1)*8 + 8));
end
file = fopen('QAM_text_out.txt','wt+');
fwrite(file,QAM_output_samples,'char');
fclose(file);
49
end
end
if file_input_type == 3
output_samples_big = zeros(1,floor(length(output)/8)); %extra zeros are not original data
for i = 1:length(output_samples_big)
output_samples_big(i) = bin2eight(output(1 + (i-1)*8:(i-1)*8 + 8));
end
%convert dynamic range from 0:255 to -1:1
output_samples = (output_samples_big-127)/128;
%sound file output
wavwrite(output_samples, 11025, 8, 'OFDM_out.wav')
if do_QAM == 1
QAM_data_out_big = zeros(1,floor(length(QAM_data_out)/8));
for i = 1:length(QAM_data_out_big)
QAM_data_out_big(i) = bin2eight(QAM_data_out(1 + (i-1)*8:(i-1)*8 + 8));
end
%convert dynamic range from 0:255 to -1:1
QAM_output_samples = (QAM_data_out_big-127)/128;
%sound file output
wavwrite(QAM_output_samples, 11025, 8, 'QAM_out.wav')
end
end
if file_input_type == 4
%image file output - not implemented
end
end