Understanding Photonics Using MATLAB
Photonics is the science and technology of generating, controlling, and detecting photons. MATLAB is a powerful tool for simulating photonic systems, analyzing optical data, and solving equations related to photonics.
Simulating Photonic Systems Using Matlab
Photonics often involves solving wave equations, analyzing optical interference patterns, and modeling light propagation. Here’s an example of creating a simulation for light interference:
% Simulating light interference
lambda = 500e-9; % Wavelength in meters (500 nm)
x = linspace(-1e-3, 1e-3, 500); % x-coordinates
y = linspace(-1e-3, 1e-3, 500); % y-coordinates
[X, Y] = meshgrid(x, y);
r1 = sqrt((X - 0.5e-3).^2 + Y.^2); % Distance from source 1
r2 = sqrt((X + 0.5e-3).^2 + Y.^2); % Distance from source 2
I = cos(2*pi*(r1 - r2)/lambda).^2; % Interference pattern
imagesc(x, y, I);
colorbar;
title('Interference Pattern');
xlabel('x (m)');
ylabel('y (m)');
Output:
A colorful interference pattern plot will be displayed, illustrating the interaction between two light sources.
Solving Photonics Equations
Photonics often requires solving equations such as the wave equation or Maxwell’s equations. Here’s an example of solving the wave equation for light propagation in a medium:
% Solving the wave equation
c = 3e8; % Speed of light in vacuum (m/s)
k = 2*pi/(500e-9); % Wave number
omega = c * k; % Angular frequency
x = linspace(0, 2e-6, 100);
t = linspace(0, 1e-14, 100);
[X, T] = meshgrid(x, t);
E = sin(k*X - omega*T); % Electric field
mesh(X, T, E);
xlabel('x (m)');
ylabel('t (s)');
zlabel('Electric Field (E)');
title('Wave Propagation');
Output:
A 3D mesh plot will show the wave propagation of the electric field over time.
Photonics Simulations: Refraction
Simulate light refraction using Snell’s Law:
% Refraction Simulation
n1 = 1; % Refractive index of medium 1
n2 = 1.5; % Refractive index of medium 2
theta1 = linspace(0, pi/2, 100); % Incident angles
theta2 = asin(n1/n2 * sin(theta1)); % Refracted angles
plot(rad2deg(theta1), rad2deg(theta2));
xlabel('Incident Angle (degrees)');
ylabel('Refracted Angle (degrees)');
title('Refraction Simulation');
Output:
A 2D plot showing the relationship between incident and refracted angles based on Snell's Law.
Example Problems in Photonics Using Matlab
Example 1: Beam Propagation in an Optical Fiber
Simulate the beam propagation in an optical fiber using the scalar beam propagation method (BPM):
% Beam Propagation Method in Optical Fiber
L = 10; % Fiber length (mm)
lambda = 1550e-9; % Wavelength (m)
n_core = 1.45; % Core refractive index
n_clad = 1.44; % Cladding refractive index
dx = 0.01; % Spatial step size (mm)
dz = 0.1; % Propagation step size (mm)
x = -5:dx:5; % Spatial grid (mm)
[X, Z] = meshgrid(x, 0:dz:L);
E0 = exp(-X.^2); % Initial Gaussian beam
beta = (2*pi/lambda) * n_core; % Propagation constant
E = zeros(size(Z));
E(:,1) = E0;
for k = 1:size(Z,2)-1
E(:,k+1) = E(:,k) .* exp(1i * beta * dz); % BPM update
end
imagesc(x, linspace(0, L, size(Z,2)), abs(E)');
colorbar;
xlabel('x (mm)');
ylabel('z (mm)');
title('Beam Propagation in Optical Fiber');
Output:
A 2D plot showing the evolution of the beam intensity along the length of the optical fiber.
Example 2: Photonic Band Gap Calculation
Calculate the photonic band gap for a 1D periodic structure:
% Photonic Band Gap Calculation for 1D Photonic Crystal
d1 = 0.2e-6; % Thickness of material 1 (m)
d2 = 0.3e-6; % Thickness of material 2 (m)
n1 = 2.0; % Refractive index of material 1
n2 = 1.5; % Refractive index of material 2
c = 3e8; % Speed of light (m/s)
lambda = linspace(0.5e-6, 2e-6, 1000); % Wavelength range (m)
omega = 2*pi*c ./ lambda; % Angular frequency
k1 = 2*pi*n1 ./ lambda; % Wave vector in material 1
k2 = 2*pi*n2 ./ lambda; % Wave vector in material 2
% Transfer matrix calculation
T = abs(cos(k1*d1) .* cos(k2*d2) - (1/2) * (k2/k1 + k1/k2) .* sin(k1*d1) .* sin(k2*d2));
plot(lambda * 1e6, T);
xlabel('Wavelength (microns)');
ylabel('Transmission Coefficient');
title('Photonic Band Gap Calculation');
Output:
A plot showing transmission as a function of wavelength, identifying the band gap where transmission is minimal.
Example 3: FDTD Simulation of Light Scattering
Simulate light scattering using the Finite-Difference Time-Domain (FDTD) method:
% FDTD Simulation for Light Scattering
Nx = 200; % Grid points in x-direction
Ny = 200; % Grid points in y-direction
dx = 10e-9; % Grid spacing (m)
dy = 10e-9; % Grid spacing (m)
c = 3e8; % Speed of light (m/s)
dt = dx / (2*c); % Time step
Nt = 500; % Number of time steps
% Initialize fields
Ez = zeros(Nx, Ny);
Hx = zeros(Nx, Ny);
Hy = zeros(Nx, Ny);
% Source
source_x = Nx/2;
source_y = Ny/2;
for t = 1:Nt
% Update magnetic field
Hx(:, 1:end-1) = Hx(:, 1:end-1) - (dt/(mu0*dx)) * diff(Ez, 1, 2);
Hy(1:end-1, :) = Hy(1:end-1, :) + (dt/(mu0*dy)) * diff(Ez, 1, 1);
% Update electric field
Ez(2:end-1, 2:end-1) = Ez(2:end-1, 2:end-1) + (dt/(eps0*dx)) * ...
(diff(Hy(:, 2:end), 1, 2) - diff(Hx(2:end, :), 1, 1));
% Inject source
Ez(source_x, source_y) = Ez(source_x, source_y) + sin(2*pi*1e14*t*dt);
end
imagesc(Ez');
colorbar;
title('FDTD Light Scattering Simulation');
xlabel('x (grid points)');
ylabel('y (grid points)');
Output:
A 2D plot showing the electric field intensity distribution due to light scattering.
Example 4: Coupled Mode Theory: Coupling Between Two Waveguides
Analyze the coupling of light between two parallel optical waveguides:
% Coupled Mode Theory for Two Waveguides
kappa = 1; % Coupling coefficient (1/mm)
L = 10; % Length of the waveguides (mm)
z = linspace(0, L, 100); % Propagation distance
A0 = 1; % Initial amplitude in waveguide 1
B0 = 0; % Initial amplitude in waveguide 2
A = A0 * cos(kappa*z); % Amplitude in waveguide 1
B = A0 * sin(kappa*z); % Amplitude in waveguide 2
plot(z, A, z, B);
xlabel('Propagation Distance (mm)');
ylabel('Amplitude');
legend('Waveguide 1', 'Waveguide 2');
title('Coupled Mode Theory: Waveguide Coupling');
Output:
A plot showing the periodic transfer of optical power between the two waveguides as a function of propagation distance.
Example 5: Gaussian Beam Simulation
Simulate the propagation of a Gaussian beam through free space:
% Gaussian Beam Propagation Simulation
lambda = 1550e-9; % Wavelength (m)
w0 = 1e-3; % Beam waist (m)
z = linspace(0, 0.1, 1000); % Propagation distance (m)
zR = pi * w0^2 / lambda; % Rayleigh range (m)
w = w0 * sqrt(1 + (z/zR).^2); % Beam radius as a function of z
R = z .* (1 + (zR./z).^2); % Radius of curvature
phi = atan(z/zR); % Gouy phase
plot(z, w*1e3);
xlabel('Propagation Distance (m)');
ylabel('Beam Radius (mm)');
title('Gaussian Beam Propagation');
grid on;
Output:
A plot showing the beam radius (spot size) as a function of propagation distance, highlighting the waist and divergence.
Example 6: Simulation of Fabry-Perot Resonator
Simulate the transmission spectrum of a Fabry-Perot resonator:
% Fabry-Perot Resonator Transmission Simulation
lambda = linspace(1.5e-6, 1.6e-6, 1000); % Wavelength range (m)
L = 2e-6; % Cavity length (m)
R = 0.9; % Reflectivity of mirrors
T = 1 - R; % Transmissivity
c = 3e8; % Speed of light (m/s)
F = (4*R) / (1 - R)^2; % Finesse parameter
delta = 2*pi*L ./ lambda; % Phase shift
T_resonator = (T^2) ./ (1 + F*sin(delta/2).^2);
plot(lambda*1e6, T_resonator);
xlabel('Wavelength (\mum)');
ylabel('Transmission');
title('Fabry-Perot Resonator Transmission Spectrum');
grid on;
Output:
A plot showing the periodic peaks of transmission as a function of wavelength, representing the resonant modes of the cavity.
Example 7: Diffraction Grating Simulation
Calculate the diffraction efficiency for a given grating:
% Diffraction Grating Efficiency Calculation
lambda = linspace(400e-9, 700e-9, 1000); % Wavelength range (m)
d = 1e-6; % Grating spacing (m)
m = 1; % Diffraction order
theta = asin(m * lambda / d); % Diffraction angle
efficiency = (cos(theta).^2) .* (sin(pi*d*sin(theta)./lambda).^2);
plot(lambda*1e9, efficiency);
xlabel('Wavelength (nm)');
ylabel('Efficiency');
title('Diffraction Grating Efficiency');
grid on;
Output:
A plot showing the variation of diffraction efficiency with wavelength for the specified grating parameters.
Example 8: Simulating Supercontinuum Generation
Model the generation of a supercontinuum in a nonlinear photonic crystal fiber:
% Supercontinuum Generation Simulation
lambda0 = 1550e-9; % Central wavelength (m)
P0 = 1e3; % Input peak power (W)
L = 1; % Fiber length (m)
gamma = 1.5; % Nonlinear coefficient (W^-1*m^-1)
beta2 = -2e-26; % Group velocity dispersion (s^2/m)
z = linspace(0, L, 100); % Propagation distance
lambda = linspace(1e-6, 2e-6, 500); % Wavelength range (m)
omega = 2*pi*3e8 ./ lambda; % Angular frequency
P_lambda = P0 * exp(-((lambda-lambda0).^2)/(2*(0.1e-6)^2)); % Input power spectrum
S = abs(P_lambda .* exp(-1i * gamma * P0 * z' * beta2)).^2; % Output spectrum
imagesc(lambda*1e6, z, S);
xlabel('Wavelength (\mum)');
ylabel('Propagation Distance (m)');
title('Supercontinuum Generation');
colorbar;
Output:
A 2D plot showing the broadening of the spectrum along the propagation distance due to supercontinuum generation.
Useful MATLAB Functions for Photonics
Practice Questions
Test Yourself
1. Simulate an interference pattern for a wavelength of 600 nm.
2. Plot the relationship between incident and refracted angles for n1 = 1.33 and n2 = 1.50.
3. Solve the wave equation for a wave traveling at 2e8 m/s.