is my code logically correct? will i get the same output when i do it manually?

15 views (last 30 days)
RUPADHARSHINI on 21 May 2024 at 9:24
Commented: Mathieu NOE on 28 May 2024 at 17:37
clear;
clc;
close all;
x = input('Enter a sequence: ');
figure(1);
subplot(3,1,1);
stem(x);
ylabel('Amplitude');
xlabel('Samples');
title('Input sequence');
% Decimation by 4
y1 = resample(x, 1, 4);
subplot(3,1,2);
stem(y1);
ylabel('Amplitude');
xlabel('Samples');
title('Decimation by 4 - Sequence');
% Interpolation by 4
y2 = resample(x, 4, 1);
subplot(3,1,3);
stem(y2);
ylabel('Amplitude');
xlabel('Samples');
title('Interpolation by 4 - Sequence');
% Sinusoidal signal
fs = 10;
N = 50;
f = 1;
n = 0:N-1;
Ts = 1/fs;
x1 = sin(2*pi*f*Ts*n);
figure(2);
% Sine signal
subplot(3,1,1);
stem(x1);
ylabel('Amplitude');
xlabel('Samples');
title('Sine signal');
% Decimation of sinusoidal signal by 4
yd_decimate = resample(x1, 1, 4);
subplot(3,1,2);
stem(yd_decimate);
ylabel('Amplitude');
xlabel('Samples');
title('Decimation by 4 - Sinusoidal signal');
% Interpolation of sinusoidal signal by 4
yd_interpolate = resample(x1, 4, 1);
subplot(3,1,3);
stem(yd_interpolate);
ylabel('Amplitude');
xlabel('Samples');
title('Interpolation by 4 - Sinusoidal signal');
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Answers (1)

Mathieu NOE on 21 May 2024 at 10:20
hello
I wondered if the exercise was more to prove that decimating then resampling (by the same factor) would give (almost) the original signal
if yes , you have to modify your code , like
% Interpolation of sinusoidal signal by 4
yd_interpolate = resample(x1, 4, 1);
must be changed into
% Interpolation of sinusoidal signal by 4
yd_interpolate = resample(yd_decimate, 4, 1);
(otherwise you are resampling the input signal not the decimated signal)
all the best
clear;
clc;
close all;
x = input('Enter a sequence: ');
figure(1);
subplot(3,1,1);
stem(x);
ylabel('Amplitude');
xlabel('Samples');
title('Input sequence');
% Decimation by 4
y1 = resample(x, 1, 4);
subplot(3,1,2);
stem(y1);
ylabel('Amplitude');
xlabel('Samples');
title('Decimation by 4 - Sequence');
% Interpolation by 4
% y2 = resample(x, 4, 1);
y2 = resample(y1, 4, 1);
subplot(3,1,3);
stem(y2);
ylabel('Amplitude');
xlabel('Samples');
title('Interpolation by 4 - Sequence');
% Sinusoidal signal
fs = 10;
N = 50;
f = 1;
n = 0:N-1;
Ts = 1/fs;
x1 = sin(2*pi*f*Ts*n);
figure(2);
% Sine signal
subplot(3,1,1);
stem(x1);
ylabel('Amplitude');
xlabel('Samples');
title('Sine signal');
% Decimation of sinusoidal signal by 4
yd_decimate = resample(x1, 1, 4);
subplot(3,1,2);
stem(yd_decimate);
ylabel('Amplitude');
xlabel('Samples');
title('Decimation by 4 - Sinusoidal signal');
% Interpolation of sinusoidal signal by 4
% yd_interpolate = resample(x1, 4, 1);
yd_interpolate = resample(yd_decimate, 4, 1);
subplot(3,1,3);
stem(yd_interpolate);
ylabel('Amplitude');
xlabel('Samples');
title('Interpolation by 4 - Sinusoidal signal');
1 CommentShow -1 older commentsHide -1 older comments
Mathieu NOE on 28 May 2024 at 17:37
hello again
problem solved ?

Sign in to comment.

Categories

Find more on Multirate Signal Processing 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!