⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcm_a.m

📁 PCM(脉冲编码调制
💻 M
字号:
echo off
clear,clc

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SNR_Max = 12;
Fc = 10000; 
Fs1 = 15000;
Fs = Fs1;
t = (0:1/Fs:5/Fc-1/Fs);   % column vector with all the time samples
y = cos(2*pi*Fc*t)+rand(1,length(t));
Y=abs(fftshift(fft(y)));
N=length(t);
f=(0:N-1)/N*Fs-Fs/2;
subplot(212);plot(f,Y/N)
title('原始信号频谱')
subplot(211);plot(t,y)
title('原始信号(采样率Fs<2Fm)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SNR_Max = 12;
clear,clc
Fc = 10000; 
Fs2 = 100000;
Fs = Fs2;
t = (0:1/Fs:5/Fc-1/Fs);   % column vector with all the time samples
y = cos(2*pi*Fc*t)+rand(1,length(t));
Y=abs(fftshift(fft(y)));
N=length(t);
f=(0:N-1)/N*Fs-Fs/2;
figure
subplot(212);plot(f,Y/N)
title('原始信号频谱')
subplot(211);plot(t,y)
title('原始信号(采样率Fs>2Fm)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

in = y;
Note=[32 64 128];
for i1=1:length(Note)
%     %%%%%%%%%%%%%%%%%%%%分析信噪比对量化误差的影响%%%%%
%     if i1==3
%         snr_dB=0:2:12;
%         for i2=1:length(snr_dB);
%             snr = 10^(snr_dB(i1)/10);   %SNR
%             in=in+sqrt(1/snr)*rand(1,N);
%             out1=compand(in, 87.6, 1, 'A/compressor'); %A律压缩
%             [out_,code]=u_pcm(out1, Note(i1));  %线性编码
%             out21=compand(out_, 87.6, 1, 'A/expander'); %A律解压
%             err(i2)=sum(abs(in-out21));
%         end
%         clear snr in out1 out_ code out21;
%         in=y;
%         figure
%         plot(snr_dB,err);
%         xlabel('信噪比(dB)')
%         ylabel('量化误差和')
%         title('分析信噪比对量化误差的影响')
%     end
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    out1=compand(in, 87.6, 1, 'A/compressor'); %A律压缩
    [out_,code]=u_pcm(out1, Note(i1));  %线性编码
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %u_pcm 一个序列的均匀PCM编码
    %[a_quan,code]=u_pcm(a,n)
    %a=输入序列
    %n=量化级数的数目(偶数)
    %a_quan=编码前的量化输出
    %code=编码后的输出
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    out2(i1,:)=compand(out_, 87.6, 1, 'A/expander'); %A律解压
end
figure
plot(t,out2(1,:),'-o',t,out2(2,:),'-d',t,out2(3,:),'-*',t,in,'r')
legend('量化级数32','量化级数64','量化级数128','原始信号')
xlabel('时间')
ylabel('幅度')
title('量化级数对信号恢复的影响分析');
figure
plot([1:N], in-out2(3,:),'-r+');  %量化误差,out_为编码前的量化输出
title('量化误差');xlabel('n');ylabel('dV');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h0 = figure('Units','points', ...
	'Color',[0.8 0.8 0.8], ...
	'Colormap','default', ...
	'FileName','start.m', ...
	'MenuBar','none', ...
	'Name','量化输出码组 ', ...
	'NumberTitle','off', ...
	'PaperPosition',[18 180 476 432], ...
	'PaperUnits','points', ...
	'Position',[230 150 275.25 250.5], ...
	'Resize','on', ...
	'Tag','UIFigure', ...
	'ToolBar','none');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',1.0, ...
	'Position',[10.75 17.5 193.75 223.75], ...
	'String','', ...
	'Style','listbox', ...
	'Tag','NumofSim');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',1.0, ...
	'Position',[210.75 17.5 93.75 23.75], ...
	'String','', ...
	'Style','Text', ...
	'Tag','Rank');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(findobj('Tag','NumofSim'),'string',num2str(code))
set(findobj('Tag','Rank'),'string','量化级数为128')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -