Home > matlab code > requantise

requantise

% this function takes a signal ip and modifies it so that
% occupies 2^(num_bits) quantisation levels
%
% ns = rand(1, 1000);
% op = requantise(ns, 2);
% plot(ns)
% hold on 
% plot(op,'r') % youshould be able to clearly see the 4 possible levels the
% new signal occupies
function op = requantise(ip, num_bits)
    num_levels = 2^num_bits;
    quantization_diff = (max(ip)-min(ip))/num_levels;
    quantization_levels = min(ip)+quantization_diff/2:quantization_diff:max(ip)-quantization_diff/2;
    op = zeros(1,length(ip));
    for k = 1: length(ip)
        [min_diff closest_level_index] = min(abs(quantization_levels-  ip(k)));
        op(k) = quantization_levels(closest_level_index);
    end
Advertisement
Categories: matlab code
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: