ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:18.09KB ,
资源ID:14167819      下载积分:5 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-14167819.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(DPCM编码MATLAB实现.docx)为本站会员(b****1)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

DPCM编码MATLAB实现.docx

1、DPCM编码MATLAB实现DPCM编码MATLAB实现 %本文是数字图像处理的一个源程序 %实现的功能是DPCM编码 %DPCM编码,简称差值编码,是对模拟信号幅度抽样的差值进行量化编码的调制方式 %本程序实现一阶/二阶/三阶/四阶DPCM数字信号预测 %一阶/二阶/三阶/四阶预测的区别不仅在于信号的清晰度,而更重要在于 %阶数越高,图像越光滑. clc clear close all; %从D盘导入图片,以学校风光图片为例实现DPCM I03=imread(d:shuxuejianmo.bmp); %把RGB图像转化为灰度图像 I02=rgb2gray(I03); I=double(I02

2、); fid1=fopen(mydata1.dat,w); fid2=fopen(mydata2.dat,w); fid3=fopen(mydata3.dat,w); fid4=fopen(mydata4.dat,w); m,n=size(I); %对预测信号将边缘锁定,防止程序运行时抓不到数据 J1=ones(m,n); J1(1:m,1)=I(1:m,1); J1(1,1:n)=I(1,1:n); J1(1:m,n)=I(1:m,n); J1(m,1:n)=I(m,1:n); J2=ones(m,n); J2(1:m,1)=I(1:m,1); J2(1,1:n)=I(1,1:n); J2(

3、1:m,n)=I(1:m,n); J2(m,1:n)=I(m,1:n); J3=ones(m,n); J3(1:m,1)=I(1:m,1); J3(1,1:n)=I(1,1:n); J3(1:m,n)=I(1:m,n); J3(m,1:n)=I(m,1:n); J4=ones(m,n); J4(1:m,1)=I(1:m,1); J4(1,1:n)=I(1,1:n); J4(1:m,n)=I(1:m,n); J4(m,1:n)=I(m,1:n); %一阶DPCM编码 for k=2:m-1 for l=2:n-1 J1(k,l)=I(k,l)-I(k,l-1); end end J1=round

