这里是以前做过的一个matlab仿真作业,年代有点久远,把代码传上来记录一下。当时一起的组员为Rebecca Aktins,对我们帮助很大的tutor为Ali,当时才开始写matlab不久,很多地方都有不足之处,注释都是英文的,但是也是因为才开始写,注释写得非常详细,耐心的话应该很好看懂。
当时没有写子函数分块的概念,都写在一起了。
这个代码完成的功能是:设定EbNo的值,输入一个格式为bmp的图片,可以输出一个经过这个信道后的bmp文件,以及其EbNo vs BER的图像。
代码如下:
%function transmitimage(lena1)
clear
lena1 = imread('lena1.bmp')
%Lets make 3 different 128x128 matrices to represent each colour
red= lena1(:,:,1)
green = lena1(:,:,2)
blue = lena1(:,:,3)
%Now to convert them into single column vectors:
red= red(:)
green = green(:)
blue = blue(:)
%Now convert these into binary; note that we are using de2bi, this
%conversion means the right bit is the most significant.
redbin = de2bi(red)
greenbin = de2bi(green)
bluebin = de2bi(blue)
%redbin, greenbin and bluebin are 16384x8 matrices. We now need to convert
%this into single column vectors
redbin = redbin(:)
greenbin = greenbin(:)
bluebin = bluebin(:)
%Now to append these three colmn vectors to one another ready to transmit
lena1bin =[redbin greenbin bluebin]
lena1bin = lena1bin(:)
%Lets change this from uint8 to double precision for when we add noise
lena1bin = double(lena1bin)
%Lets transmit these bits (add noise) and then convert back into a 128x128x3
%matrice
%we firstly need to create our own noise
%Assume A = 1 and T = 1
EbN0 = 6; % in dB
%Convert EbN0 into decibels
EbN0=10^(EbN0/10)
A=1
T=1
Eb = 1/2
N0 = Eb/EbN0;
sd = sqrt(N0*T/4)
%Now to make a column vector of noise the same size as out transmitted
%column vector
X = normrnd(0,s