Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create swa_Project3DSpeed.m #53

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions SW/swa_Project3DSpeed.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% * Program: SW
% * Author: Anna Castelnovo & Matteo Zago
% * Created: 2017.09.21, 14:36
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function [twr, speed] = swa_Project3DSpeed (Info, sw, scaleFactor, img)

if nargin < 4
img = 1;
end

% assegna nome a variabili
% x, y ,z: coordinate elettrodi reali
% tw: coordinate travelling wave su griglia
% twr: coordinate travelling wave reali
y = [Info.Electrodes.X];
x = [Info.Electrodes.Y];
z = [Info.Electrodes.Z];

XYZ = [x', y', z'] * [scaleFactor 0 0; 0 scaleFactor 0; 0 0 scaleFactor];
x = XYZ(:,1);
y = XYZ(:,2);
z = XYZ(:,3);

% eloc = swa_add2dlocations(Info.Electrodes);

% estrae una travelling wave
tw = sw.Travelling_Streams{1}';

% trasformazione
a = min(x);
x1 = x - a;
b = max(x1);

c = min(y);
y1 = y - c;
d = max(y1);

twr(:,1) = (tw(:,1) * b)/(40-1) -1 + a;
twr(:,2) = (tw(:,2) * d)/(40-1) -1 + c;

% ricavo terza dimensione reale
F = scatteredInterpolant(x, y, z);
twr(:,3) = F(twr(:,1), twr(:,2));

% calcolo velocita (modulo vettore spostam diviso delay)
speed = sqrt(sum( twr.^2, 2)) ./ sw.Stream_Travelling_Delay ;

% grafico (opzionale)
if img
suptitle('Botto');
subplot(121);
plot3(x,y,z,'*k'); hold on;
speedRange = max(speed) - min(speed);
speedColor = abs([speed-min(speed) zeros(size(speed)) zeros(size(speed))])./speedRange;
for k = 1 : length(speed)
twp = plot3(twr(k,1), twr(k,2), twr(k,3));
set(twp, 'color', speedColor(k, :), 'marker', 'o');
end
title('3D real view');

subplot(122);
pcolor(sw.Travelling_DelayMap); hold on; grid on;
plot([Info.Electrodes.x], [Info.Electrodes.y], '*k');
for k = 1 : length(speed)
twp = plot(tw(k,1), tw(k,2));
set(twp, 'color', speedColor(k, :), 'marker', 'o');
end
colorbar;
title('2D grid view');
end

%end