Downsample and reconstruct a subsection of a vector?

2 views (last 30 days)
Ben
Ben on 18 Jan 2023
Edited: dpb on 19 Jan 2023
Hi all,
I have vectors of lonitude and latitude (and other equally sized metadata vectors) from some geospatial data over a region at a uniform resolution. Within this I have defined an area of interest using a bounding box (geo.FineSamplingBox) defining top left and bottom left coordinates of the area of interest. I have used this to index the points inside and outside this box. The points inside the box I would like to retain the original sampling rate, and the points outside the box I would like to downsample by a factor of 10 (geo.SS_Factor).
I have managed to extract the respective points, but I am unsure how to re-insert them into the original matrix without losing the original order. I have attempted to solve it by appending the fine matrix with the coarse matrix and then sorting them but I am not sure the best way of doing this.
Any thoughts, answers or comments would be greatly appreciated, thank you! Apologies I cannot provide any data - the fine sampled vectors are 1888x1, and the coarse sampled vectors are 1370x1.
Code extract below:
%% ADDED - APPLY COARSE/FINE SUBSAMPLING BASED ON BOUNDING BOX
if geo.BB ==1
FineSampLon = loadedData.Lon > geo.FineSamplingBox(1) & loadedData.Lon < geo.FineSamplingBox(3);
FineSampLat = loadedData.Lat < geo.FineSamplingBox(2) & loadedData.Lat > geo.FineSamplingBox(4);
FineSamp = FineSampLon & FineSampLat;
CoarseSamp = find(loadedData.Lon < geo.FineSamplingBox(1) | loadedData.Lon > geo.FineSamplingBox(3) | loadedData.Lat > geo.FineSamplingBox(2) | loadedData.Lat < geo.FineSamplingBox(4));
if sum(CoarseSamp)>0
PhaseCoarse= downsample(loadedData.Phase(CoarseSamp),geo.SS_Factor);
LatCoarse = downsample(loadedData.Lat(CoarseSamp),geo.SS_Factor);
LonCoarse = downsample(loadedData.Lon(CoarseSamp),geo.SS_Factor);
HeadCoarse = downsample(loadedData.Heading(CoarseSamp),geo.SS_Factor);
IncCoarse = downsample(loadedData.Inc(CoarseSamp),geo.SS_Factor);
PhaseFine = loadedData.Phase(FineSamp);
LatFine = loadedData.Lat(FineSamp);
LonFine = loadedData.Lon(FineSamp);
HeadFine = loadedData.Heading(FineSamp);
IncFine = loadedData.Inc(FineSamp);
end
end
%Reorder lat and lon matrix and apply that to the other matricies?
%Find when lat is above or below the thresholds of the bounding box and
%add coarse sampled data back in??

Answers (1)

dpb
dpb on 18 Jan 2023
Edited: dpb on 19 Jan 2023
If they're just vectors, I think the simplest is probably the best and likely the quickest...
LO=geo.FineSamplingBox(1); HI=geo.FineSamplingBox(3); % convenient shorthand names
N=geo.SS_Factor;
dataPrime=[decimate(data(:,1:LO),N) data(:,LO+1:HI-1) decimate(data(:,HI:end),N)]; % columns of 2D
dataPrime=[decimate(dataPrime(1:LO,:),N) dataPrime(LO+1:HI-1,:) decimate(dataPrime(HI:end,:),N)]; % rows of 2D
I didn't try to construct it, an alternative would be to create a 2D logical addressing array that matches the areas and uses it as a logical address expression.

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!