What is wrong with my code ,why i am getting exactly same output and plot for spline and cubic?

5 vues (au cours des 30 derniers jours)
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:
clc
clear all
close all
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?
  6 commentaires
ABTJ
ABTJ le 4 Juil 2020
@star strider, yes that question resolves the confusion to a great extent but here the difference between both cases was very very small,so small that when i plot them together ,it is unable to differentiate between them with normal zoom while in case of your referred question,this wasn't case and difference was noticeable when plotted together

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 3 Juil 2020
A spline is a cubic interpolation between points with the added requirement that the slopes match at the knot points. Not sure what cubic does (if it has a slope matching requirement) but if the slopes are close to matching anyway, it might not make much difference.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by