




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上实验一:clear allx,fs,bits=wavread('myheart.wav');z=sign(x); Max=max(abs(x); x1=abs(x/Max); Q=2048*x1;Y=zeros(length(x1),8);for m=1:length(x) if Q(m)>128 & Q(m)<2048 Y(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)&g
2、t;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 if z(m)>0 Y(m,1)=1; elseif z(m)<0 Y(m,1)=0; endendN=zeros(1,length(x1);for m=1:length(x1) N(m)=Y(m,2)*4+Y(m,3)*2+Y(m,4)+1;enda=0,16,32,64,128,256,512,1024
3、;b=1,1,2,4,8,16,32,64;for m=1:length(x1) q=ceil(Q(m)-a(N(m)/b(N(m); if q=0 Y(m,(5:8)=0,0,0,0; else k=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); endEnd实验结果:Max =0.3906a =Columns 1 through 7 0 16 32 64 128 256 512Column 8 1024b = 1 1 2 4
4、 8 16 32 64bits =16fs =22050k =m =q =476实验二:RGB=imread('8.jpg');I=rgb2gray(RGB);J=dct2(I);imshow(log(abs(J),),colormap(jet(64),colorbarJ(abs(J)<10)=0;K=idct2(J);figure,imshow(I)figure,imshow(K,0 255)原图像经过离散余弦变换后原图像的灰度图像经反变换后的图像:2.输入DCT进行JPEG图像压缩的代码如下:RGB=imread('8.jpg');I=rgb2gray
5、(RGB);I=im2double(I); T=dctmtx(8); B=blkproc(I,8 8,'P1*x*P2',T,T'); Mask= 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; B2=blkproc(B,8 8,' P1*x',Mask); I2= blkproc(B2,8,8,'P1*x*P2',T',T
6、); 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);for i=1:1:image2length if image2(i)>=127 image2(i)=255; else image2(i)=0; endendimage3=reshape(i
7、mage2,512,512);figure,imshow(image3);X=image3(:);x=1:1:length(X);figure,plot(x,X(x);j=1;image4(1)=1;for z=1:1:(length(X)-1) if X(z)=X(z+1) image4(j)=image4(j)+1; else data(j)=X(z); j=j+1; image4(j)=1; endenddata(j)=X(length(X);image4length=length(image4);y=1:1:image4length ;figure,plot(y,image4(y);C
8、R=image2length/image4length;实验三function code = 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; endfunction bitcoded = channelcoding(sym,G,k)A=vec2mat(sym,k);%把向量转换成
9、矩阵U=A*G;U=mod(U,2);bitcoded=reshape(U',1,);function bitdecoded = 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);for i=1:rowfor j=1:2(n-k)%查表纠错if(S(i,:)=Smatrix(j,:)E(i,:)=Etab(j,:);
10、RM(i,:)=R(i,:)+E(i,:);RM(i,:)=mod(RM(i,:),2);break;endendendbitdecoded=reshape(RM',1,);%转化为比特流ticclc%功能:有无信道编码性能比较M=2;%进制b=log2(M);%每符号比特数n=128*10000;%符号数G=1 1 1 1 0 0 0;1 0 1 0 1 0 0;0 1 1 0 0 1 0;1 1 0 0 0 0 1;%生成矩阵H=1 0 0 1 1 0 1;0 1 0 1 0 1 1;0 0 1 1 1 1 0;%监督矩阵Etab=0 0 0 0 0 0 0;0 0 0 0 0 0
11、 1;0 0 0 0 0 1 0;0 0 0 0 1 0 0;0 0 0 1 0 0 0;0 0 1 0 0 0 0;0 1 0 0 0 0 0;1 0 0 0 0 0 0;%错误图样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到15dL=length(snr)%模拟信源编码%信道编码,(7,
12、4)码ser=zeros(1,L);ser2=zeros(1,L);for k=1:Ly=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=channeldec
13、oding(Rstream,Etab,Smatrix,H,7,4);err=(bitdecoded=bitcoded);errbits=sum(err);ser2(k)=log10(errbits/(length(bitcoded);endplot(snr,ser,'b-*')hold onplot(snr,ser2,'r-o')grid onlegend('没有信道编码','信道编码');xlabel('Eb/No(dB)');ylabel('SER');title('2PSK有无信道编码
14、性能比较');toc%clc;clear;close all;n=10000;b=randint(1,n);f1=1;f2=2;t=0:1/30:1-1/30;%ASKsa1=sin(2*pi*f1*t);E1=sum(sa1.2);sa1=sa1/sqrt(E1); %unit energy sa0=0*sa1;%FSKsf0=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);%PSKsp0=-sin(2*pi*f1*t)/sqrt(E1);sp1=s
15、in(2*pi*f1*t)/sqrt(E1);%调制ask=;psk=;fsk=;for i=1:n if b(i)=1 ask=ask sa1; psk=psk sp1; fsk=fsk sf1; else ask=ask sa0; psk=psk sp0; fsk=fsk sf0; endendfigure(1)subplot(411)stairs(0:10,b(1:10) b(10),'linewidth',1.5)axis(0 10 -0.5 1.5)title('Message Bits');grid onsubplot(412)tb=0:1/30:1
16、0-1/30;plot(tb, ask(1:10*30),'b','linewidth',1.5)title('ASK Modulation');grid onsubplot(413)plot(tb, fsk(1:10*30),'r','linewidth',1.5)title('FSK Modulation');grid onsubplot(414)plot(tb, psk(1:10*30),'k','linewidth',1.5)title('PSK Mo
17、dulation');grid onxlabel('Time');ylabel('Amplitude')%AWGNfor snr=0:30 askn=awgn(ask,snr); pskn=awgn(psk,snr); fskn=awgn(fsk,snr); %DETECTION A=;F=;P=; for i=1:n %ASK Detection if sum(sa1.*askn(1+30*(i-1):30*i)>0.5 A=A 1; else A=A 0; end %FSK Detection if sum(sf1.*fskn(1+30*(i-
18、1):30*i)>0.5 F=F 1; else F=F 0; end %PSK Detection if sum(sp1.*pskn(1+30*(i-1):30*i)>0 P=P 1; else P=P 0; end end %BER errA=0;errF=0; errP=0; for i=1:n if A(i)=b(i) errA=errA; else errA=errA+1; end if F(i)=b(i) errF=errF; else errF=errF+1; end if P(i)=b(i) errP=errP; else errP=errP+1; end end
19、BER_A(snr+1)=errA/n; BER_F(snr+1)=errF/n; BER_P(snr+1)=errP/n;endfigure(2)subplot(411)stairs(0:10,b(1:10) b(10),'linewidth',1.5)axis(0 10 -0.5 1.5);grid ontitle('Received signal after AWGN Channel')subplot(412)tb=0:1/30:10-1/30;plot(tb, askn(1:10*30),'b','linewidth',1
20、.5)title('Received ASK signal');grid onsubplot(413)plot(tb, fskn(1:10*30),'r','linewidth',1.5)title('Received FSK signal');grid onsubplot(414)plot(tb, pskn(1:10*30),'k','linewidth',1.5)title('Received PSK signal');grid onfigure(3)semilogy(0:30,
21、BER_A, 'b','linewidth',2)title('BER Vs SNR')grid on;hold onsemilogy(0:30,BER_F,'r','linewidth',2)semilogy(0:30,BER_P, 'k','linewidth',2)xlabel('Eo/No(dB)')ylabel('BER')hold offlegend('ASK','FSK','PSK');实验
22、四clcclear%Generationofbitpatterns=round(rand(1,25);signal=;%Generating20bitscarrier=;t=0:2*pi/119:2*pi;for k=1:25 %Creating60samplesforonecosine if s(1,k)=0 sig=-ones(1,120); %120minusonesforbit0 %120onesforbit1 else sig=ones(1,120); end c=cos(t); carrier=carrier c; signal=signal sig;endsubplot(4,1,
23、1);plot(signal);axis(-100 3100 -1.5 1.5);title('bfit Original Bit Sequence');%BPSKModulationofthesignalbpsk_sig=signal.*carrier;subplot(4,1,2);%Modulatingthesignalplot(bpsk_sig)axis(-100 3100 -1.5 1.5);title('bfit BPSK Modulated Signal');%Preparationof6newcarrierfrequenciest1=0:2*pi/
24、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=c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1;c2=cos(t2);c2=c2 c2 c2 c2 c2 c2;c3=cos(t3);c3=c3 c3 c3 c3;c4=cos(t4);c4=c4 c4 c4;c5=cos(t5);c5=c5 c5;c6=cos(t6);%Randomfrequencyhoppstoformaspreadsignalspread_signal=;for n=1:25 c=randint(1,1,1 6); switch(c) case(1) spread
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高危工作安全协议书
- 超市利润分红协议书
- 道路迁坟火化协议书
- 金供应商合同协议书
- 销售生产订单协议书
- 餐饮供应合同协议书
- 农村自流地换地协议书
- 餐具承包合同协议书
- 买车位只有认购协议书
- 金融物资转让协议书
- 黄泉下的美术:宏观中国古代墓葬
- 无违法犯罪记录证明申请表(个人)
- 内部调拨单表格
- 2023年07月浙江建设技师学院200人笔试历年常考点试卷附带答案详解
- 中国真正丹道理法及工程次第阐真
- 2022年四川省成都市中考英语试卷及答案
- 新年春节廉洁过年过廉洁年端午节清廉文化中秋节廉洁过节优秀课件两篇
- GB/T 10920-2008螺纹量规和光滑极限量规型式与尺寸
- 认知宇宙飞船之星际探索
- 皮肤病理知识学习整理课件整理
- 人工智能课件213产生式表示法
评论
0/150
提交评论