Simulation with Matlab: wave scattering from two bodies

Radar back signal received


First the animation: that is video from figure 2., introducing wave scattering and some stealthness principles.



Simulation and computationnal aspects rely on finite difference method, see for example (french) this page and also for example (also french) introduction to Matlab programming, and more specifically activities 8, simulation of monodimensionnal wave scattering, 9, simulation of bidimensionnal wave scattering, and 10, simulation of wave scattering inside a medium.

About the simulation and animation on which result is shown on top, the Matlab code is:
clear all;close all
clc;
c=8;
Lx=100;Ly=Lx;
Nx=150;Ny=150;
dx=Lx/Nx;dy=Ly/Ny;
x=linspace(0,Lx,Nx);
y=linspace(0,Ly,Ny);

dt=sqrt(dx^2+dy^2)/(2*c);
nu=1;       % frqce de la source
Temis=4;    % source emitting duration
T=32;
t=[0:dt:T];Nt=length(t);
gax=c^2*dt^2/dx^2;
gay=c^2*dt^2/dy^2;

% Source location
sx=round(Lx/10);
sy=round(Ly/10);

u=zeros(Nx,Ny,Nt);


% First Obstacle
Ox=round(3*Nx/4);Oy=round(Ny/2);% centre

% Second Obstacle
Px=round(Nx/4);Py=round(4*Ny/5);% centre

for k=2:Nt-1
    for i=2:Nx-1
        for j=2:Ny-1
            tmp1=u(i-1,j,k)+u(i+1,j,k)-2*u(i,j,k);
            tmp2=u(i,j-1,k)+u(i,j+1,k)-2*u(i,j,k);
            u(i,j,k+1)=2*u(i,j,k)-u(i,j,k-1)+gax*tmp1+gay*tmp2;
        end
    end
    if (k*dt<Temis)
        u(sx,sy,k+1)=2*sin(2*pi*nu*k*dt);
    else
        u(sx,sy,k+1)=0;
    end
    %
    % Obstacles :
    for l=-2:4
        u(Ox-l-4:Ox+l^2+2,Oy+l:Oy+l+2,k+1)=0; 
        u(Px+l:Px+l^2,Py+l:Py+l^2,:)=0; 
    end
    %
    % Not wanted reflections:
    u(1,:,k+1)=u(2,:,k);
    u(Nx,:,k+1)=u(Nx-1,:,k);
    u(:,1,k+1)=u(:,2,k);
    u(:,Ny,k+1)=u(:,Ny-1,k);
end

% Source drawing
u(sx,sy,:)=10;

% First obstacle drawing
for l=-2:4
    u(Ox-l-4:Ox+l^2+2,Oy+l:Oy+l+2,:)=10; 
end

% Second obstacle drawing
for l=-2:4
    u(Px+l:Px+l^2,Py+l:Py+l^2,:)=10; 
end


fig=figure(1);clf;whitebg('w')
colormap(jet)

MM=[];

for k=1:2:Nt
    
    subplot(211);
    %imagesc(squeeze(u(:,:,k)));
    pcolor(squeeze(u(:,:,k)));
    axis off
    shading interp
    caxis([-0.5 2]);%colorbar
    
    subplot(212),hold on
    pp=plot([1:k]*dt,squeeze(u(sx+3,sy+3,1:k)));
    set(pp,'linewidth',3')
    pp=plot(t,zeros(size(t)),'--k');
    set(pp,'linewidth',0.5')
    axis([0 T -0.6 0.6])
    xlabel('Temps [ms]','fontsize',16)
    ylabel('Amplitude','fontsize',16)
    grid on
    %pause(0.01)
    MM=[MM getframe(fig)];
end

%break
movie2avi(MM,'Anim.avi')


Video resulting from movie2avi is usually a heavy (if not really huge) one.
One can directly enable Matlab to use some codecs, see movie2avi parameters, via
help movie2avi
or, also see Matlab alternative solution to video generation: VideoWriter, which is to used nearly the same way as movie2avi, but is a rather more complete with respect to codecs; see the list of available "profiles"
VideoWriter.getProfiles()


Another alternative is to convert video after Matlab process, via for example ffmpeg
ffmpeg -i film.avi film.mp4

which one can then use directly use, for example, inside html5 <video> (as at the top of page), or to convert to animated gif, via convert utility (ImageMagic software)
convert -loop 2 film.avi film.gif

See also: