How to change the timescale of a signal?
Show older comments
I was wondering how one would change the time-scale of a signal. In particular I have a stimulus that changes every 0.62 ms or so, and either has a value of +1 or -1. I need it so that I have the value of the stimulus at each ms. I have tried various re-sampling/up-sampling functions but I have had limited success so far. Thanks.
Answers (1)
Fangjun Jiang
on 7 Dec 2011
resample() can be used sometimes. But since your signal value is either +1 or -1, I guess you might want to resample it using the last known value.
%%Original data
t=0.62*(0:9);
y=round(rand(10,1))*2-1;
figure(1);
stairs(t,y);
ylim([-1.5 1.5]);
% New data
T=0:0.001:t(end);
ind=bsxfun(@le,t',T);
Y=y(sum(ind));
figure(2);
plot(T,Y,'r+');
ylim([-1.5 1.5]);
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!