数字通信技术实验报告.docx
- 文档编号:14178719
- 上传时间:2023-06-21
- 格式:DOCX
- 页数:21
- 大小:753.86KB
数字通信技术实验报告.docx
《数字通信技术实验报告.docx》由会员分享,可在线阅读,更多相关《数字通信技术实验报告.docx(21页珍藏版)》请在冰点文库上搜索。
数字通信技术实验报告
实验一:
clearall
[x,fs,bits]=wavread('myheart.wav');
z=sign(x);Max=max(abs(x));x1=abs(x/Max);Q=2048*x1;
Y=zeros(length(x1),8);
form=1:
length(x)
ifQ(m)>128&Q(m)<2048Y(m,2)=1;
end
if(Q(m)>32&Q(m)<128)||(Q(m)>512&Q(m)<2048)Y(m,3)=1;
end
if(Q(m)>16&Q(m)<31)||(Q(m)>64&Q(m)<128)||(Q(m)>256&Q(m)<512)||(Q(m)>1024&Q(m)<2048)Y(m,4)=1;
end
ifz(m)>0Y(m,1)=1;
elseifz(m)<0Y(m,1)=0;
end
end
N=zeros(1,length(x1));
form=1:
length(x1)
N(m)=Y(m,2)*4+Y(m,3)*2+Y(m,4)+1;
end
a=[0,16,32,64,128,256,512,1024];
b=[1,1,2,4,8,16,32,64];
form=1:
length(x1)
q=ceil(Q(m)-a(N(m))/b(N(m)));
ifq==0Y(m,(5:
8))=[0,0,0,0];
elsek=num2str(dec2bin(q-1,4));
Y(m,5)=str2num(k
(1));
Y(m,6)=str2num(k
(2));
Y(m,7)=str2num(k(3));
Y(m,8)=str2num(k(4));
end
End
实验结果:
Max=0.3906
a=
Columns1through7
0163264128256512
Column8
1024
b=11248163264
bits=16
fs=22050
k=111011011
m=168873
q=476
实验二:
RGB=imread('8.jpg');
I=rgb2gray(RGB);
J=dct2(I);
imshow(log(abs(J)),[]),colormap(jet(64)),colorbar
J(abs(J)<10)=0;
K=idct2(J);
figure,imshow(I)
figure,imshow(K,[0255])
原图像经过离散余弦变换后
原图像的灰度图像
经反变换后的图像:
2.输入DCT进行JPEG图像压缩的代码如下:
RGB=imread('8.jpg');
I=rgb2gray(RGB);
I=im2double(I);
T=dctmtx(8);
B=blkproc(I,[88],'P1*x*P2',T,T');
Mask=[11110000
11100000
11000000
10000000
00000000
00000000
00000000
00000000];
B2=blkproc(B,[88],'P1*x',Mask);
I2=blkproc(B2,[8,8],'P1*x*P2',T',T);
Subplot(1,2,1);
Imshow(I);title('原图像');
Subplot(1,2,2);
Imshow(I2);title('压缩图像');
3.游程编码:
image1=imread('lena.jpg');
imshow(image1);
image2=image1(:
);
image2length=length(image2);
fori=1:
1:
image2length
ifimage2(i)>=127
image2(i)=255;
else
image2(i)=0;
end
end
image3=reshape(image2,512,512);
figure,imshow(image3);
X=image3(:
);
x=1:
1:
length(X);
figure,plot(x,X(x));
j=1;
image4
(1)=1;
forz=1:
1:
(length(X)-1)
ifX(z)==X(z+1)
image4(j)=image4(j)+1;
else
data(j)=X(z);
j=j+1;
image4(j)=1;
end
end
data(j)=X(length(X));
image4length=length(image4);
y=1:
1:
image4length;
figure,plot(y,image4(y));
CR=image2length/image4length;
实验三
functioncode=addfade(modcode,Tf,isperiod,isfade)
%功能:
向传输序列modcode叠加衰落性信道的衰落参数k(t)
if(isfade==1)
if(isperiod==1)
a=31;
b=30+10*Tf;
modcode(1,a:
b)=0.1*modcode(1,a:
b);
end
code=modcode;
else
code=modcode;
end
functionbitcoded=channelcoding(sym,G,k)
A=vec2mat(sym,k);%把向量转换成矩阵
U=A*G;
U=mod(U,2);
bitcoded=reshape(U',1,[]);
functionbitdecoded=channeldecoding(recode,Etab,Smatrix,H,n,k)
%前向纠错函数,实现纠错功能
row=length(recode)/n;
E=zeros(row,n);
RM=zeros(row,n);%纠错之后的矩阵
R=vec2mat(recode,n);
S=R*H';%伴随矩阵
S=mod(S,2);
fori=1:
row
forj=1:
2^(n-k)
%查表纠错
if(S(i,:
)==Smatrix(j,:
))
E(i,:
)=Etab(j,:
);
RM(i,:
)=R(i,:
)+E(i,:
);
RM(i,:
)=mod(RM(i,:
),2);
break;
end
end
end
bitdecoded=reshape(RM',1,[]);%转化为比特流
tic
clc
%功能:
有无信道编码性能比较
M=2;
%进制
b=log2(M);
%每符号比特数
n=128*10000;%符号数
G=[1111000;1010100;0110010;1100001];%生成矩阵
H=[1001101;0101011;0011110];
%监督矩阵
Etab=[0000000;0000001;
0000010;0000100;
0001000;0010000;
0100000;1000000];
%错误图样
Smatrix=Etab*H';
%对应的伴随式
sym=randint(n,1,M);
sym=de2bi(sym,'left-msb');
bitcoded=channelcoding(sym,G,4);
modbit=pskmod(bitcoded,M);
%在传输序列modbit加入AWGN噪声
snr=0:
0.2:
15;%噪声为0到15d
L=length(snr)
%模拟信源编码
%信道编码,(7,4)码
ser=zeros(1,L);
ser2=zeros(1,L);
fork=1:
L
y=awgn(modbit,10*log10(b)+snr(k),'measured');
zsym=pskdemod(y,M);
%复数解调
zbit=de2bi(zsym,'left-msb');
recode=reshape(zbit',1,[]);
Rstream=recode;
err=(Rstream~=bitcoded);
errnum=sum(err);
ser(k)=log10(errnum/length(bitcoded));
%纠错
bitdecoded=channeldecoding(Rstream,Etab,Smatrix,H,7,4);
err=(bitdecoded~=bitcoded);
errbits=sum(err);
ser2(k)=log10(errbits/(length(bitcoded)));
end
plot(snr,ser,'b-*')
holdon
plot(snr,ser2,'r-o')
gridon
legend('没有信道编码','信道编码');
xlabel('Eb/No(dB)');
ylabel('SER');
title('2PSK有无信道编码性能比较');
toc
%
clc;
clear;
closeall;
n=10000;
b=randint(1,n);
f1=1;f2=2;
t=0:
1/30:
1-1/30;
%ASK
sa1=sin(2*pi*f1*t);
E1=sum(sa1.^2);
sa1=sa1/sqrt(E1);%unitenergy
sa0=0*sa1;
%FSK
sf0=sin(2*pi*f1*t);
E=sum(sf0.^2);
sf0=sf0/sqrt(E);
sf1=sin(2*pi*f2*t);
E=sum(sf1.^2);
sf1=sf1/sqrt(E);
%PSK
sp0=-sin(2*pi*f1*t)/sqrt(E1);
sp1=sin(2*pi*f1*t)/sqrt(E1);
%调制
ask=[];psk=[];fsk=[];
fori=1:
n
ifb(i)==1
ask=[asksa1];
psk=[psksp1];
fsk=[fsksf1];
else
ask=[asksa0];
psk=[psksp0];
fsk=[fsksf0];
end
end
figure
(1)
subplot(411)
stairs(0:
10,[b(1:
10)b(10)],'linewidth',1.5)
axis([010-0.51.5])
title('MessageBits');gridon
subplot(412)
tb=0:
1/30:
10-1/30;
plot(tb,ask(1:
10*30),'b','linewidth',1.5)
title('ASKModulation');gridon
subplot(413)
plot(tb,fsk(1:
10*30),'r','linewidth',1.5)
title('FSKModulation');gridon
subplot(414)
plot(tb,psk(1:
10*30),'k','linewidth',1.5)
title('PSKModulation');gridon
xlabel('Time');ylabel('Amplitude')
%AWGN
forsnr=0:
30
askn=awgn(ask,snr);
pskn=awgn(psk,snr);
fskn=awgn(fsk,snr);
%DETECTION
A=[];F=[];P=[];
fori=1:
n
%ASKDetection
ifsum(sa1.*askn(1+30*(i-1):
30*i))>0.5
A=[A1];
else
A=[A0];
end
%FSKDetection
ifsum(sf1.*fskn(1+30*(i-1):
30*i))>0.5
F=[F1];
else
F=[F0];
end
%PSKDetection
ifsum(sp1.*pskn(1+30*(i-1):
30*i))>0
P=[P1];
else
P=[P0];
end
end
%BER
errA=0;errF=0;errP=0;
fori=1:
n
ifA(i)==b(i)
errA=errA;
else
errA=errA+1;
end
ifF(i)==b(i)
errF=errF;
else
errF=errF+1;
end
ifP(i)==b(i)
errP=errP;
else
errP=errP+1;
end
end
BER_A(snr+1)=errA/n;
BER_F(snr+1)=errF/n;
BER_P(snr+1)=errP/n;
end
figure
(2)
subplot(411)
stairs(0:
10,[b(1:
10)b(10)],'linewidth',1.5)
axis([010-0.51.5]);gridon
title('ReceivedsignalafterAWGNChannel')
subplot(412)
tb=0:
1/30:
10-1/30;
plot(tb,askn(1:
10*30),'b','linewidth',1.5)
title('ReceivedASKsignal');gridon
subplot(413)
plot(tb,fskn(1:
10*30),'r','linewidth',1.5)
title('ReceivedFSKsignal');gridon
subplot(414)
plot(tb,pskn(1:
10*30),'k','linewidth',1.5)
title('ReceivedPSKsignal');gridon
figure(3)
semilogy(0:
30,BER_A,'b','linewidth',2)
title('BERVsSNR')
gridon;
holdon
semilogy(0:
30,BER_F,'r','linewidth',2)
semilogy(0:
30,BER_P,'k','linewidth',2)
xlabel('Eo/No(dB)')
ylabel('BER')
holdoff
legend('ASK','FSK','PSK');
实验四
clc
clear
%Generationofbitpattern
s=round(rand(1,25));
signal=[];
%Generating20bits
carrier=[];
t=[0:
2*pi/119:
2*pi];
fork=1:
25
%Creating60samplesforonecosine
ifs(1,k)==0
sig=-ones(1,120);
%120minusonesforbit0
%120onesforbit1
else
sig=ones(1,120);
end
c=cos(t);
carrier=[carrierc];
signal=[signalsig];
end
subplot(4,1,1);
plot(signal);
axis([-1003100-1.51.5]);
title('\bf\itOriginalBitSequence');
%BPSKModulationofthesignal
bpsk_sig=signal.*carrier;
subplot(4,1,2);
%Modulatingthesignal
plot(bpsk_sig)
axis([-1003100-1.51.5]);
title('\bf\itBPSKModulatedSignal');
%Preparationof6newcarrierfrequencies
t1=[0:
2*pi/9:
2*pi];
t2=[0:
2*pi/19:
2*pi];
t3=[0:
2*pi/29:
2*pi];
t4=[0:
2*pi/39:
2*pi];
t5=[0:
2*pi/59:
2*pi];
t6=[0:
2*pi/119:
2*pi];
c1=cos(t1);
c1=[c1c1c1c1c1c1c1c1c1c1c1c1];
c2=cos(t2);
c2=[c2c2c2c2c2c2];
c3=cos(t3);
c3=[c3c3c3c3];
c4=cos(t4);
c4=[c4c4c4];
c5=cos(t5);
c5=[c5c5];
c6=cos(t6);
%Randomfrequencyhoppstoformaspreadsignal
spread_signal=[];
forn=1:
25
c=randint(1,1,[16]);
switch(c)
case
(1)
spread_signal=[spread_signalc1];
case
(2)
spread_signal=[spread_signalc2];
case(3)
spread_signal=[spread_signalc3];
case(4)
spread_signal=[spread_signalc4];
case(5)
spread_signal=[spread_signalc5];
case(6)
spread_signal=[spread_signalc6];
end
end
subplot(4,1,3)
plot([1:
3000],spread_signal);
axis([-1003100-1.51.5]);
title('\bf\itSpreadSignalwith6frequencies');
%SpreadingBPSKSignalintowiderbandwithtotalof12frequencies
freq_hopped_sig=bpsk_sig.*spread_signal;
subplot(4,1,4)
plot([1:
3000],freq_hopped_sig);
axis([-1003100-1.51.5]);
title('\bf\itFrequencyHoppedSpreadSpectrumSignal');
%ExpressingtheFFTs
figure,subplot(2,1,1)
plot([1:
3000],freq_hopped_sig);
axis([-1003100-1.51.5]);
title('\bf\itFrequencyHoppedSpreadSpectrumsignalanditsFFT');
subplot(2,1,2);
plot([1:
3000],abs(fft(freq_hopped_sig)));
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数字通信 技术 实验 报告
![提示](https://static.bingdoc.com/images/bang_tan.gif)