0

I have a continuous signal which I want to convert to a step-like function (I'm not sure what the correct term is)

So every sample in the lower part of the signal should be replaced by 1, middle ones 2 and high ones 3. And I want to control the size of steps (which is 3 in this example, but it can change)

How can I do that with MATLAB? Thanks in advance.

P.S.

I tried quant and ordinal, but I couldn't make it.

jeff
  • 13,055
  • 29
  • 78
  • 136

3 Answers3

0

Do you want something like this?

x = randn(1000, 1); % your signal
y = zeros(size(x));
y(x < -1) = 1;
y(x >= -1 & x < 3) = 2;
y(x >= 3) = 3;

You can get the quantiles using quantile to decide the thresholds.

Memming
  • 1,731
  • 13
  • 25
0

You could use combinations of the heaviside function. I should mention that sometimes H(x=0)=0.5.

x=linspace(-1,5);  % your signal to be quantized---- could be anything
y= a*heaviside(x-x1)  + b*heaviside(x-x2) + c;   
% a, b and c decide the heights of your quantization
%   x1 and x2 decide the levels

if you want a fourth level just use the following

y= a*heaviside(x-x1)  + b*heaviside(x-x2) + c*heaviside(x-x3)  +e;

The function is defined here: http://en.wikipedia.org/wiki/Heaviside_step_function

To quantize to k levels

    fun=a
    for k=1:n
       fun = fun+ h(i)*heaviside(x-xi(k))
    end
    fun=fun/normalization   % normalization is a number to decide the level of your signal
0

I think this is not quite what you are asking, but it may have some helpful information.

The Matlab fixed-point toolbox can deal with quantized (limited precision) numbers and arithmetic. Type "help fi" to see how to declare fixed-point number with a particular word length, fraction length, and signedness. This is especially helpful for binary point scaling (each bit position in the binary word signifies a power of 2).

You may need a special license for this toolbox.

Adam W
  • 1