Seeking documentat​ion/links/​suggestion​s/help on implementing data "smoothing" with 'interp2' in animated surf plot. Is it even possible?

2 次查看(过去 30 天)
Hi,
I have been using the 'interp2' function call to smooth data displayed on static surf (and trisurf) plots with good success with the following code (edited for posting and random test data included) ...
%% GRAPHICS SMOOTHING/INTERPOLATED PLOT TEST SCRIPT
Z = rand(10);
[X Y] = meshgrid(1:10,1:10);
surf(X,Y,Z);
%T = delaunay(X,Y);
[Xx,Yy] = meshgrid(1:0.1:10,1:0.1:10);
%Tt = delaunay(Xx,Yy);
Zz = interp2(X,Y,Z,Xx,Yy,'spline');
figure;
surf(Xx,Yy,Zz, 'LineWidth', 0.001);
title('L_{TEST} (RANDOM) - Reverberation Chamber');
xlabel('Distance from Focus [mm]')
%ylabel('Distance from Focus [mm]')
zlabel('L_{MAX} [dB]')
xlim([1 10])
ylim([1 10])
xticks(1:1:10);
yticks(1:1:10);
xticklabels([-500 -400 -300 -200 -100 100 200 300 400 500]);
yticklabels([-500 -400 -300 -200 -100 100 200 300 400 500]);
I'm wondering if there's a way to implement this kind of 'interp2' "smoothing" in an animated surf plot. I've tried adding the interp2 line to the concatenation and permute stage outside the 'for' loop, and also inside the loop (as well as some almost illogical, desperate attempts). Best I achieved in one of those desperate attempts was to smooth the first Z matrix called (sample 1 of the data indexed from the 100 microphone positions), but I foolishly didn't save the code at that stage; it's the warmest I've got. I've been successfully generating animated plots and writing MP4 video with the code below (edited for posting and lines for generating random test data included if anyone wants to run it) ...
%% PLOT ANIMATION and VIDEO WRITING
Fs = 48000; % Audio sample rate
% Test data ONLY (reflects format of real data; 11 channels, but only ten need plotting)
a = -0.3;
b = 0.3;
Position01 = a + (b-a) .* rand(48000,11);
Position02 = a + (b-a) .* rand(48000,11);
Position03 = a + (b-a) .* rand(48000,11);
Position04 = a + (b-a) .* rand(48000,11);
Position05 = a + (b-a) .* rand(48000,11);
Position06 = a + (b-a) .* rand(48000,11);
Position07 = a + (b-a) .* rand(48000,11);
Position08 = a + (b-a) .* rand(48000,11);
Position09 = a + (b-a) .* rand(48000,11);
Position10 = a + (b-a) .* rand(48000,11);
[NumSamples] = size(Position01(:,1)); % Get length of audio vectors from any; all measurements are the same length.
NumSamples = NumSamples(1,1);
% VideoObj = VideoWriter('AnimatedPlotNEWTEST.avi'); % Create video object
% VideoObj.FrameRate = 30; % Set frame rate
% open(VideoObj); % Open video object
Video = VideoWriter('AnimatedPlot02','MPEG-4');
open(Video);
[X, Y] = meshgrid(1:10,1:10);
%T = delaunay(X, Y);
% make the plot matrix outside of the loop (you need to use 3 dimensions)
PlotMatrix = permute(cat(3,Position01(:,1:10), Position02(:,1:10), Position03(:,1:10), Position04(:,1:10), Position05(:,1:10),Position06(:,1:10), Position07(:,1:10), Position08(:,1:10), Position09(:,1:10), Position10(:,1:10)),[2,3,1]);
figure1 = figure; % explicitly create a new figure
grid on
h = surf(X,Y,PlotMatrix(:,:,1), 'FaceAlpha', '0.5');
axis manual
zlim([-0.3 0.3])
xlabel('Distance from Focus [mm]')
%ylabel('Distance [mm]')
zlabel('Normalised Amplitude')
xlim([1 10]);
ylim([1 10]);
xticks(1:1:10);
yticks(1:1:10);
zticks(-0.3:0.1:0.3);
xticklabels([-500 -400 -300 -200 -100 100 200 300 400 500]);
yticklabels([-500 -400 -300 -200 -100 100 200 300 400 500]);
[PeakValue PeakIndex] = max(Position01(:,11));
StartIndex = PeakIndex - (0.001 * Fs);
FinishIndex = PeakIndex + (0.001 * Fs);
for i = StartIndex : FinishIndex % Length of audio file in samples (time on Z axis).
data = PlotMatrix(:,:,i);
h.CData = data;
h.ZData = data;
str = ['Time [ms]: ', num2str(i * (0.001/Fs))];
title(str)
drawnow
frame = getframe(gcf);
writeVideo(Video,frame);
end
close(Video);
Would be greatly appreciative for any help/suggestions, or direction to relevant documentation or question threads, etc., my searching hasn't found anything dealing with this specifically (or related to it closely enough to adapt), but perhaps I'm using the wrong search terms (which I've found to be the case sometimes). Though, I'm half expecting the answer would have been staring me in the face all along, but I think I need another pair of eyes to be able to see it. Hehe.
(Yes, the time counter is wrong, but my primary school maths really sucks. Haha :/ )
Thanks!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by