Cody

# Problem 263. Nonuniform quantizer as a piecewise constant function

Solution 261136

Submitted on 14 Jun 2013 by Dan
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% assert(isequal(nonuniformQuantizer(-23), -3.5));

ans = -3.5000

2   Pass
%% assert(isequal(nonuniformQuantizer(0), 0.5));

ans = 0.5000

3   Pass
%% assert(isequal(nonuniformQuantizer(1.1), 1.5));

ans = 1.5000

4   Pass
%% assert(isequal(nonuniformQuantizer(2.9), 1.5));

ans = 1.5000

5   Pass
%% assert(isequal(nonuniformQuantizer(-Inf), -3.5));

ans = -3.5000

6   Pass
%% assert(isequal(nonuniformQuantizer(Inf), 3.5));

ans = 3.5000

7   Pass
%% x = -4.0:0.5:4.5; y = [-3.5 -3.5 -1.5 -1.5 -1.5 ... -1.5 -0.5 -0.5 0.5 0.5 1.5 ... 1.5 1.5 1.5 3.5 3.5 3.5 3.5]; assert(isequal(y, nonuniformQuantizer(x)));

ans = Columns 1 through 10 -3.5000 -3.5000 -1.5000 -1.5000 -1.5000 -1.5000 -0.5000 -0.5000 0.5000 0.5000 Columns 11 through 18 1.5000 1.5000 1.5000 1.5000 3.5000 3.5000 3.5000 3.5000

8   Pass
%% x = -4.0:0.5:4.5; y = [-3.5 -3.5 -1.5 -1.5 -1.5 ... -1.5 -0.5 -0.5 0.5 0.5 1.5 ... 1.5 1.5 1.5 3.5 3.5 3.5 3.5]; assert(isequal(y', nonuniformQuantizer(x')));

ans = -3.5000 -3.5000 -1.5000 -1.5000 -1.5000 -1.5000 -0.5000 -0.5000 0.5000 0.5000 1.5000 1.5000 1.5000 1.5000 3.5000 3.5000 3.5000 3.5000

9   Pass
%% x = -4.0:0.5:4.5; y = [-3.5 -3.5 -1.5 -1.5 -1.5 ... -1.5 -0.5 -0.5 0.5 0.5 1.5 ... 1.5 1.5 1.5 3.5 3.5 3.5 3.5]; assert(isequal(reshape(y,3,6), ... nonuniformQuantizer(reshape(x,3,6))));

ans = -3.5000 -1.5000 -0.5000 0.5000 1.5000 3.5000 -3.5000 -1.5000 -0.5000 1.5000 1.5000 3.5000 -1.5000 -1.5000 0.5000 1.5000 3.5000 3.5000

10   Pass
%% x = -4.0:0.5:4.5; y = [-3.5 -3.5 -1.5 -1.5 -1.5 ... -1.5 -0.5 -0.5 0.5 0.5 1.5 ... 1.5 1.5 1.5 3.5 3.5 3.5 3.5]; assert(isequal(reshape(y,1,6,3), ... nonuniformQuantizer(reshape(x,1,6,3))));

ans(:,:,1) = -3.5000 -3.5000 -1.5000 -1.5000 -1.5000 -1.5000 ans(:,:,2) = -0.5000 -0.5000 0.5000 0.5000 1.5000 1.5000 ans(:,:,3) = 1.5000 1.5000 3.5000 3.5000 3.5000 3.5000