数字通信技术实验报告

时间:2024.4.7

实验一:

clear all

[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);

for m=1:length(x)

    if Q(m)>128  & Q(m)<20##      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)>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;

    end

end

N=zeros(1,length(x1));

for m=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];

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));

   end

End

实验结果:

Max =0.3906

a =

Columns 1 through 7

     0          16          32          64         128         256         512

Column 8

   1024

b = 1     1     2     4     8    16    32    64

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,[0 255])

经反变换后的图像:

2.输入DCT进行JPEG图像压缩的代码如下:

RGB=imread('8.jpg');

I=rgb2gray(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);

         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;

   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;

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;

    end

end

data(j)=X(length(X));

image4length=length(image4);

y=1:1:image4length  ;

figure,plot(y,image4(y));

CR=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;

   end

function bitcoded = channelcoding(sym,G,k)

A=vec2mat(sym,k);%把向量转换成矩阵

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:row

for j=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=[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 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到15d

L=length(snr)

%模拟信源编码

%信道编码,(7,4)码

ser=zeros(1,L);

ser2=zeros(1,L);

for k=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-*')

hold on

plot(snr,ser2,'r-o')

grid on

legend('没有信道编码','信道编码');

xlabel('Eb/No(dB)');

ylabel('SER');

title('2PSK有无信道编码性能比较');

toc

%

clc;

clear;

close all;

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); %unit energy

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=[];

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];

    end

end

figure(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 on

subplot(412)

tb=0:1/30:10-1/30;

plot(tb, ask(1:10*30),'b','linewidth',1.5)

title('ASK Modulation');grid on

subplot(413)

plot(tb, fsk(1:10*30),'r','linewidth',1.5)

title('FSK Modulation');grid on

subplot(414)

plot(tb, psk(1:10*30),'k','linewidth',1.5)

title('PSK Modulation');grid on

xlabel('Time');ylabel('Amplitude')

%AWGN

for 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-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

    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([0 10 -0.5 1.5]);grid on

title('Received signal after AWGN Channel')

subplot(412)

tb=0:1/30:10-1/30;

plot(tb, askn(1:10*30),'b','linewidth',1.5)

title('Received ASK signal');grid on

subplot(413)

plot(tb, fskn(1:10*30),'r','linewidth',1.5)

title('Received FSK signal');grid on

subplot(414)

plot(tb, pskn(1:10*30),'k','linewidth',1.5)

title('Received PSK signal');grid on

figure(3)

semilogy(0:30,BER_A, 'b','linewidth',2)

title('BER Vs SNR')

grid on;

hold on

semilogy(0:30,BER_F,'r','linewidth',2)

semilogy(0:30,BER_P, 'k','linewidth',2)

xlabel('Eo/No(dB)')

ylabel('BER')

hold off

legend('ASK','FSK','PSK');

实验四

clc

clear

%Generationofbitpattern

s=round(rand(1,25));

signal=[];

%Generating20bits

carrier=[];

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];

end

subplot(4,1,1);

plot(signal);

axis([-100 3100 -1.5 1.5]);

title('\bf\it Original Bit Sequence');

%BPSKModulationofthesignal

bpsk_sig=signal.*carrier;

subplot(4,1,2);

%Modulatingthesignal

plot(bpsk_sig)

axis([-100 3100 -1.5 1.5]);

title('\bf\it BPSK Modulated Signal');

%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=[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);

%Randomfrequencyhoppstoformaspreadsignal

spread_signal=[];

for n=1:25

    c=randint(1,1,[1 6]);

    switch(c)

        case(1)

           spread_signal=[spread_signal c1];

        case(2)

            spread_signal=[spread_signal c2];

        case(3)

            spread_signal=[spread_signal c3];

        case(4)

           spread_signal=[spread_signal c4];

        case(5)

           spread_signal=[spread_signal c5];

        case(6)

           spread_signal=[spread_signal c6];

    end

end

subplot(4,1,3)

plot([1:3000],spread_signal);

axis([-100 3100 -1.5 1.5]);

title('\bf\it Spread Signal with 6 frequencies');

%SpreadingBPSKSignalintowiderbandwithtotalof12frequencies

freq_hopped_sig=bpsk_sig.*spread_signal;

subplot(4,1,4)

plot([1:3000],freq_hopped_sig);

axis([-100 3100 -1.5 1.5]);

title('\bf\it Frequency Hopped Spread Spectrum Signal');

%ExpressingtheFFTs

figure,subplot(2,1,1)

plot([1:3000],freq_hopped_sig);

axis([-100 3100 -1.5 1.5]);

title('\bf\it Frequency Hopped Spread Spectrum signal and its FFT');

subplot(2,1,2);

plot([1:3000],abs(fft(freq_hopped_sig)));

更多相关推荐:
数字电路实验报告

北京邮电大学数字电路与逻辑设计实验实验报告实验名称足球比赛游戏机班级学号姓名20xx年11月8号1一实验目的1进一步掌握VHDL和QuartusII软件的使用2理解状态机的工作原理和设计方法3掌握利用EDA工具...

《数字电子技术基础》实验报告

实验报告实验名称课程名称院系部学生姓名同组人指导教师实验日期电子技术实验数字专业班级学号实验台号成绩华北电力大学实验报告要求一实验目的及要求二仪器用具三实验原理四实验步骤包括原理图实验结果与数据处理五讨论与结论...

数字电子技术实验报告格式

贵州大学计算机科学与技术学院数字系统与逻辑设计实验报告项目名称组合逻辑电路分析姓名专业班级学号同组成员学号实验日期

数字电路译码器实验报告

一实验目的与要求1了解和正确使用MSI组合逻辑部件2掌握一般组合逻辑电路的特点及分析设计方法3学会对所设计的电路进行静态功能测试的方法4观察组合逻辑电路的竞争冒险现象预习要求1复习组合逻辑电路的分析与设计方法2...

数字电路课程设计实验报告

交通灯控制电路的设计设计单位物电系XXX班设计人XXX指导老师XXX设计时间20xx年10月10日一设计内容与要求1设计内容1利用各种器件设计一个交通灯控制电路2利用电路板对所设计的电路进行检验3总结检验电路设...

数字电路实验报告 实验1

实验报告集成逻辑门的测试04093043一实验目的1了解与非门各参数的意义2熟悉万用表的使用方法3熟悉数字逻辑实验板的使用方法4了解集成逻辑门电路的使用注意事项二实验设备及器件1数字逻辑电路实验板1块1片1块2...

数字电路跑马灯实验报告

实验名称发光二极管走马灯电路设计与实现姓名班级班内序号学院日期一发光二极管走马灯电路设计与实现1实验目的1进一步了解时序电路描述方法2熟悉状态机的设计方法2实验所用仪器及元器件1计算机2直流稳压电源3数字系统与...

数字电路实验报告-实验六

实验六中规模组合逻辑电路的设计一实验目的熟悉中规模集成电路的使用掌握用中规模集成电路设计组合逻辑电路的方法二实验预习复习数据选择器和译码器的逻辑功能三实验器材直流稳压电源数字逻辑实验箱74LS0074LS207...

数字电路实验报告2

暨南大学本科实验报告专用纸课程名称数字逻辑电路实验成绩评定实验项目名称组合逻辑电路装测调试方法指导教师实验项目编号0806003802实验项目类型验证型实验地点学生姓名学号学院电气信息学院系专业实验时间20xx...

《数字电路课程设计》实验报告模板

实验报告年月日成绩

数字电路实验报告

实验一半加器与全加器的电路图实现一半加器1半加器的电路图见图1图1半加器的电路图2半加器仿真波形图见图2图2半加器仿真波形图3仿真图简析如图2为半加器仿真波形图对应ab输入波形得到的c为进位s为和如a1b0c0...

数字电子技术基础课程设计报告

11扬州大学能源与动力工程学院本科生课程设计题目智力竞赛抢答器课程数字电子技术基础专业电气工程及其自动化班级学号XXXXXX姓名XXXXXX指导教师XXX完成日期20xxXXXX12总目录第一部分任务书第二部分...

数字电子技术实验报告(26篇)