Resampling a signal without using built-in command
31 views (last 30 days)
Show older comments
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);
figure;
stem(0:200,x(1:201),'LineWidth',1)
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);
figure;
subplot(2,1,1)
stem(0:200,x_a(1:201),'LineWidth',1)
title('Signal Is Interpolated')
t_a_ii = 0:((1/fs)*M_a):1*M_a;
y_a = (x_a.*t_a_ii);
subplot(2,1,2)
stem(0:200,y_a(1:201),LineWidth=1)
title('Signal Is Then Decimated')
sgtitle('Signal is resampled by Interpolation & then Decimation')
Kindly guide me in this.
0 Comments
Answers (1)
AndresVar
on 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
[N,D]=rat(1.66)
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
0 Comments
See Also
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!