I want to define inputs for the function quantized_signal
64 views (last 30 days)
Show older comments
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
on 29 Jan 2026 at 17:08
Hi @Albert
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
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);
Accepted Answer
Sam Chak
on 29 Jan 2026 at 20:05
Hi @Albert
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
More Answers (1)
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.
0 Comments
See Also
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

