?? pcm_a.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=量化級數(shù)的數(shù)目(偶數(shù))
%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('量化級數(shù)32','量化級數(shù)64','量化級數(shù)128','原始信號')
xlabel('時間')
ylabel('幅度')
title('量化級數(shù)對信號恢復的影響分析');
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','量化級數(shù)為128')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -