How to shift a matrix by a specified number of points
4 views (last 30 days)
Show older comments
I am looking to align the highest peaks of two sets of 2500x1 matrix data to the same point number. My program obtains the sample number associated the highest amplitude peak of each data set and I can get the difference in data points between the two peaks. I need to either shift one of the data sets by the difference in data points or add zeros to one of the data points so that they align. Does anyone know how this can be done? Thank you
0 Comments
Answers (1)
dpb
on 22 May 2016
Edited: dpb
on 22 May 2016
'Pends on what you want to happen w/ the rest of the data...it's trivial enough to simply augment a vector with zeros on either end but you might want to read
doc circshift
ADDENDUM
Well, if you have the two points of interest, then pick one as the reference; I'll presume to move the one with the rightmost peak and, for convenience in addressing the two that they're in a 2D array by column.
Given then nChMax is the corresponding 2-vector of the locations, to align the two would be
[~,idx]=max(nChMax); % determine which is the rightmost peak of the two
nZ=abs(diff(nChMax)); % the offset between the two in absolute mag
s(:,idx)=[s(nChMx(idx)-nZ:end,idx); zeros(nZ,1)]); % shift up by nZ and augment
This "throws away" the first of the shifted signal maintaining the same overall length. Alternatively, you can also augment the other with nZ at the front and keep the full length of signal but other than for visual purposes it won't matter as there's nothing matching when you get ready to do the calculations on a pointwise basis.
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!