HELP REQUIRED TO GET A LEGACY PROGRAM RUNNING
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Andy
el 31 de En. de 2024
Comentada: Rena Berman
el 15 de Mzo. de 2024
Hi,
A quick update: thanks to the responses on here, I realise that I need the GUI figure to use this code, for which I don't have. However, I do have a picture of what it should look like (see below). Is there any way of 'reverse engineering' the GUI figure from the code? Or is it a case of stating from scatch?
Best regards,
Andy
function varargout = TimeReversalMirror_11(varargin)
%Time Reversal Mirror Version 1.1
%Spring 2004
%Electromagnetic simulation to test the ideas behind time reversal methods for communications.
%The program is complete graphics based and allows users to control many different aspects of the program.
%The sizae of the simulation, the placement of the recevier and array can be defined. Several preset
%enviroments can be chosen, or the user can input their own enviroment aby hand. The user can test
%three types of digital modulation, ASK, PSK, and FSK. The full signal constellation is trasnmitted to the
%array. The array reversed the signal in time and stores it as the new prototype signal constellation.
%The user can then transmit the prototype signals back to the receiver through the same enviroment.
%Throughout the process, the electric field intensity is plotted on a log scale. The entire process can
%be recorded and then converted to an AVI file. The EM simulation is performed using the FDTD algorithm
%With PML boundary conditions that were coded by Mary Alt.
%---------------------------------------GUI-------------------------------------------------------------
% TIMEREVERSALMIRROR_11 Application M-file for TimeReversalMirror_11.fig
% FIG = TIMEREVERSALMIRROR_11 launch TimeReversalMirror_11 GUI.
% TIMEREVERSALMIRROR_11('callback_name', ...) invoke the named callback.
% Last Modified by GUIDE v2.0 12-Apr-2004 18:55:29
if nargin == 0 % LAUNCH GUI
fig = openfig(TimeReversalMirror_11);
% Generate a structure of handles to pass to callbacks, and store it.
handles = guihandles(fig);
guidata(fig, handles);
if nargout > 0
varargout{1} = fig;
end
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
catch
disp(lasterr);
end
end
%| ABOUT CALLBACKS:
%| GUIDE automatically appends subfunction prototypes to this file, and
%| sets objects' callback properties to call them through the FEVAL
%| switchyard above. This comment describes that mechanism.
%|
%| Each callback subfunction declaration has the following form:
%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)
%|
%| The subfunction name is composed using the object's Tag and the
%| callback type separated by '_', e.g. 'slider2_Callback',
%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.
%|
%| H is the callback object's handle (obtained using GCBO).
%|
%| EVENTDATA is empty, but reserved for future use.
%|
%| HANDLES is a structure containing handles of components in GUI using
%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This
%| structure is created at GUI startup using GUIHANDLES and stored in
%| the figure's application data using GUIDATA. A copy of the structure
%| is passed to each callback. You can store additional information in
%| this structure at GUI startup, and you can change the structure
%| during callbacks. Call guidata(h, handles) after changing your
%| copy to replace the stored original so that subsequent callbacks see
%| the updates. Type "help guihandles" and "help guidata" for more
%| information.
%|
%| VARARGIN contains any extra arguments you have passed to the
%| callback. Specify the extra arguments by editing the callback
%| property in the inspector. By default, GUIDE sets the property to:
%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))
%| Add any extra arguments after the last argument, before the final
%| closing parenthesis.
%=======================VARIABLES====================================
% --------------------------X Dimension---------------------------
function varargout = X_Callback(h, eventdata, handles, varargin)
handles.x= str2double(get(h,'string'));
guidata(h,handles);
% --------------------------Y Dimension--------------------------
function varargout = Y_Callback(h, eventdata, handles, varargin)
handles.y = str2double(get(h,'string'));
guidata(h,handles);
% -------------------------Recevier in X---------------------------
function varargout = receiver_Callback(h, eventdata, handles, varargin)
handles.receiver=str2double(get(h,'string'));
guidata(h,handles);
% ---------------------Location of first array element---------
function varargout = arraystart_Callback(h, eventdata, handles, varargin)
handles.arraystart = str2double(get(h,'string'));
guidata(h,handles);
% ---------------------# of elements in the array---------------
function varargout = elements_Callback(h, eventdata, handles, varargin)
handles.elements = str2double(get(h,'string'));
guidata(h,handles);
% ----------------------Sapcing between arrayelements------
function varargout = spacing_Callback(h, eventdata, handles, varargin)
handles.arrayspace = str2double(get(h,'string'));
guidata(h,handles);
% ------------------distance between array and recevier-----
function varargout = distance_Callback(h, eventdata, handles, varargin)
handles.depth = str2double(get(h,'string'));
guidata(h,handles);
% ------------------offset from x=0 and recevier-----------
function varargout = offset_Callback(h, eventdata, handles, varargin)
handles.offset = str2double(get(h,'string'));
guidata(h,handles);
% ---------------------Shape of hte array----------------------
function varargout = shape_Callback(h, eventdata, handles, varargin)
handles.shape=get(h,'value');
guidata(h,handles);
% --------------------environment--------------------------
function varargout = random_media_Callback(h, eventdata, handles, varargin)
handles.media=get(h,'value');
guidata(h,handles);
% -------------------movie name------------------------------
function varargout = movie_name_Callback(h, eventdata, handles, varargin)
handles.movie_name=get(h,'string');
guidata(h,handles);
% ---------------------convert movie to AVI----------------------
function varargout = avi_Callback(h, eventdata, handles, varargin)
frames1=handles.frames1;
frames2=handles.frames2;
movie_name=handles.movie_name;
movie2avi([frames1 frames2],movie_name)
%==========================PROCESSING================================
% ------------------------------First Transmission---------------------
function varargout = ping_Callback(h, eventdata, handles, varargin)
X=handles.x;
Y=handles.y;
depth=handles.depth;
offset=handles.offset;
arraystart=handles.arraystart;
arrayspace=handles.arrayspace;
elements=handles.elements;
receiver=handles.receiver;
media=handles.media;
shape=handles.shape;
if media==5
er=handles.er;
else
er=0;
end
fc=1E9;
c=3E8;
lambda=c/fc;
%length in meters of each cell
del=lambda/10;
dt=(1/(c*sqrt((1/del)^2+(1/del)^2)));
Fs=1/dt;
handles.del=del;
ping_signal=handles.send_data;
%plot the signal to transmit
axes(handles.axes4);
plot(ping_signal);
set(handles.signal,'string','Pinging Signal sent from the Receiver to the Array');
media=handles.media;
%Transmit the original signal from the recevier
axes(handles.axes1)
[E1, V1, frames1] = fdtd05(X, Y, del, ping_signal, receiver, 1, elements, arraystart, arrayspace, depth, offset,media,er);
handles.E1=E1;
handles.V1=V1;
handles.frames1=frames1;
set(handles.signal,'string','Recorded Ping at the Array Elements')
axes(handles.axes4)
plot(1:length(V1),V1)
guidata(h,handles);
% ----------------------------Time Reversal-------------------
function varargout = TR_Callback(h, eventdata, handles, varargin)
elements=handles.elements;
V1=handles.V1;
send_data=handles.send_data;
depth=handles.depth;
arrayspace=handles.arrayspace;
%find the delay amount for each array element
for k=1:elements
delay(k)=min(find(abs(V1(k,:))>1E-3));
end
%d_hat represents the delay from the start of the simulation to the time when the first element records a signal
d_hat=min(delay);
%determines the delay for each signal relative to the first one
delay=delay-d_hat;
stop=d_hat+120;
if stop>length(V1)
stop=length(V1);
end
%create the signal to send to the receiver
for k=1:elements
temp2(k,:)=[ zeros(1,round(2*depth)) V1(k,d_hat:stop)];
end
%Flip the signal and normalize it to 1
send=fliplr(temp2/max(max(abs(temp2))));
handles.send=send;
axes(handles.axes4)
plot(1:length(send),send)
set(handles.signal,'string','Time Reversed signal to be sent');
guidata(h,handles)
% -----------------------------Perform the modulation----------------------------------
function varargout = modulation_Callback(h, eventdata, handles, varargin)
depth=handles.depth;
fc=1E9;
c=3E8;
lambda=c/fc;
%length in meters of each cell
del=lambda/10;
dt=(1/(c*sqrt((1/del)^2+(1/del)^2)));
Fs=1/dt;
t=0:1/Fs:29/Fs-1/Fs;
%Regular Sine wave without modulation
source=sin(2*pi*fc*t);
ping_signal=[source];
value=get(h,'value');
data=[1 0];
if value==1 % FSK
send_data=dmod(data,fc,Fs/30,Fs,'fsk');
set(handles.signal,'string','1 0 FSK Digitally Modulated Bits')
elseif value==2 % ASK
send_data=dmod(data,fc,Fs/30,Fs,'ask');
set(handles.signal,'string','1 0 ASK Digitally Modulated Bits')
elseif value==3 %PSK
send_data=dmod(data,fc,Fs/30,Fs,'psk');
set(handles.signal,'string','1 0 PSK Digitally Modulated Bits')
elseif value==4 %No Modulation
send_data=ping_signal;
set(handles.signal,'string','The Original Pining Signal (No Modulation)')
end
%Form the original signal to be trasnmitted
send_data=[send_data zeros(1,round(2*depth))];
handles.send_data=send_data;
axes(handles.axes4)
plot(send_data)
guidata(h,handles);
% -------------------------Re-Trasnmit the Time Revered Signal------------------------------
function varargout = transmit_Callback(h, eventdata, handles, varargin)
X=handles.x;
Y=handles.y;
del=handles.del;
send=handles.send;
arraystart=handles.arraystart;
arrayspace=handles.arrayspace;
receiver=handles.receiver;
depth=handles.depth;
offset=handles.offset;
media=handles.media;
shape=handles.shape;
frames1=handles.frames1;
if media==5
er=handles.er;
else
er=0;
end
%Transmit
axes(handles.axes1);
[E2, V2, frames2] = fdtd05(X, Y, del,send, arraystart, arrayspace, 1, receiver, 1, -depth, offset+depth,media,er);
handles.frames2=frames2;
maximum=length(frames1)+length(frames2);
slider_step(1) = 1/(maximum-1);
slider_step(2) = 1/(maximum-1);
set(handles.slider1,'sliderstep',slider_step,'max',maximum,'min',1,'Value',1)
%Plot the Recevied signal
set(handles.signal,'string','The Received Signal from the Array')
axes(handles.axes4)
plot(V2)
guidata(h,handles)
%-----------------------Show the Simulation Set-Up------------------------------------
function varargout=array_setup_Callback(h, eventdata, handles, varargin)
X=handles.x;
Y=handles.y;
receiver=handles.receiver;
elements=handles.elements;
arraystart=handles.arraystart;
arrayspace=handles.arrayspace;
depth=handles.depth;
offset=handles.offset;
media=handles.media;
shape=handles.shape;
%Determine where the array is?
center=arraystart+((elements-1)/2)*arrayspace;
edge1=arraystart;
edge2=arraystart+(elements-1)*arrayspace;
length=(offset+depth);
left=offset;
right=offset+depth;
%Define the realtive permativitty of each point in the simulation
er=ones(X,Y);
pointsy1=round((Y-3)*[ 0.7271 0.3093 0.8385 0.5681 0.3704 0.7027 0.5466 0.4449 0.6946
0.6213])+3;
pointsy2=round((Y-3)*[ 0.1365 0.0118 0.8939 0.1991 0.2987 0.6614 0.2844 0.4692 0.0648
0.9883])+3;
pointsx1=round((X/2-10)*[ 0.7948 0.9568 0.5226 0.8801 0.1730 0.9797 0.2714 0.2523 0.8757
0.7373])+3;
pointsx2=round((X/2-10)*[0.5828 0.4235 0.5155 0.3340 0.4329 0.2259 0.5798 0.7604 0.5298
0.6405])+(X/2+8);
points=[[pointsx1 pointsx2]' [pointsy1 pointsy2]'];
scatter=20;
%Provide the desired environment
switch media
case 1 %waveguide
er(edge1-2,(1:length))=100*ones(1,length);
er(edge2+2,(1:length))=100*ones(1,length);
case 2 %line of Sight
for i=1:scatter
er(points(i,1)-4:points(i,1)+4,points(i,2)-4:points(i,2)+4)=100*ones(9,9);
end
case 3 %No Line of Sight
er(center-4:center+4,left+(right-left)/2-4:left+(right-left)/2+4)=100*ones(9,9);
for i=1:scatter
er(points(i,1)-4:points(i,1)+4,points(i,2)-4:points(i,2)+4)=100*ones(9,9);
end
case 4 % Free Space
case 5 %User Defined
figure(1)
plot(offset,receiver,'marker','<','markerfacecolor','y','markeredgecolor','b','linestyle',':', 'markersize', 5)
hold on
plot((offset+depth)*ones(1,elements),arraystart:arrayspace:arraystart+(elements-1)*arrayspace,...
'marker','>','markerfacecolor','y','markeredgecolor','b','linestyle',':','markersize', 5)
axis equal
axis([1 Y 1 X])
title('Place Reflectors with Left Mouse Button, Press Right Mouse Button When Finished')
xlabel('Y')
ylabel('X')
view([0 270])
figure(1)
check=1;
grid on
grid minor
%Allow the user to place their own reflectors
while check ==1
[x,y,button]=ginput(1);
if button==3
check=0;
else
plot(round(x),round(y),'marker','square','markerfacecolor','r','markeredgecolor','k','markersize', 5)
axis([1 Y 1 X])
er(round(y),round(x))=1000;
end
end
hold off
close
end
handles.er=er;
guidata(h,handles)
axes(handles.axes2)
%Plot the simulation space
colormap(jet)
imagesc(er)
caxis([0 100])
hold on
plot(offset,receiver,'marker','<','markerfacecolor','y','markeredgecolor','b','linestyle',':', 'markersize', 5)
plot((offset+depth)*ones(1,elements),arraystart:arrayspace:arraystart+(elements-1)*arrayspace,...
'marker','>','markerfacecolor','y','markeredgecolor','b','linestyle',':','markersize', 5)
axis([1 Y 1 X])
xlabel('Y')
ylabel('X')
axis image
hold off
%===============================MENU FUNCTIONS=======================
% --------------------------------------------------------------------
function save_Callback(hObject, eventdata, handles)
% hObject handle to save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function save_array_pattern_Callback(hObject, eventdata, handles)
% hObject handle to save_array_pattern (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function save_array_setup_Callback(hObject, eventdata, handles)
% hObject handle to save_array_setup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes2)
print -dmeta simulation_setup
% --------------------------------------------------------------------
function save_movie_Callback(hObject, eventdata, handles)
% hObject handle to save_movie (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function print_Callback(hObject, eventdata, handles)
% hObject handle to print (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function print_array_setup_Callback(hObject, eventdata, handles)
% hObject handle to print_array_setup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
print -f handles.axes2
% --------------------------------------------------------------------
function print_array_pattern_Callback(hObject, eventdata, handles)
% hObject handle to print_array_pattern (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
print -f handles.axes3
% --------------------------------------------------------------------
function close_Callback(hObject, eventdata, handles)
% hObject handle to close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
delete(handles.figure1)
% --------------------------------------------------------------------
function varargout = edit11_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = slider1_Callback(h, eventdata, handles, varargin)
frames1=handles.frames1;
frames2=handles.frames2;
slides=[frames1 frames2];
slider_value = get(handles.slider1,'Value');
axes(handles.axes1)
image(frame2im(slides(slider_value)));
axis image
set(handles.edit11,'string',num2str(slider_value))
%-----------------------------------------------------------------------
function [E, V, frames] = fdtd05(imax, jmax, del, signal, start, space, array, rstart, rspace, depth, offset, media, ER)
% Reverse Time Migration - Modified on August 1, 2002
%
% Inputs:
% imax: size of grid in x-direction (in number of cells)
% jmax: size of grid in y-direction (in number of cells)
% del: size of cell in meters( needs to be less than lambda/10)
% signal: matrix with row vectors of signal (Input Signal)
% space: the number of cells between transmitters
% start: the cell at which the first trasnmitter is located
% array: the number of elements in the receiving array
% rstart: the x-coordinate of the first receiver
% rspace: the spacing between receivers
% depth: the distance between the receiving array and the transmitting array
% offset: the distance from zero in the x-direction where the simulation will start
% media: value between 1 and 5 that deterines the type of environment in which the expermient takesplace
% ER: when media=5, a user defined environment is provided
%
% Outputs:
% E: Outputs the final electric field
% V: Outputs the received signal at certain points (array elements for forward migration, receiver for
reverse migration)
% frames: a slide show that shows the evolution of E over time. Can be converted into AVI format using
%movie2avi command
% constitutive parameters
e0 = (1e-9)/(36*pi);
u0 = (4e-7)*pi;
c = 1./sqrt(e0*u0);
%The time step is determined by the cell size accroding to the courant stability equation
dt=(1/(c*sqrt((1/del)^2+(1/del)^2)));
%Allows for the input of several signals at a time (tr = array elements, Nt = length of signal)
[tr,Nt] = size(signal);
m = signal;
nb = 32; % PML: number of layers
% Compute total grid size, including PML layers
itotal = imax+2*nb;
jtotal = jmax+2*nb;
er = ones(itotal, jtotal); % relative permittivity
ur = ones(itotal, jtotal); % relative permeability
order = 3; % order of PML layer number
r = 1e-7; % reflection factor R(0);
smax = log(r)*(-(order+1)/2)*(e0*c)/(nb*del); % max conductivity
tt = dt:dt:Nt*dt; % time vector
sig = 0.00*ones(itotal, jtotal); % conductivity
sigex = zeros(itotal, jtotal); % electric conductivity on left and right PML
sigey = zeros(itotal, jtotal); % electric conductivity on upper and lower PML
%Determines the type pf propagation that is occuring and declares variables that help map the environment
if space==1; %forward Propagation
center=rstart+((array-1)/2)*rspace;
edge1=rstart;
edge2=rstart+(array-1)*rspace;
length=(offset+depth);
left=offset;
right=offset+depth;
end
if rspace==1; %Reverse Propagation
center=start+((tr-1)/2)*space;
edge1=start;
edge2=start+(tr-1)*space;
length=offset;
left=offset+depth;
right=offset;
end
%random points used to define the environment with LOS or no LOS propagation
pointsy1=round((jmax-3)*[ 0.7271 0.3093 0.8385 0.5681 0.3704 0.7027 0.5466 0.4449 0.6946 0.6213])+3;
pointsy2=round((jmax-3)*[ 0.1365 0.0118 0.8939 0.1991 0.2987 0.6614 0.2844 0.4692 0.0648 0.9883])+3;
pointsx1=round((imax/2-10)*[ 0.7948 0.9568 0.5226 0.8801 0.1730 0.9797 0.2714 0.2523 0.8757 0.7373])+3;
pointsx2=round((imax/2-10)*[0.5828 0.4235 0.5155 0.3340 0.4329 0.2259 0.5798 0.7604 0.529 0.6405])+(imax/2+8);
points=[[pointsx1 pointsx2]' [pointsy1 pointsy2]'];
scatter=20;
%Determines which type of environment to run the simulation under
switch media
case 1 %waveguide
er(nb+edge1-2,nb+(0:length-1))=100*ones(1,length);
er(nb+edge2+2,nb+(0:length-1))=100*ones(1,length);
case 2 %Line of Sight
for i=1:scatter
er(nb+points(i,1)-2:nb+points(i,1)+2,nb+points(i,2)-2:nb+points(i,2)+2)=100*ones(5,5);
end
case 3 %No Line of Sight
er(nb+center-4:nb+center+4,nb+left+(right-left)/2-4:nb+left+(right-left)/2+4)=100*ones(9,9);
for i=1:scatter
er(nb+points(i,1)-2:nb+points(i,1)+2,nb+points(i,2)-2:nb+points(i,2)+2)=100*ones(5,5);
end
case 4 % Free Space
case 5 %User Input
if nargin==13
er(nb:nb+imax-1,nb:nb+jmax-1)=ER;
end
end
% Electric conductivity
for i=1:nb,
sigex(i,:) = smax*((nb-i+1)/nb)^order;
sigey(:,i) = smax*((nb-i+1)/nb)^order;
sigex(imax+nb+i, :) = smax*(i/nb)^order;
sigey(:, jmax+nb+i) = smax*(i/nb)^order;
end;
sigmx = sigex*u0./e0; %magnetic conductivity on left and right PML
sigmy = sigey*u0./e0; %magnetic conductivity on upper and lower PML
% Coefficients for Maxwell's equations
alphaex = ones(itotal, jtotal);
alphaey = ones(itotal, jtotal);
alphamx = ones(itotal, jtotal);
alphamy = ones(itotal, jtotal);
betaex = ones(itotal, jtotal);
betaey = ones(itotal, jtotal);
betamx = ones(itotal, jtotal);
betamy = ones(itotal, jtotal);
%input boundary coefficients for PML
%*********************************************
alphaex = exp(-(sigex*dt)./e0); %left,right
alphaey = exp(-(sigey*dt)./e0); %upper,lower
alphamx = exp(-(sigmx*dt)/u0); %left,right
alphamy = exp(-(sigmy*dt)/u0); %upper,lower
% left component
betaex(1:nb,:) = (1-alphaex(1:nb,:))./(er(1:nb,:).*sigex(1:nb,:)*del);
% right componentbetaex(imax+nb+1:itotal,:) = (1-alphaex(imax+nb+1:itotal,:))/(er(imax+nb+1:itotal,:).*sigex(imax+nb+1:itotal,:)*del);
% upper component
betaey(:,1:nb) = (1-alphaey(:,1:nb))./(er(:,1:nb).*sigey(:,1:nb)*del);
% lower component
betaey(:,jmax+nb+1:jtotal) = (1-alphaey(:,jmax+nb+1:jtotal))/(er(:,jmax+nb+1:jtotal).*sigey(:,jmax+nb+1:jtotal)*del);
% left component
betamx(1:nb,:) = (1-alphamx(1:nb,:))./(sigmx(1:nb,:)*del);
% right component
betamx(imax+nb+1:itotal,:) = (1-alphamx(imax+nb+1:itotal,:))/(sigmx(imax+nb+1:itotal,:)*del);
% upper component
betamy(:,1:nb) = (1-alphamy(:,1:nb))./(sigmy(:,1:nb)*del);
% lower component
betamy(:,jmax+nb+1:jtotal) = (1-alphamy(:,jmax+nb+1:jtotal))/(sigmy(:,jmax+nb+1:jtotal)*del);
% Input coefficiences in main FDTD grid
%************************************************
dtdu = dt./(ur*u0*del);
dtde = dt./(er*e0*del);
loss = 1 - ((sig*dt)./(er*e0));
alphaex(nb+1:imax+nb,:) = loss(nb+1:imax+nb,:);
alphaey(:,nb+1:jmax+nb) = loss(:,nb+1:jmax+nb);
alphamx(nb+1:imax+nb,:) = 1;
alphamy(:,nb+1:jmax+nb) = 1;
betaex(nb+1:imax+nb,:) = dtde(nb+1:imax+nb,:);
betaey(:,nb+1:jmax+nb) = dtde(:,nb+1:jmax+nb);
betamx(nb+1:imax+nb,:) = dtdu(nb+1:imax+nb,:);
betamy(:,nb+1:jmax+nb) = dtdu(:,nb+1:jmax+nb);
% Initialize electromagnetic fields
ezx = zeros(itotal,jtotal);
ezy = zeros(itotal,jtotal);
hx = zeros(itotal,jtotal);
hy = zeros(itotal,jtotal);
% Start the main loop for FDTD calculations
%*****************************************************
% The outer loop enters each step, one at a time, while the inner loop inputs that
% step for each trace.
for j = 1:Nt,
for i = 1:tr;
% enter the signal from the last time step to the first (reversed in time)
%The Electric field is initiated by creating a magnetic loop
hx((i-1)*space+nb+start,offset+nb) = signal(i,j);
hy((i-1)*space+nb+start,offset+nb) = -signal(i,j);
hx((i-1)*space+nb+start,offset+nb+1) = -signal(i,j);
hy((i-1)*space+nb+start+1,offset+nb) = signal(i,j);
ezy((i-1)*space+nb+start,offset+nb)=0;
ezx((i-1)*space+nb+start,offset+nb)=0;
end;
% Advance the fields using code 'fdtdsteve'
[ezx,ezy,hx,hy] = fdtdsteve(ezx,ezy,hx,hy,alphaex,alphaey,alphamx,alphamy,betaex,betaey,betamx,betamy);
%The extra layers from the boundary conditions are removed
E=(ezx+ezy);
[a,b] = size(E);
E = E(33:(a-32), 33:(b-32));
%The desired signal is recorded
V(1:array,j)=[E(rstart:rspace:rstart+(array-1)*rspace,offset+depth)];
%The current electric field is plotted and saved for the movie
colormap(jet)
imagesc(E)
caxis([-100 100])
axis image
frames(j)=getframe;
end;
%######################################################################
function [ezx,ezy,hx,hy] = fdtdsteve(ezx,ezy,hx,hy,alphaex,alphaey,alphamx,alphamy,betaex,betaey,betamx,betamy);
[m,n]=size(ezx);
%advance electric field Ezx
for j=1:n
for i=1:m-1
ezx(i,j)=alphaex(i,j)*ezx(i,j)+betaex(i,j)*(hy(i+1,j)-hy(i,j));
end
end
%advance the electric field Ezy
for j=1:n-1
for i=1:m
ezy(i,j)=alphaey(i,j)*ezy(i,j)-betaey(i,j)*(hx(i,j+1)-hx(i,j));
end
end
%advance the magnetic field Hx
for j=2:n
for i=1:m
hx(i,j) = alphamy(i,j)*hx(i,j)-betamy(i,j)*(ezx(i,j)+ezy(i,j)-ezx(i,j-1)-ezy(i,j-1));
end
end
%advance the magentic field Hy
for j=1:n
for i=2:m
hy(i,j) = alphamx(i,j)*hy(i,j)+betamx(i,j)*(ezx(i,j)+ezy(i,j)-ezx(i-1,j)-ezy(i-1,j));
end
end
6 comentarios
Respuesta aceptada
Cris LaPierre
el 1 de Feb. de 2024
If you are going to have to rebuild anyway, I would suggest transitioning your gui to App Designer. MathWorks has been warning for a while now that Guide will be removed in a future release. No sense putting all the effort into it if you will then just have to transition to App Designer soon anyway.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Data Acquisition Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!