Comparison of C++ and MATLAB Using Object Oriented Application Example
This example calculates the bit error rate (BER) of a Bluetooth or 802.11b communication link interfered with by another 802.11b or Bluetooth transmitter. It uses the new MATLAB object oriented programming features released in R2008a.
The main function btint and accompanying classes have been translated from the C++ NIST Bluetooth and IEEE 802.11b Coexistence Simulator. The original C++ code has been retained as comments in the MATLAB code to help with its understanding for those familiar with C++.
In same cases, the MATLAB code has been written in a style to more closely match the C++ code. Additional MATLAB language features could be used in those circumstance to improve efficiency or understandability.
Contents
Setup
Put the folder containing these files on your path. This avoids problems which can occur if you change folders, taking class definitions out of scope, while you have objects based on them defined in the workspace.
Running the Simulation
The btint function calculates the BER of a system specified by the input arguments. It takes all string parameters to copy the behavior of the equivalent C main function. We will call the function with a couple of different configurations using this subset of arguments:
- -d Desired signal type (BT or 802.11)
- -i Interfering signal (BT or 802.11)
- -EbNo Carrier-to-noise ratio (in dB)
- -c Packet count
- -bd Bitrate of desired signal (in Mb/s)
1) Bluetooth interfered by 802.11b, noise level 0, 5 packets
btint -d BT -i 802.11 -EbNo 0 -c 5;
Desired signal transmitter/receiver: BT. Interference transmitter: 802.11. Number of packets = 5. Packet length = 160. Frequency offset (MHz)= 4 Carrier-to-interference ratio (dB) = 100. Carrier-to-noise ratio (dB) = 0. Number of bit errors = 233. BER = 3.03e-001.
2) 802.11b, 11Mbps rate, interfered by Bluetooth, noise level 0, 40 packets
btint -d 802.11 -bd 11 -i BT -EbNo 0 -c 40;
Desired signal transmitter/receiver: 802.11. Interference transmitter: BT. Number of packets = 40. Packet length = 176. Frequency offset (MHz)= 4 Carrier-to-interference ratio (dB) = 100. Carrier-to-noise ratio (dB) = 0. Number of bit errors = 996. BER = 1.50e-001.
For a list of all available parameters see the NIST web site.
Application Overview
The application is made up of the following functions and classes.
Functions
- Main function btint, support functions setRSRCpulseShapingFilter and getArg.
Classes
- BluetoothTransmitter and IEEE802_11b_Transmitter sub classes which inherit from the Transmitter super class
- BluetoothReceiver and IEEE802_11b_Receiver sub classes which inherit from the Receiver super class
- AWGNChannel sub class which inherits from the Channel super class
- Other Classes: AWGN, FIRFilter, random, RandomBit, programArgs, constants
Things to Investigate
- See the published M file ComparingCAndMATLAB for notes on the overall differences between the implementations.
- For best viewing of the MATLAB code, ensure 'code folding' for block comments is enabled and set to initially folded. See code folding section of the editor preferences.
- View the main function btint and see how the MATLAB code compares with the C++ code in comments.
- To see specifically how the class definition syntax of MATLAB compares to C++, look at the classes used in the application such as AWGN.m, or IEEE802_11b_Receiver.m.
- To create a new set of MATLAB files with all the C++ comments removed, run the script stripCComments.
- Run test_ber to plot the BER for a range of SNR.