How can I turn time series data into a spatial map?

조회 수: 13 (최근 30일)
Motivation: I am building a microscope to scan a laser across patterned surfaces to map the surface. The most intuitive method for this is to step from one point to the next and collect data at each fixed point. However, this is very slow. The fastest method is to use continuous motion of the laser spot to create a time series of data that has associated X,Y points at each time. However, real experimental equipment can't follow an arbitrary path due to finite accelerations (i.e., PID settings). This means that a raster map (see blue line in plots) will have errors in the true position compared to the target position when rastering quickly (see red line in plots). This in itself is not a problem as long as the visualized data accounts for the true position of the measured data.
Problem: The problem is visualization of the resulting "map". Specifically, time series data can't be easily converted into a 2D matrix that can be plotted in the "surf" function to visualize the surface map/image. This is even more complicated when using non-rastering mapping methods such as Lissajous motion.
Need:
  1. A surface plotting function that accepts vectors for X,Y and Z instead of 2D arrays. Similar to "plot3" but that yields a "continuous surface like "surf". OR
  2. A way to sort/rearrange time series data into a 2D matrix that can be used in "surf" or other similar surface plotting function.
Data Included:
  1. Target points vs. time
  2. Measured position vs. time

채택된 답변

Christopher Saltonstall
Christopher Saltonstall 2022년 7월 14일
편집: Christopher Saltonstall 2022년 7월 14일
Answer: Use "griddata" and "meshgrid" functions as shown below.
clear
close all
%% Get experimental data
path = 'C:\';
filename = 'data.mat';
load(fullfile(path,filename));
%down sample factor
fsample = 30;
%number of x-mesh points
nx = 100;
%number of y-mesh points
ny = 100;
% time vector (s)
t = data.measure.t;
t = downsample(t,fsample);
% x-position vector (um)
x = data.measure.x;
x = downsample(x,fsample);
% y-position vector (um)
y = data.measure.y;
y = downsample(y,fsample);
%% generate z-data using experimental data points for visual example
% x-wavelength
Lx = 10;
% y-wavelength
Ly = 6;
% z-points for heat map
z = sin(2*pi/Lx*x) + cos(2*pi/Ly*y);
%% Choose mesh points
xmin = min(x);
xmax = max(x);
ymin = min(y);
ymax = max(y);
%sample points for mesh
xSample = linspace(xmin,xmax,nx);
ySample = linspace(ymin,ymax,ny);
%2D array of x and y points
[xMesh, yMesh] = meshgrid(xSample,ySample);
%interpolate z-data using mesh points
zMesh = griddata(x,y,z,xMesh,yMesh,'cubic');
%% Plot that ish
figure(1)
scatter3(x,y,z,5,z)
colormap(gca,"winter")
xlabel('x-Position (um)')
ylabel('y-Position (um)')
zlabel('Intensity (a.u.)')
title('3D Scatter Plot')
figure(2)
mesh(xMesh,yMesh,zMesh)
axis tight;
hold on
plot3(x,y,z,'.r','MarkerSize',5)
hold on
xlabel('x-Position (um)')
ylabel('y-Position (um)')
zlabel('Intensity (a.u.)')
title('Mesh + Scatter Plot')
figure(3)
h = surf(xMesh,yMesh,zMesh);
shading interp
set(h,'LineStyle','none')
xlabel('x-Position (um)')
ylabel('y-Position (um)')
zlabel('Intensity (a.u.)')
title('Surface Plot')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by