0
$\begingroup$

Which command should be used for quantization of a signal in MATLAB?

Please check above question link especially answer of @Hilmar, especially the first paragraph of answer and especially the highlighted statement:

"Every signal that's represented as a vector or a matrix in Matlab is already quantized. You can't really represent an analog signal in Matlab: once it's list of numbers, it's discrete in time and in amplitude"

Does this statements holds true for each and every case??

$\endgroup$
2
  • 2
    $\begingroup$ Continuous-time signals not only have an infinite number of values to represent them, it's an uncountably infinite number of values. How are you gonna get a computer to represent such a signal generally? $\endgroup$ Mar 2 at 5:33
  • $\begingroup$ You can't really represent an analog signal in Matlab: once it's list of numbers, ---- I would say that this does not hold true in each and every case. $\endgroup$ Mar 20 at 1:46

3 Answers 3

3
$\begingroup$

MATLAB does support the evaluation of symbolic inputs with variable-precision floating point, which means we can represent numerical values to any precision desired at any time step desired, as limited by the memory of the computer. That said, we could feasibly represent a number to 1000 bits of precision with an arbitrarily small time step if needed which for practical terms could be viewed as well beyond what is needed for "proper and exact". On theoretical terms since continuous time signals have infinite precision and infinitely small time steps, such accuracy can never be reached with finite memory and finite time.

$\endgroup$
11
  • $\begingroup$ So in nutshell,you mean that theoretically we can not fully/completely represent continous time signals in MATLAB but practically we can with a very very small(almost negligible) error?? $\endgroup$
    – DSP_CS
    Mar 13 at 14:07
  • $\begingroup$ @engr Yes exactly as on any digital computer or computation, as far as the ability to represent the waveform at any position in time at any precision. Does this answer your question? $\endgroup$ Mar 13 at 14:27
  • $\begingroup$ Yes. Thank you so much. Have a nice day $\endgroup$
    – DSP_CS
    Mar 13 at 14:43
  • 1
    $\begingroup$ That is just quantization in time, so same considerations as far as noise (in time it is phase noise). As the time step approaches zero, we approach a continuous waveform and we can choose any arbitrary time step (in a computer). But agree it is not continuous but also my point is that doesn’t matter, it can be arbitrarily close to continuous. $\endgroup$ Mar 19 at 18:51
  • 1
    $\begingroup$ @OverLordGoldDragon A set of samples can represent the continuous-domain (band limited) function with arbitrary precision -- let's assume it's 100% accurate. It's still a set of samples. This is the only point I'm trying to get across here. As I interpret the question, OP asks whether we can represent a signal in another way that is not a set of samples. All I'm reading here is that a set of samples is potentially good enough for any application, that you can reconstruct the continuous signal from the samples. Which is true, but not necessarily an answer to the question as I read it. $\endgroup$ Mar 21 at 20:53
3
$\begingroup$

If you have a sampled signal (stored as a finite number of sample values, assumed uniformly sampled) and you assume that the samples represent the values of a continuous-time signal at those uniformly-spaced sampling instances, and you assume that the original continuous-time was bandlimited to less than half of the sample rate, then you have sufficient information to represent this continuous-time signal and you can write software that will give you the value of that continuous-time signal at any continuous time at a precision you set in advance.

$\endgroup$
4
  • $\begingroup$ …except that sampling theory assumes an infinite series of samples. Near the ends of the finite series the approximation of the continuous signal is poor, elsewhere it might be good, but never exact. Also, noise is never band-limited. $\endgroup$ Mar 21 at 19:39
  • $\begingroup$ I said "at a precision you set in advance". $\endgroup$ Mar 21 at 19:43
  • $\begingroup$ And white noise is not band-limited. And because of that, it has infinite power. We can't really talk about white noise with finite power unless we bandlimit it to the bandwidth of the system it exists in. So, for sampled systems, you can run your noise, whether it's white or not, through a brickwall filter with Nyquist bandwidth (half of the sample rate). That is what we would assume of simulated noise that is a good random number generated each sample. $\endgroup$ Mar 21 at 20:41
  • $\begingroup$ I think it’s a great answer and upvoted ; I think it would read even better if quantization was mentioned in the first sentence $\endgroup$ Mar 21 at 23:22
1
$\begingroup$