4、(J1); cont1=fwrite(fid1,J1,int8); cc1=fclose(fid1); %二阶DPCM编码 for k=2:m-1 for l=2:n-1 J2(k,l)=I(k,l)-(I(k,l-1)/2+I(k-1,l)/2); end end J2=round(J2); cont2=fwrite(fid2,J2,int8); cc2=fclose(fid2); %三阶DPCM编码 for k=2:m-1 for l=2:n-1 J3(k,l)=I(k,l)-(I(k,l-1)*(4/7)+I(k-1,l)*(2/7)+I(k-1,l-1)*(1/7); end end

5、J3=round(J3); cont3=fwrite(fid3,J3,int8); cc3=fclose(fid3); %四阶DPCM编码 for k=2:m-1 for l=2:n-1 J4(k,l)=I(k,l)-(I(k,l-1)/2+I(k-1,l)/4+I(k-1,l-1)/8+I(k-1,l+1)/8); end end J4=round(J4); cont4=fwrite(fid4,J4,int8); cc4=fclose(fid4); %= %以上是DPCM编码的编码过程,为了使程序具有连贯性,将编码和解码放在同一个M文件目录下 %= %以下是DPCM解码 fid1=fopen

6、(mydata1.dat,r); fid2=fopen(mydata2.dat,r); fid3=fopen(mydata3.dat,r); fid4=fopen(mydata4.dat,r); I11=fread(fid1,cont1,int8); I12=fread(fid2,cont2,int8); I13=fread(fid3,cont3,int8); I14=fread(fid4,cont4,int8); tt=1; for l=1:n for k=1:m I1(k,l)=I11(tt); tt=tt+1; end end tt=1; for l=1:n for k=1:m I2(k

7、,l)=I12(tt); tt=tt+1; end end tt=1; for l=1:n for k=1:m I3(k,l)=I13(tt); tt=tt+1; end end tt=1; for l=1:n for k=1:m I4(k,l)=I14(tt); tt=tt+1; end end I1=double(I1); I2=double(I2); I3=double(I3); I4=double(I4); J1=ones(m,n); J1(1:m,1)=I1(1:m,1); J1(1,1:n)=I1(1,1:n); J1(1:m,n)=I1(1:m,n); J1(m,1:n)=I1(

8、m,1:n); J2=ones(m,n); J2(1:m,1)=I2(1:m,1); J2(1,1:n)=I2(1,1:n); J2(1:m,n)=I2(1:m,n); J2(m,1:n)=I2(m,1:n); J3=ones(m,n); J3(1:m,1)=I3(1:m,1); J3(1,1:n)=I3(1,1:n); J3(1:m,n)=I3(1:m,n); J3(m,1:n)=I3(m,1:n); J4=ones(m,n); J4(1:m,1)=I4(1:m,1); J4(1,1:n)=I4(1,1:n); J4(1:m,n)=I4(1:m,n); J4(m,1:n)=I4(m,1:n)

9、; %一阶解码 for k=2:m-1 for l=2:n-1 J1(k,l)=I1(k,l)+J1(k,l-1); end end cc1=fclose(fid1); J1=uint8(J1); %二阶解码 for k=2:m-1 for l=2:n-1 J2(k,l)=I2(k,l)+(J2(k,l-1)/2+J2(k-1,l)/2); end end cc2=fclose(fid2); J2=uint8(J2); %三阶解码 for k=2:m-1 for l=2:n-1 J3(k,l)=I3(k,l)+(J3(k,l-1)*(4/7)+J3(k-1,l)*(2/7)+J3(k-1,l-

10、1)*(1/7); end end cc3=fclose(fid3); J3=uint8(J3); %四阶解码 for k=2:m-1 for l=2:n-1 J4(k,l)=I4(k,l)+(J4(k,l-1)/2+J4(k-1,l)/4+J4(k-1,l-1)/8+J4(k-1,l+1)/8); end end cc4=fclose(fid4); J4=uint8(J4); %分区画图 figure(1) subplot(3,2,1); imshow(I03); %隐藏坐标轴和边框,以免坐标轴与标题重叠 axis off box off title(原始图像,fontsize,11,fon

11、tname,隶体); subplot(3,2,2); imshow(I02); axis off box off title(灰度图像,fontsize,11,fontname,隶体); subplot(3,2,3); imshow(J1); axis off box off title(一阶预测,fontsize,11,fontname,隶体); subplot(3,2,4); imshow(J2); axis off box off title(二阶预测,fontsize,11,fontname,隶体); subplot(3,2,5); imshow(J3); axis off box o

12、ff title(三阶预测,fontsize,11,fontname,隶体); subplot(3,2,6); imshow(J4); axis off box off title(四阶预测,fontsize,11,fontname,隶体); % 学会DPCM编码必须彻底了解DPCM编码原理 % DPCM编码是数字图形处理的一项应用 % Removing all variables, functions, and MEX-files from memory, leaving the % workspace empty. clear all % Deleting all figures whos

13、e handles are not hidden. close all % Deleting all figures including those with hidden handles. close all hidden % Clearing all input and output from the Command Window display giving us a clean screen. clc % Opening the file TEOTH.mp3 in the read access mode. fid = fopen (TEOTH.mp3,r); % Generating

14、 the input signal m(t) by reading the binary data in 16 bit % integer format from the specified file and writing it into a matrix % m(t) and the number of elements successfully read is returned into an % output argument count. m,count = fread (fid,int16); % Redefining the count for efficiency. count

15、 = 8500; % Setting the sampling frequency. % because the audio signal has a maximum frequency of 4K and according to % Nyquist criteria, we get the following sampling frequency. Fs = 8000; % Setting the sampling instant. Ts = 1; % Setting the number of samples to be used. No_Samples = (2*Fs)+Ts; % D

16、efine the time vector for the calculations. time = 1:Fs/64; % Calculating maximum value of the input signal m(t). Mp = max (m) % Setting number of bits in a symbol. bits = 5; % Number of levels of uniform quantization. levels = 2bits; % Calculating the bit rate. bit_rate = 8000*bits; % Since the DPC

17、M is implemented by the linear predictor (transversal % predictor) Hence setting up the prediction coefficient alpha. alpha = 0.45; % Transmitting the difference. % Since there is no estimated value before the first sample so we get diff_sig(1) = m(1); % Calculating the rest of the values of the dif

18、ference signal with the help % of coefficient. for k = 2:count, diff_sig(k) = m(k) - alpha*m(k-1); end % Calculating maximum value of the input signal diff_sig(t),i.e, to be % quantized. Dp = max (diff_sig) % Calculating the step size of the quantization. step_size = (2*Mp)/levels % Quantizing the d

19、ifference signal. for k = 1:No_Samples, samp_in(k) = m(k*Ts); quant_in(k) = samp_in(k)/step_size; error(k) = (samp_in(k) - quant_in(k)/No_Samples; end % quant_in = diff_sig/step_size; % Indicating the sign of the input signal m(t) and calculating the % quantized signal quant_out. signS = sign (m); q

20、uant_out = quant_in; for i = 1:count, S(i) = abs (quant_in(i) + 0.5; quant_out(i) = signS(i)*round(S(i)*step_size; end % Decoding the signal using the quantized difference signal. s_out = quant_out; s_out(1) = quant_out(1); for k = 2:count, s_out(k) = quant_out(k) + alpha*s_out(k-1); end % Calculati

21、ng the quantization noise Nq. Nq = (step_size)2)/12)*(Mp/Dp)2) % Calculating signal to noise ratio SNR. SNR = 1.5*(levels2) SNR_db = 10*log10(SNR) % Plotting the input signal m(t). %figure; subplot(4,1,1); plot(time,m(time),time,s_out(time),r); title(Input Speech Signal); xlabel(Time); ylabel(m(t);

22、grid on; % Plotting the quantized signal quant_in(t). %figure; subplot(4,1,2); stem(time,quant_in(time),r); title(Quantized Speech Signal); xlabel(Time); ylabel(Levels); grid on; % Plotting the DPCM signal s_out(t). %figure; subplot(4,1,3); plot(time,s_out(time); title(Decoded DPCM Speech Signal); x

23、label(Time); ylabel(Dq(t); grid on; % Plotting the error signal error(t). subplot(4,1,4); plot(time,error(time); title(Error Signal); xlabel(Time); ylabel(Error(t); grid on; % Removing all variables, functions, and MEX-files from memory, leaving the % workspace empty. clear all clear all close all %

24、Solicitatipo de se馻l a muestrear opcion = input(Escriba 1 siquierecodificar se馻l de audio o 2 siquierecodificarotra: ) %abre se馻l seleccionadapor el usuario if opcion=1; t_input = input(escriba el tiempo en segundosquedeseegrabar el audio: ); m = wavrecord(t_input*30000,30000,int16); %fid = fopen (s

25、onido.wav,r); %m = fread (fid,int16); ini_cuenta = 10; end if opcion=2; t = input(escriba el vector de tiempopara la se馻l: ); m = input(escriba la se馻l quedeseecodificar f(t): ); ini_cuenta = 2; end %Solicitafrecuencia de muestreo y niveles de cuantizacion Fs = input(escriba la frecuencia de muestre

26、o: ); levels = input(escriba los niveles de cuantizacion: ); Mp = max (m) %Calcula el nivel m醲imo de la se馻l step_size = (Mp*2)/levels %Incremento entre cadanivel de cuant particion = -Mp:step_size:Mp; %vector de particion (cuant) %particion = 0:step_size:2*Mp; Ts = 1; longitud_m = length(m); inc_mu

27、estreo = longitud_m/Fs; red_inc_muestreo = floor(inc_muestreo); No_samples = (red_inc_muestreo*Fs)+1; %Numero de muestras, %Muestreo for k=ini_cuenta:No_samples if k = ini_cuenta samp_in(k-1) = 0; ind_pcm = 1 end residuo = rem(k,red_inc_muestreo); if residuo = 0 samp_in(k) = m(k); elseifresiduo = 0

28、samp_in(k) = samp_in(k-1); end end %Cuantizacion quant = quantiz(samp_in,particion); pcm_cad = dec2bin(quant) ind_pcm = 1; %Genera codigobinario de PCM for h=ini_cuenta:No_samples residuo = rem(h,red_inc_muestreo); if residuo = 0 PCM(ind_pcm) = str2num(pcm_cad(h,:); ind_pcm = ind_pcm+1; end end subp

29、lot(2,2,1); plot(m); title(se馻l anal骻ica); xlabel(tiempo); ylabel(amplitud); subplot(2,2,2); stairs(samp_in); title(se馻l muestreada); xlabel(tiempo); ylabel(amplitud); subplot(2,2,3); plot(quant); title(se馻l cuantizada); xlabel(tiempo); ylabel(niveles de cuantizacion); DPCM预测编码的MATLAB原代码: 收藏 DPCM预测编码原代码: i1=imread(3.jpg); i1=rgb2gray(i1); i1=imcrop(i1,20 20 160 160); i=double(i1); m,n=size(i); p=zeros(m,n); y=zeros(m,n); y(1:m,1)=i(1:m,1); p(1:m,1)=i(1:m,1);

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2