is my code logically correct? will i get the same output when i do it manually?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Mathieu NOE
2024-5-21
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');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!