So Cris Luengo, here is a short MATLAB program demonstrating this. (The purpose of the program was to demonstrate something about a discontinuity that causes the interpolated bandlimited function to exceed the samples by several dB. But you can change the input sequence, $x[n]$, if you want.)

Now, the length of the interpolation filter is $N$ and the number of fractional times between each input sample is $R$. This uses a simple Kaiser-windowed $\operatorname{sinc}(\cdot)$ function, but you can design your reconstruction filter however you think is better.

It's a ridiculously long interpolation filter; it looks 2048 samples in the past and 2048 samples into the future to interpolate between any two adjacent samples. So the brickwall is pretty damn bricky. And there are 256 little fractional delays in between each input sample. Both numbers can be increased to as high as you need to make the precision of this reconstruction to be as good as you need.

And the continuous-time $t$ need not be an integer multiple of $\frac{1}{R}$. You can set $R$ very large and then linearly interpolate between adjacent micro-samples and have $t$ have any precision you want. If you don't like linear interpolation, you can use a higher order polynomial like a cubic Hermite spline and get it even more smooth. Ain't smooth enough? Then increase $R$. Brickwall filter not bricky enough? Then increase $N$.

N = 4096;      % number of samples used in interpolation calculation
R = 256;       % number of equally-spaced fractional sample delays


stop_band_attenuation = 90;

h = zeros(1, N*R);          % zero the whole thang

t = linspace(-N/2+1/R, N/2-1/R, N*R-1);
h = [0 sinc(t)/R .* kaiser(N*R-1, 0.1102*(stop_band_attenuation-8.7))'] ;       % kaiser windowed sinc()
clear t;

%
%   this defines a simple triangle (linear) interpolation function (for testing purposes)
%
%   h((N/2-1)*R+1:(N/2)*R+1) = linspace(0.0, 1.0/R, R+1);
%   h((N/2)*R+1:(N/2+1)*R+1) = linspace(1.0/R, 0.0, R+1);
%


xLen = 16384;
t_x = linspace(-xLen/2, xLen/2-1, xLen);

x = [repmat([-1 1], 1, xLen/4) repmat([1 -1], 1, xLen/4)];

yLen = R*(xLen+N);
t_y = linspace(-(xLen+N)/2, (xLen+N)/2-1/R, yLen);

y = zeros(1, yLen);

for n = 0:xLen-1
    y(R*n+1:R*n+R*N) = y(R*n+1:R*n+R*N) + x(n+1)*R*h;
end


figure(1)
plot(t_x, x, 'ro')
hold on
plot(t_y, y, 'b')
hold off


figure(2)
plot(R*h);                          % plot impulse response
pause;

freq = linspace(0, R-R/(8*N*R), 8*N*R);                                     % set of frequencies from DC to just under Nyquist
H = fft([h([N*R/2:N*R-1]) zeros(1, 15*N*R+1) h([1:N*R/2-1])]);              % fft after zero-padding to extend length by factor of 8
plot(freq, 20*log10(abs(H(1:8*N*R))+1e-16));                                % dB by linear freq plot
pause;

semilogx(freq(2:8*N*R), 20*log10(abs(H(2:8*N*R))+1e-16));                   % dB by log freq plot, skip DC
pause;

So here is what the brickwall filter looks like. Is it sufficiently bricky for you?

brickwall filter frequency response

$\endgroup$
3
  • $\begingroup$ I know, I know, you can approximate a band-limited continuous function with any precision using a set of uniform samples. My career is based on that. :) I was just being overly anal about the details of sampling theory. [By the way, I didn't downvote your post.] $\endgroup$ Mar 21 at 20:46
  • $\begingroup$ Since I got a +8, evidently this answer got both an upvote and a downvote. Dunno why it deserves a downvote. But my point is, you can have a stream of uniformly-spaced samples $x[n]$. And you can derive a continuous-time function, $x(t)$ that these samples represent. Now, of course you can't represent that $x(t)$ at every value of $t$ (that's an uncountably infinite number of times). But you can represent $x(t)$ (to within any finite precision) at any value of $t$, no matter how fine the time resolution is and within any given accuracy for $x(t)$. $\endgroup$ Mar 21 at 20:53
  • $\begingroup$ You can click on the post's score to get a break-down of up and down votes. $\endgroup$ Mar 21 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.