Formulating a function on Matlab for the Shannon interpolation formula - Signal Processing Stack Exchange most recent 30 from dsp.stackexchange.com 2019-11-15T00:01:47Z https://dsp.stackexchange.com/feeds/question/37480 https://creativecommons.org/licenses/by-sa/4.0/rdf https://dsp.stackexchange.com/q/37480 0 Formulating a function on Matlab for the Shannon interpolation formula Jason Born https://dsp.stackexchange.com/users/20662 2017-02-07T17:26:33Z 2017-02-08T06:18:49Z <p>I am trying to formulate an algorithm for applying to Shannon interpolation formula to the discrete signal</p> <p>$$x[n]=\frac{c^2}{4}\int\limits_{0}^{n T}y\left(\tfrac{c}{2}s\right)\,ds,$$</p> <p>where $c$ is constant. Now, if $\frac{1}{T}=f_{s}&gt;2B$, where $B$ is the band-limit of $X(f)$, then we can reconstruct the continuous time signal as:</p> <p>$$x_{\text{const}}(t)=\sum\limits_{n=-\infty}^{\infty}\frac{c^2}{4}{\int\limits_{0}^{n T}y\left(\tfrac{c}{2}s\right)\,ds}\cdot\text{sinc}\left(\frac{t-n T}{T}\right)$$</p> <pre><code>function x=interpolate(y,N,T,c) x=0; for n=1:N x=x+((c^2)/2)*integral(y,0,n.*T).*sinc((t-n.*T)./T); end </code></pre> <p>However, I am having trouble with incorporating the <code>t</code> variable here. Setting it as global and running <code>interpolate(y,20,20,1)</code> also produces nothing to note.</p> <p>Note that the continuous time signal in question is given by</p> <p>$$x_{\text{true}}(t)=\frac{c^2}{4}\int_{0}^{t}y\left(\tfrac{c}{2}s\right)\,ds.$$</p> https://dsp.stackexchange.com/questions/37480/-/37490#37490 3 Answer by Maximilian Matthé for Formulating a function on Matlab for the Shannon interpolation formula Maximilian Matthé https://dsp.stackexchange.com/users/24701 2017-02-08T06:18:49Z 2017-02-08T06:18:49Z <p>Given your samples $x[n]$, here's a code to perform the interpolation by the sinc-functions:</p> <pre><code>F = 1000; % the sampling frequency used for drawing the continuous function Fs = 50; % the sampling frequency T = 1/Fs; % the sampling time t = 0:1/F:1; % the time-samples for "continuous" plotting ts = 0:T:1; % the time at the sample points % the original function. In your case, this would be integral expression x = @(t) sin(2*pi*10*t) + cos(2*pi*11*t); xn = x(ts); % the discrete sequence % perform interpolation from xn to x: interpolated = 0; for n=1:length(ts) % n-1 due to the 1-based indexing of matlab interpolated = interpolated + xn(n) * sinc((t-(n-1)*T)/T); end hold off; plot(t, x(t), 'r', 'linewidth', 3); hold on; % plot continuous stem(ts, xn); hold on; % plot sampled plot(t, interpolated, 'k-o'); % plot interpolated on top of red curve </code></pre> <p><a href="https://i.stack.imgur.com/EDWhd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EDWhd.png" alt="enter image description here"></a></p> <p>As a bonus, here's what happens when the signal is not enough bandlimited: I changed the frequency of the first sine from $sin(2\pi 10 t)$ to $sin(2\pi 30 t)$: <a href="https://i.stack.imgur.com/zqVjX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zqVjX.png" alt="enter image description here"></a></p> <p>Note: The Shannon-Interpolation requires bandlimited signals, so in particular it does not work exactly with time-limeted signals (since these are never band-limited). So, you will see some deviations especially at the edge of the signal.</p>