# How to reconstruct original signal from sampled signal?

My original signal as

f1=2;
f2=5;

fs=100;
Ts=1/fs;
t=0:Ts:1;

xt=cos(2*pi*f1*t)+cos(2*pi*f2*t);

figure
plot(t,xt)


as shown below figure.

and my sampled signal with fs=12 which is greater than two times of maximum frequency, 2*f2=10;

fs=12;
Ts=1/fs;
tn=0:Ts:1;

xn=cos(2*pi*f1*tn)+cos(2*pi*f2*tn);


and then I want to reconstruct the original signal with sampled signal.

I tried it using the matlab function interp1 as below

xr=interp1(tn,xn,t,'spline');


I compared original signal and reconstructed signal, but they are different as shown below figure.

How to reconstruct original signal?

Sinc interpolation can exactly reconstruct an above-Nyquist-sampled strictly bandlimited signal from noiseless samples. See the Whittaker-Kotelnikov-Shannon reconstruction or resampling theorem: https://en.wikipedia.org/wiki/Whittaker–Shannon_interpolation_formula and https://ccrma.stanford.edu/~jos/resample/Theory_Ideal_Bandlimited_Interpolation.html

For computation, you can try using a windowed Sinc (or other near-brick-wall linear phase low pass filter) for a more reasonable finite length interpolation kernel. For any finite length of samples, both the band-limit and the low-pass reconstruction filter's stop-band need to be strictly below (NOT equal to) half the sampling rate. Due to finite window length, and finite-precision floating point sampling and arithmetic, you may see some end effects and other reconstruction differences.

• Thank you so much. May 17, 2021 at 7:13
• For ideal Sinc interpolation you need an infinite number of samples. A windowed Sinc allows you to use a finite set of samples, but you are going to have end effects and the beginning and end of your data i.e. where you run out of data. May 17, 2021 at 14:18

To implement a digital-to-analog converter, all you need is an ideal low-pass filter to filter out the periodic frequency response that $$\varOmega \geq \varOmega_s/2$$.

H(j\varOmega) =\left\{ \begin{aligned} T,\ \ \ \ |\varOmega|<\varOmega_s/2 \\ 0,\ \ \ \ |\varOmega|\geq\varOmega_s/2 \end{aligned} \right.

The impulse response of an ideal low-pass filter is a sinc function

$$h(t) = \frac{\sin(\pi t/T)}{\pi t/T}$$

Convolving the sampled signal with this impulse response gives the analog signal.

\begin{aligned} y_a(t) =& \sum_{n=-\infty}^{\infty} x_a(nt) h(t-nT)\\ =&\sum_{n=-\infty}^{\infty} x(n) \frac{\sin[\pi (t-nT)/T]}{\pi (t-nT)/T} \end{aligned}

f1=2;
f2=5;

fs=100;
Ts=1/fs;
t=0:Ts:1;
xt=cos(2*pi*f1*t)+cos(2*pi*f2*t);
figure
plot(t,xt)

fs=12;
Tn=1/fs;
tn=0:Tn:1;
xn=cos(2*pi*f1*tn)+cos(2*pi*f2*tn);
hold on
stem(tn, xn)

y = dac(xn, Tn, t);
plot(t,y)

function y = dac(x, T, t)
m = 0:length(x)-1;
y = zeros(1, length(t));
for ii = 1:length(t)
h = sinc((t(ii)-m*T)/T);
y(ii) = sum(x .* h);
end
end

• Thank you so much. May 17, 2021 at 7:13