Filter löschen
Filter löschen

Resampling a signal without using built-in command

28 Ansichten (letzte 30 Tage)
Arsalan Amin
Arsalan Amin am 9 Feb. 2022
Beantwortet: AndresVar am 10 Feb. 2022
Attached below is my effort of doing this question but I was not able to obtain required output:
clear; clc;
f = 30;
fs = 200;
t = 0:(1/fs):1;
x = cos(2*pi*f*t);
title('Orignal Signal')
%%%%%%%%%%%%%%%%%%% Part A %%%%%%%%%%%%%%%%%%
R_a = 1.66;
[L_a,M_a] = rat(R_a);
t_a_i = 0:((1/fs)/L_a):1/L_a;
x_a = cos(2*pi*f*t_a_i);
title('Signal Is Interpolated')
t_a_ii = 0:((1/fs)*M_a):1*M_a;
y_a = (x_a.*t_a_ii);
title('Signal Is Then Decimated')
sgtitle('Signal is resampled by Interpolation & then Decimation')
Kindly guide me in this.

Antworten (1)

AndresVar am 10 Feb. 2022
Regarding t: Your time intervals don't need to change length just the step size.
Regarding x_a: you need to keep only the samples from the orignal signal other samples should be zero
Regarding y_a: you can just use colon indexing to downsample ever other 'M_a' smaples
Also, typically you need to do low pass filtering. When you interpolate first upsample then low pass using the fs_original/2. When you decimate, low pass first with fs_final/2.
To get your new signals you can use loops or some built in indexing methods
t_original = 0:1/fs:1
t_interpol = 0:1/fs/N:1;
t_decimate = t_interpol(1:D:end) % OR 0:1/fs/N*D:1, note you downsample the upsampled signal
x_original = % evaluate at t_original
x_interpol = % you can evaluate at t_interpol, BUT you should only keep the samples at times in t_original
x_decimate = x_interpol(1:D:end) % look at x_interpol and keep samples at times t_decimate
% for x_interpol and x_decimate you can use loops, or check out
doc ismember % to see when t_interpol and t_original are the same ex. x2(~ismember(t2,t))=0
doc intersect % similar use to ismember ex. [~,idx] = intersect(t2,t)
% i recommend you compare your results to the built in methods
doc upsample
doc downsample
doc resample % note resample has special filter to remove artifacts




Community Treasure Hunt

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

Start Hunting!

Translated by