Fit a signal into smaller window while maintaiing proportion
1 view (last 30 days)
Show older comments
I have a random signal of 2048 points. There are several peaks spread out (maybe 10). The rest are all zeros or have very low amplitude.
I want to squeeze this signal into a 512 signal window maintaining all the peaks and data with less of the zeros or low amplitude data.
How can I do this in Matlab?
0 Comments
Accepted Answer
Image Analyst
on 16 Mar 2013
You can sort and then keep just the 512 with the highest values:
data = rand(1, 2048);
subplot(2, 1, 1);
plot(data);
% Sort the data
[sortedData, sortIndices] = sort(data, 'descend');
% Find the first 512 - they will be the greatest value.
elementsToKeep = sortIndices(1:512);
% Get them back in their original order:
elementsToKeep = sort(elementsToKeep);
% Extract those elements
extractedData = data(elementsToKeep);
subplot(2, 1, 2);
plot(extractedData);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
That's one way to do it.
More Answers (0)
See Also
Categories
Find more on Logical 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!