通信人家园

 找回密码
 注册

只需一步,快速开始

短信验证,便捷登录

搜索

军衔等级:

  下士

注册:2010-3-17
跳转到指定楼层
1#
发表于 2013-12-4 22:14:25 |只看该作者 |倒序浏览
还是一样,先贴程序
%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的值就可以修改量化电平数,量化电平数越少,量化误差越大。

举报本楼

本帖有 2 个回帖,您需要登录后才能浏览 登录 | 注册
您需要登录后才可以回帖 登录 | 注册 |

手机版|C114 ( 沪ICP备12002291号-1 )|联系我们 |网站地图  

GMT+8, 2024-5-22 08:58 , Processed in 0.120005 second(s), 18 queries , Gzip On.

Copyright © 1999-2023 C114 All Rights Reserved

Discuz Licensed

回顶部