0
$\begingroup$

We know digital computer cannot deal with continuous time signals directly. But then how MATLAB "plot" command works?

Does that uses interpolation technique to show an apparently continous time graph by connecting the various discrete data points?

Till now, i am able to understand is that MATLAB only handles discrete time data, MATLAB models continous time signals using discrete time signals but with very very small sampling interval,so it appears to be continuous while in reality it is discrete and then connects those discrete points using interpolation

I have also attached a snapshot of wikipedia where a graph of polynomial interpolation is shown

I have also attached a snapshot of chapter4 first page of book signal processing first, where interpolation discussion is mentioned

enter image description here

enter image description here

$\endgroup$

1 Answer 1

3
$\begingroup$

By default MATLAB uses linear interpolation when creating line plots, which means it simply draws a line from each point to each point, unless there are more points than pixels in which case each point or group of points within each pixel would represent each pixel shown.

Compare the following to see this:

This plots a line from x,y=1,2 to x,y= 5,7

plot([1 5], [2 7])

The above is the same as the following where a line is explicitly declared:

plot([1 5], [2 7], '-')

While in comparison the following will plot a “o” at each sample:

plot([1 5], [2 7], 'o') 

Update: To interpolate more smoothly between samples such as polynomial interpolation, you would need to create the interpolated samples and then plot the higher sampled result. The simplest way to do this in MATLAB is to use the resample command where resample(f,M,N) will interpolate the waveform $f$ by $M/N$ samples. Another approach demonstrated below is interpolating using the FFT. Although DSP.SE is not a MATLAB coding site, the following does demonstrate well how to properly do a time domain interpolation using a zero-padded IFFT which is of general signal processing interest. Zero padding in one domain results in interpolation in the other domain, however the technique is to "zero-pad" from the center of the frequency domain waveform with index k from 0 to N-1, such that the high frequency component of the FFT is extended.

N=6;
M=1000;
x= [0:N-1];
y = sin(2*pi*x/N);
fy = fft(y);
padfy = [fy(1:floor(N/2)) zeros(1, M-N) fy(floor(N/2+1:end))];
figure;
plot(N*[1:M]/M, M/N*real(ifft(padfy)));

Interpolation

$\endgroup$
4
  • 1
    $\begingroup$ @Man You can zoom in on MATLAB Plots to actually see that MATLAB does not do interpolation of any kind for displaying plots. It just draws a line between 2 adjacent values of function. To make the function appear continuous, all you can do is evaluate the function on a large number of closely spaced values of x. You might call what MATLAB does as linear interpolation though. $\endgroup$
    – DSP Rookie
    Commented Apr 6, 2020 at 17:54
  • 1
    $\begingroup$ @DSPRookie and Dan, Psssst, connecting the dots is called "linear interpolation". This thread should convince you that the Nyquist bin (if even) should be split before zero padding: dsp.stackexchange.com/questions/59068/… (except for degenerate cases like the one cited, i.e whole cycles per frame) This question and answers explore different interpolation techniques: dsp.stackexchange.com/questions/58032/… For me, it's MATLAB and I don't use it. $\endgroup$ Commented Apr 6, 2020 at 18:09
  • 1
    $\begingroup$ @CedronDawg Yeah, that's what I wrote in the last line of my comment, that it is linear interpolation what MATLAB does when plotting. $\endgroup$
    – DSP Rookie
    Commented Apr 6, 2020 at 18:23
  • 1
    $\begingroup$ @Dan please kindly update your answer to include one more line ,which mentions that "plot command is using linear interpolation," as mentioned by DSP Rookie and Cedron in their comments $\endgroup$
    – DSP_CS
    Commented Apr 8, 2020 at 8:05

Your Answer

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

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