What is wrong with my code ,why i am getting exactly same output and plot for spline and cubic?
Show older comments
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 Comments
KALYAN ACHARJYA
on 3 Jul 2020
You mean decoder and ci variables?
ABTJ
on 3 Jul 2020
John D'Errico
on 3 Jul 2020
Edited: John D'Errico
on 3 Jul 2020
Lacking the signal processin TB, do they plots just look the same? Or are the vectors si and ci IDENTICALLY the same? For example, what do these commands report?
norm(si - ci)
norm(si)
Given the fine spacing on what should be a smooth relation, I'd expect to see differences between si and ci that are quite small, but not identically zero, and probably larger than eps.
Star Strider
on 3 Jul 2020
ABTJ
on 4 Jul 2020
ABTJ
on 4 Jul 2020
Accepted Answer
More Answers (0)
Categories
Find more on Spectral Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!