I want to define inputs for the function quantized_signal

64 views (last 30 days)
Looking at this function:
function quantized_signal = nonlinear_quantize(signal, bits, method, param)
end
How do I define signal, bits, method and param?
  4 Comments
Sam Chak
Sam Chak on 29 Jan 2026 at 17:08
Could you please clarify what the {signal, bits, method, and param} are? We need to send these four inputs to the function nonlinear_quantize() in order to generate the output quantized_signal. If it is difficult to describe in words, please consider providing a sketch of the quantized_signal using the specified inputs {signal, bits, method, and param}.
Here is a code snippet:
% Sine wave function
function output_signal = sine_fcn(t, T, phi)
output_signal = sinpi(2/T*t + phi);
end
% user-defined parameters
T = 2; % time period to complete 1 oscillation
phi = 0; % phase angle in radian
t = linspace(0, 4, 4001);
% pass the inputs to sine_fcn()
x = sine_fcn(t, T, phi);
% plot the signal
plot(t, x), grid on
ylim([-1.5, 1.5])
title('Sine wave signal')
xlabel('Time, t')
ylabel('x(t)')
Walter Roberson
Walter Roberson on 29 Jan 2026 at 19:48
The code needs to be called as follows:
N = 512;
Signal = rand(1,N);
QS = nonlinear_quantize(Signal, 4, 'paisley_clown', 0.2198472);

Sign in to comment.

Accepted Answer

Sam Chak
Sam Chak on 29 Jan 2026 at 20:05
Not sure if this is what you are looking for. I discovered that MATLAB has a function for performing quantization. However, it requires the Communications Toolbox. For more examples, please refer to the documentation for quantiz().
t = [0:0.1:4];
sig = sinpi(t);
partition = [-1.0:0.2:1.0];
codebook = [-1.2:0.2:1.0];
[index, quants] = quantiz(sig, partition, codebook);
plot(t, sig, 'x', t, quants,'.'), grid on
title('Quantization of Sine Wave')
xlabel('Time')
ylabel('Amplitude')
legend('Original sampled sine wave','Quantized sine wave');
axis([-0.2, 4.2, -1.5 1.5])
  9 Comments
Sam Chak
Sam Chak about 1 hour ago
It is good to hear that, @Albert. You can replace the "x" signal with your own signal and the define the input parameters according to your quantization specifications.

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 29 Jan 2026 at 14:07
Are you asking in general about how to call functions in MATLAB? If so you probably want to look at this section of the Getting Started documentation. You may also want to work through the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
Are you asking what requirements this particular function has for its input arguments? As you've written it, the answer is none; there's no code in the body of the function so there's nothing to require that "this input is a positive scalar" or "that input is a square matrix", etc. [Of course, nothing in the (non-existent) code defines the variable quantized_signal that the function is supposed to return as output, so if you were to call this function with an output argument MATLAB would error.]
If you've snipped out the actual body for purposes of posting to MATLAB Answers, then you're going to have to look at the code, look at any help text or documentation the author has written describing the purpose/requirements of the input arguments, ask the author and/or maintainer for information on how to use this function, and/or try it out and deduce the requirements from any warning and/or error messages you receive when you call it with various inputs.

Products


Release

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!