通信人家园

标题: 在matlab中理解抽样量化的概念:均匀量化的实现  [查看完整版帖子] [打印本页]

时间:  2013-12-4 22:14
作者: s466501480     标题: 在matlab中理解抽样量化的概念:均匀量化的实现

还是一样,先贴程序
%sampling and quantisation
clc;
clear;
%sampling
A = 1; % sinusoid's amplitude
f = 2;% frequency Hz
phase = 0*pi;% phase Rad
f_sample = 1000;%sample frequecy
t_start = 0;
t_stop = 1;
t = t_start:1/f_sample:t_stop;
y = A*sin(2*pi*f*t+phase); % y includes all sampled value
figure(1);
plot(t,y);
xlabel('t');
grid on;

%quantisation
n = 2; % n bits represent the number of 2^n combinations
M = 2^n;% quantization level
delta_v = 2*A/M; % quantization interval
m_i = zeros(1,M);% mi = a + i*delta_v, quantization_endpoint_value
for i = 1:M
    m_i(i) = -A + i*delta_v;
end
m_i_ahead = [-A m_i(1:end-1)]; % mi-1
% quantization_value qi = (mi+mi-1)/2
q_i = (m_i + m_i_ahead)/2;

% find the sampled valued which is the nearst to quantization value
y_hat = repmat(y,M,1);
q_i_hat = repmat(q_i.',1,size(y_hat,2));
nearst_value = abs(y_hat - q_i_hat);
[min_value min_location] = min(nearst_value,[],1);
min_location_hat = min_location-1;%because the value of min_location is from 1 to 8, change
% it from 0 to 7, in order to turn it to 000,001,010...
y_digital = dec2bin(min_location_hat,n);

% plot quantization_value
hold on;
plot(t,q_i_hat(min_location),'r');
legend('sampled value','quantized value')


程序的第一部分我在之前发的一个帖子里说明过,就是一个时间上离散但是数值上是连续的信号(抽样过的信号),那么接下来我们要做的就是给信号量化成数字信号。具体的理论书上都有,不在这细谈,可以书上查找查找,我这里仿真的是最简单的均与量化,至于非均匀量化,看懂原理,花费些时间,都可以编出来。
量化电平数 M = 2^n;
均匀量化间隔 delta_v = (b-a)/M;
量化区间终点 mi = a+i*delta_v ;
量化区间中点 qi = (mi+mi_1)/2, i = 1,2,3...M,

5.jpg 6.jpg 7.jpg
有兴趣的可以下下来试试,修改n的值就可以修改量化电平数,量化电平数越少,量化误差越大。


附件: 5.jpg (2013-12-4 22:09, 42.35 KB) / 下载次数 0
https://www.txrjy.com/forum.php?mod=attachment&aid=MjI2NDA0fGMzODEwYWJifDE3MzI0MTU5MTh8MHww

附件: 6.jpg (2013-12-4 22:09, 42.07 KB) / 下载次数 0
https://www.txrjy.com/forum.php?mod=attachment&aid=MjI2NDA1fDFkMjRiYzg5fDE3MzI0MTU5MTh8MHww

附件: 7.jpg (2013-12-4 22:09, 41.87 KB) / 下载次数 0
https://www.txrjy.com/forum.php?mod=attachment&aid=MjI2NDA2fDNiZjlmMjYyfDE3MzI0MTU5MTh8MHww
时间:  2013-12-4 22:57
作者: 天玉英杰

曾经熟悉的身影现在变得那么的模糊!!!!!!
时间:  2016-5-21 14:21
作者: 帅张

不错啊




通信人家园 (https://www.txrjy.com/) Powered by C114