# How to use 'drawnow' to create an animated surface plot from audio measurements taken in a matrix of 10 x 10 microphone positions

31 views (last 30 days)
Peter Beringer on 30 Sep 2020
Commented: Peter Beringer on 6 Oct 2020
I am attempting to code for an animated surface plot of audio data.
The measurements were taken in ten steps of ten channels to create a 10 x 10 matrix of microphone measurement positions, and so 100 resultant recordings of equal length.
In principle, I want each value in a 10 x 10 x Z(ampliude) surface plot to be "fed" by data from an audio vector, whether sample by sample or at increments (every 100th sample, for example); whatever balances computational efficiency with satisfactory visualisation. So, position x = 1, y = 1 in the "new"/empty matrix (that will become the animated plot) will be "fed" values from its corresponding audio recording. Basically, the plot should redraw itself for each sample (or sample increment) of the 100 recordings.
So far, I think using the 'drawnow' function call is the way to go, but I'm not sure where to go from here. Do I need to create 100 'for' loops; one for each position in the animated matrix?
I'm at the very start of figuring this out, so have no code to show. I hope I've managed to explain what I'm trying to achieve. Thanks in advance for any help anyone may be able to provide.
Cheers!

KALYAN ACHARJYA on 30 Sep 2020
Edited: KALYAN ACHARJYA on 30 Sep 2020
for i=1:100
data=rand(10,10); % Choose your incoming audio data here
fig=surf(data);
grid on;
pause(0.1); % Animation speed hold time
clf(fig); % It clear the privious data and plot next in same figure
end
##### 2 CommentsShowHide 1 older comment
Peter Beringer on 6 Oct 2020
I really appreciate your answering my question. It ceratinly got me started on trying to get this working, but I'm having real problems calling my data into the matrix to be plotted. I need to create a 10 x 10 matrix of audio recordings where each position is fed its value sample by sample from the source audio data. I hope the attached code explains what I'm trying to achieve. I think I have the dimensions mixed up judging by the resulting plot. Any further help would be greatly appreciated. Please let me know if there's any other information you need; if you need some of the data with which it works; screenshots, etc. THank you very much in advance! :)
% Import data
Position01 = importdata('Position01.mat');
Position02 = importdata('Position02.mat');
Position03 = importdata('Position03.mat');
Position04 = importdata('Position04.mat');
Position05 = importdata('Position05.mat');
Position06 = importdata('Position06.mat');
Position07 = importdata('Position07.mat');
Position08 = importdata('Position08.mat');
Position09 = importdata('Position09.mat');
Position10 = importdata('Position10.mat');
% Get 10 out of 11 channels of audio from columns 1:10
% Should these channels of audio be turned into rows using:
% Pos01audiovectors = Position01.audio(:,1:10)': or something like that???
Pos01audiovectors = Position01.audio(:,1:10);
Pos02audiovectors = Position02.audio(:,1:10);
Pos03audiovectors = Position03.audio(:,1:10);
Pos04audiovectors = Position04.audio(:,1:10);
Pos05audiovectors = Position05.audio(:,1:10);
Pos06audiovectors = Position06.audio(:,1:10);
Pos07audiovectors = Position07.audio(:,1:10);
Pos08audiovectors = Position08.audio(:,1:10);
Pos09audiovectors = Position09.audio(:,1:10);
Pos10audiovectors = Position10.audio(:,1:10);
% Get vector/recording length
[numRows] = size(Position01.audio); % All recordings are the same length, data can be called from any
length = numRows(1, 1);
fs = Position01.fs; % Get sample rate from any of the audio datasets
for i = 1:length % Surf plot repopulating 'for' loop
% Build 10 x 10 matrix of audio signals with each recording of ten channels
% in ten positions. 100 recordings should "play" (i.e. feed data sample by
% sample into the surface plot as it redraws) from its respective position
% in the matrix of measurement microphones.
% audiomatrix = [Pos01audiovectors(i,:); ...
% Pos02audiovectors(i,:); Pos03audiovectors(i,:); ...
% Pos04audiovectors(i,:); Pos05audiovectors(i,:); Pos06audiovectors(i,:); Pos07audiovectors(i,:); ...
% Pos08audiovectors(i,:); Pos09audiovectors(i,:); Pos10audiovectors(i,:)];
audiomatrix = [Pos01audiovectors(i,:); Pos02audiovectors(i,:); Pos03audiovectors(i,:); Pos04audiovectors(i,:); Pos05audiovectors(i,:); Pos06audiovectors(i,:); Pos07audiovectors(i,:); Pos08audiovectors(i,:); Pos09audiovectors(i,:); Pos10audiovectors(i,:)];
audiomatrix = abs(audiomatrix); % This stops the "Z must be scalar or vector" error, but not sure why.
% audiomatrix = meshgrid(audiomatrix);
Figure = surf(audiomatrix);
grid on;
pause(1/fs); % Frame rate in seconds. (1/fs)
%drawnow % 'drawnow' or 'clf' best for this?
clf(Figure); % Clears the previous data and plot next in same figure
end

R2019b

### Community Treasure Hunt

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

Start Hunting!