Convert existing MATLAB script into GUI using app designer
44 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have written a MATLAB script and I want to convert my existing code to a GUI using app designer. The code is off gunshot localization with 7 microphones array. I am new at using MATLAB and app designer. so please help me to convert my script into GUI using App designer. It will be appreciated.
%% time difference
clc;
clear;
tic;
warning off;
%% velocity of sound
c= 343;
a=1;
%% actual source location
%r;
%Theta;
%phi;
%% microphone positions
%M0 = MicLoc(0,0,0);
%M1 = MicLoc(1,0,0);
%M2 = MicLoc(0,1,0);
%M3 = MicLoc(-1,0,0);
%M4 = MicLoc(0,-1,0);
%M5 = MicLoc(0,0,1);
%M6 = MicLoc(0,0,-1);
fs=1e3;
dt=1/fs;
m0=audioread("gun-gunshot-01.wav"); %audio signal given to the reference microphone
m1=delayseq(m0,2,fs);
lx=length(m0);
lshifted_data=length(m1); %2 sec delayed audio signal given to 1st microphone
samples=1:min(lx,lshifted_data);
figure;
plot(m0(samples));
title('refrence signal');
figure;plot(m1(samples));
title('Signal given to m1');
[C,lag]=xcorr(m0(samples),m1(samples));
[~,I]=max(abs(C));
lagDiff=abs(lag(I));
tau10=abs(lagDiff*dt);
A='the time difference between refrence and first microphone signal is';
disp(A);
disp(tau10);
m2=delayseq(m0,4,fs); %4 sec delayed audio signal given to 2nd microphone
lx=length(m0);
lshifted_data1=length(m2);
samples1=1:min(lx,lshifted_data1);
figure;plot(m2(samples1));
title('Signal given to m2');
[c1,lag1]=xcorr(m0(samples1),m2(samples1));
[~,I]=max(abs(c1));
lagDiff1=abs(lag(I));
tau20=abs(lagDiff1*dt);
b='the time difference between refrence and second microphone signal is';
disp(b);
disp(tau20);
m3=delayseq(m0,6,fs); %6 sec delayed audio signal given to 3rd microphone
lx=length(m0);
lshifted_data2=length(m3);
samples2=1:min(lx,lshifted_data2);
figure;plot(m3(samples2));
title('Signal given to m3');
[c2,lag2]=xcorr(m0(samples2),m3(samples2));
[~,I]=max(abs(c2));
lagDiff2=abs(lag(I));
tau30=abs(lagDiff2*dt);
d='the time difference between refrence and third microphone signal is';
disp(d);
disp(tau30);
m4=delayseq(m0,8,fs); %8 sec delayed audio signal given to 4rth microphone
lx=length(m0);
lshifted_data3=length(m4);
samples3=1:min(lx,lshifted_data3);
figure;plot(m4(samples3));
title('Signal given to m4');
[c3,lag3]=xcorr(m0(samples3),m4(samples3));
[~,I]=max(abs(c3));
lagDiff3=abs(lag(I));
tau40=abs(lagDiff3*dt);
e='the time difference between refrence and fourth microphone signal is';
disp(e);
disp(tau40);
m5=delayseq(m0,10,fs); %10 sec delayed audio signal given to 4rth microphone
lx=length(m0);
lshifted_data4=length(m5);
samples4=1:min(lx,lshifted_data4);
figure;plot(m5(samples4));
title('Signal given to m5');
[c4,lag4]=xcorr(m0(samples4),m5(samples4));
[~,I]=max(abs(c4));
lagDiff4=abs(lag4(I));
tau50=abs(lagDiff4*dt);
f='the time difference between refrence and fifth microphone signal is';
disp(f);
disp(tau50);
m6=delayseq(m0,12,fs); %12 sec delayed audio signal given to 6th microphone
lx=length(m0);
lshifted_data5=length(m6);
samples5=1:min(lx,lshifted_data5);
figure;plot(m6(samples5));
title('Signal given to m6');
[c5,lag5]=xcorr(m0(samples5),m6(samples5));
[~,I]=max(abs(c5));
lagDiff5=abs(lag5(I));
tau60=abs(lagDiff5*dt);
f='the time difference between refrence and sixth microphone signal is';
disp(f);
disp(tau60);
%% Judgement criterion of quadrant of sound source
if (tau30> tau10 && tau40 > tau20 && tau60 > tau50)
disp('sound source is in first quadrant');
elseif (tau30 < tau10 && tau40 > tau20 && tau60 > tau50)
disp('sound source is in second quadrant');
elseif (tau30 < tau10 && tau40 < tau20 && tau60 > tau50)
disp('sound source is in third quadrant');
elseif (tau30 > tau10 && tau40 < tau20 && tau60 > tau50)
disp('sound source is in fourth quadrant');
elseif (tau30 > tau10 && tau40 > tau20 && tau60 < tau50)
disp('sound source is in fifth quadrant');
elseif (tau30 < tau10 && tau40 > tau20 && tau60 < tau50)
disp('sound source is in sixth quadrant');
elseif (tau30 < tau10 && tau40 < tau20 && tau60 < tau50)
disp('sound source is in seven quadrant');
elseif (tau30 > tau10 && tau40 < tau20 && tau60 < tau50)
disp('sound source is in eight quadrant');
end
%% array localization in XOY plane
%x0; %Rectangular coordinates in XOY plane
%y0;
%r0; % spherical coordinates in XOY Plane
%Theta0;
%phi0;
m0 = tau10 + tau20 + tau30 + tau40;
n0 = (tau10^2) + (tau20^2) + (tau30^2)+ (tau40^2);
x0 = (tau30 - tau10)*(4*(a^2) - (c^2)*n0)/(4*a*m0);
y0 = (tau40 - tau20)*(4*(a^2) - (c^2)*n0)/(4*a*m0);
r0 = abs((4*(a^2) - (c^2)*n0)/(2*m0*c));
Theta0 = angle (acos (c*(sqrt(((tau30 - tau10)^2) + (( tau40 - tau20)^2))))/(2*a));
phi0 = angle(atan ((tau40 - tau20)/(tau30 - tau10)));
disp('the value of spherical coordinates in XOY plane in ');
disp('the value of phi0 is')
disp(phi0);
disp('the value of theta0 is')
disp(Theta0);
%% localization from XOZ plane
%x1; % rectangular coordinates in XOZ plane
%z1;
%r1; % spherical coordinates in YOZ plane
%Theta1;
%phi1;
s=1;
m1 = tau10 + tau30 + tau50 + tau60;
n1 = (tau10^2) + (tau30^2) + (tau50^2) + (tau60^2);
x1 = (tau30 - tau10)*(4*(a^2) - (c^2)*n1)/(4*a*m1);
z1 = (tau60 - tau50)*(4*(a^2) - (c^2)*n1)/(4*a*m1);
r1 = abs((4*(a^2) - (c^2)*n1)/(2*m1*c));
Theta1 = angle(asin (c*(tau60 - tau50))/(2*a));
phi1 = angle(acos (c*(tau30 - tau10))/(sqrt(4*(a^2) - (c*(tau60 - tau50))^2)));
disp('the value of spherical coordinates in XOZ plane in ');
disp('the value of phi in xoz plane ');
disp(phi1);
disp('the value of theta in xoz plane is');
disp(Theta1);
%% localization in YOZ plane
% rectangular coordinates in YOZ plane
%y2;
%z2;
% spherical coordinates in YOZ plane
%r2;
%Theta2;
%phi2;
m2 = tau20 + tau40 + tau50 + tau60;
n2 = (tau20^2) + (tau40^2) + (tau50^2) + (tau60^2);
y2 = (tau40 - tau20)*(4*(a^2) - (c^2)*n2)/(4*a*m2);
z2 = (tau60 - tau50)*(4*(a^2) - (c^2)*n2)/(4*a*m2);
r2 = abs((4*(a^2) - (c^2)*n2)/(2*m2*c));
Theta2 = angle(asin (c*(tau60 - tau50))/(2*a));
phi2 = angle(asin (c*(tau40 - tau20))/(sqrt(4*(a^2) - (c*(tau60 - tau50))^2)));
disp('the value of spherical coordinates in XOZ plane in ');
disp("the value of theta in yoz plane is")
disp(Theta2);
disp("the value of phi in yoz plane is ")
disp(phi2)
%% fusion algorithm
k2 = sin(Theta0);
k1 = 1 - k2;
k4 = cos(Theta2);
k3 = 1 - k4;
r = abs((k3*((k2*r0) + (k1*r1))) + (k4*r2));
Theta =k3*(k2*Theta0 + k1*Theta1) + k4*Theta2;
phi = ((k3*(k2*phi0) + (k1*phi1)) + (k4*phi2));
theta_degree=Theta*180/pi;
phi_degree=abs(phi*180/pi);
disp('the value of spherical coordinates of the actual sound source')
disp("the value of elevation angle is")
disp(theta_degree);
disp("the value of horizontal angle is")
disp(phi_degree);
0 Kommentare
Antworten (1)
Rik
am 6 Mai 2022
The first step is to convert your code to a function. Then you can design your GUI to gather the necessary inputs for that function, that is after all the point of a GUI.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!