Why i am getting same output and plot for spline and cubic?

Viewed 45

Input of digital systems is usually analog but after processing signals in digital form they give back output in analog form

I am trying to write a code for reconstruction of signal in matlab using interpolation technique but i am getting same output/plot for both interpolation types as shown in last plot of code.

My code is below:

t= 0:0.001:1;

fm= 10
fs= 8*48

x= sin(2*pi*fm*t)     % Message Signal

% Plotting discrete time sampled signal x[n]
% Pulse Traain
d= 0:1/50:1;
y= pulstran(t,d,'rectpuls',0.001)

% Sampling
z= x.*y
%  Non-uniformly quantize the discrete time signal using u-law companding
%    method, u= 100 and number of bits= 8.
% Quantization
N= 8
V= max(x)
u= 100

compsig= compand(x,u,V,'mu/compressor');
L= 2.^N
D= [max(compsig)-min(compsig)]./(L-1);
quants= quant(compsig,D);
xq= compand(quants,u,max(quants),'mu/expander')

% Encode the Signal into discrete levels.
H_e= dsp.UniformEncoder(max(xq),N);
encoder= step(H_e,xq)

%  Decoding the signal from discrete level and reconstruct using spline and cubic 
%    interpolation to reconstruct the analog signal x'(t) from the
%    discrete time signal using $t= 0.001.
H_d= dsp.UniformDecoder(max(xq),N);
decoder= step(H_d,encoder)

% Cubic Interpolation
time= 0:0.0001:1;
ci= interp1(t,decoder,time,'cubic')

% Spline interpolation
time=0:0.0001:1
si= interp1(t,decoder,time,'spline')

figure(01)
subplot(2,1,1)
plot(t,x,'R','LineWidth',2)
xlabel('Time')
ylabel('Amplitude')
legend('x')
title('Message Signal')

subplot(2,1,2)
plot(t,y,'B','LineWidth',2)
xlabel('Time')
ylabel('Amplitude')
legend('y')
title('Pulse Train')

figure(02)
subplot(2,1,1)
plot(t,z,'C','LineWidth',2)
xlabel('Time')
ylabel('Amplitude')
legend('z')
title('Sampled Signal')

subplot(2,1,2)
plot(t,xq,'G','LineWidth',2)
xlabel('Time')
ylabel('Amplitude')
legend('xq')
title('Quantized Signal')

figure(03)
subplot(2,1,1)
plot(t,encoder,'M','LineWidth',2)
xlabel('Time')
ylabel('Amplitude')
legend('encoder')
title('Encoded Signal')

subplot(2,1,2)
plot(t,decoder,'K','LineWidth',2)
ylim([-1 1])
xlabel('Time')
ylabel('Amplitude')
legend('decoder')
title('Decoded Signal')

figure(04)
subplot(2,1,1)
plot(time,ci,'B','LineWidth',2)
ylim([-1 1])
xlabel('Time')
ylabel('Amplitude')
legend('ci')
title('Cubic Interpolation')

subplot(2,1,2)
plot(time,ci,'R',time,si,'G')
xlabel('Time')
ylabel('Amplitude')
legend('si')
title('Spline & cubic Interpolation')

How can i see difference in output/plots of both types of interpolation?

1 Answers

There's only one correct reconstructed result, and both interpolation methods are trying to approximate that.

Your input is such that they both do a good job, so you just can't see any difference.

You will need some signal content near Fs/2 in order to see any difference, and even then it might be very difficult by eye to see which is better.

The reason both interpolators are working will is that they function like low-pass filters with cut-off frequency around Fs/2. They both have good response far below that frequency and not-so-good response near that frequency.

You can do a better job of reconstructing signals with content near Fs/2 by first interpolating with a good digital low-pass filter to multiply the sampling frequency by 8 or so, and then you can use cubic interpolation to get any values for any points between those new samples. You can even adjust your digital low-pass to correct for the small errors that cubic interpolation will eventually cause, to produce a very accurate result.

Related