Path: blob/main/latex-templates/templates/optics/diffraction_grating.tex
51 views
unlisted
\documentclass[a4paper, 11pt]{article}1\usepackage[utf8]{inputenc}2\usepackage[T1]{fontenc}3\usepackage{amsmath, amssymb}4\usepackage{graphicx}5\usepackage{booktabs}6\usepackage{siunitx}7\usepackage[makestderr]{pythontex}89\title{Diffraction Grating Spectroscopy: Principles and Applications}10\author{Computational Optics}11\date{\today}1213\begin{document}14\maketitle1516\section{Introduction}17Diffraction gratings are fundamental optical elements that disperse light into its spectral components18through interference effects. This comprehensive analysis explores the physics of multi-slit diffraction,19spectral resolution, blazed gratings, and practical applications in spectroscopy. We implement20numerical simulations of grating patterns, analyze the trade-offs between resolution and intensity,21and demonstrate techniques for spectral line identification and analysis.2223\section{Mathematical Framework}2425\subsection{Grating Equation}26Principal maxima occur when:27\begin{equation}28d(\sin\theta_i + \sin\theta_m) = m\lambda29\end{equation}30where $d$ is the grating period, $\theta_i$ is the incident angle, $\theta_m$ is the diffraction angle,31and $m$ is the diffraction order.3233\subsection{Intensity Distribution}34For an N-slit grating with slit width $a$:35\begin{equation}36I(\theta) = I_0 \left(\frac{\sin\beta}{\beta}\right)^2 \left(\frac{\sin(N\alpha)}{\sin\alpha}\right)^237\end{equation}38where:39\begin{align}40\alpha &= \frac{\pi d \sin\theta}{\lambda} \\41\beta &= \frac{\pi a \sin\theta}{\lambda}42\end{align}4344\subsection{Resolving Power}45The chromatic resolving power:46\begin{equation}47R = \frac{\lambda}{\Delta\lambda} = mN48\end{equation}4950\subsection{Angular Dispersion}51\begin{equation}52\frac{d\theta}{d\lambda} = \frac{m}{d\cos\theta_m}53\end{equation}5455\section{Environment Setup}56\begin{pycode}57import numpy as np58import matplotlib.pyplot as plt59from scipy.signal import find_peaks6061plt.rc('text', usetex=True)62plt.rc('font', family='serif', size=10)63np.random.seed(42)6465def save_plot(filename, caption=""):66plt.savefig(filename, bbox_inches='tight', dpi=150)67print(r'\begin{figure}[htbp]')68print(r'\centering')69print(r'\includegraphics[width=0.95\textwidth]{' + filename + '}')70if caption:71print(r'\caption{' + caption + '}')72print(r'\end{figure}')73plt.close()74\end{pycode}7576\section{Basic Grating Diffraction Pattern}77\begin{pycode}78def grating_intensity(theta, wavelength, N, d, a):79"""Calculate normalized grating diffraction intensity."""80alpha = np.pi * d * np.sin(theta) / wavelength81beta = np.pi * a * np.sin(theta) / wavelength8283# Avoid division by zero84alpha = np.where(np.abs(alpha) < 1e-10, 1e-10, alpha)85beta = np.where(np.abs(beta) < 1e-10, 1e-10, beta)8687# Single slit envelope88I_slit = (np.sin(beta) / beta)**28990# Multi-slit interference91I_grating = (np.sin(N * alpha) / np.sin(alpha))**29293return I_slit * I_grating / N**29495# Grating parameters96d = 1e-6 # Grating period (1000 lines/mm)97a = d / 2 # Slit width (50% fill factor)98wavelength = 550e-9 # Green light99100# Angular range covering multiple orders101theta = np.linspace(-0.8, 0.8, 5000)102103# Calculate patterns for different N104N_values = [5, 20, 100, 500]105106fig, axes = plt.subplots(2, 2, figsize=(12, 10))107108for idx, N in enumerate(N_values):109row, col = divmod(idx, 2)110I = grating_intensity(theta, wavelength, N, d, a)111112axes[row, col].plot(np.rad2deg(theta), I, 'b-', linewidth=0.5)113axes[row, col].set_xlabel('Angle (degrees)')114axes[row, col].set_ylabel('Intensity (normalized)')115axes[row, col].set_title(f'N = {N} slits')116axes[row, col].set_xlim([-50, 50])117axes[row, col].grid(True, alpha=0.3)118119# Mark diffraction orders120for m in range(-1, 2):121if abs(m * wavelength / d) <= 1:122theta_m = np.rad2deg(np.arcsin(m * wavelength / d))123axes[row, col].axvline(x=theta_m, color='r', linestyle='--', alpha=0.5)124125plt.tight_layout()126save_plot('grating_n_comparison.pdf',127'Diffraction patterns for gratings with different numbers of slits.')128\end{pycode}129130\section{Spectral Resolution Analysis}131\begin{pycode}132# Sodium D-lines (classic test of spectral resolution)133lambda1 = 589.0e-9 # D1 line134lambda2 = 589.6e-9 # D2 line135delta_lambda = lambda2 - lambda1136137# Grating parameters for high resolution138d = 1e-6 # 1000 lines/mm139a = d / 2140141# Test different N values142N_test = [100, 500, 1000, 2000]143144fig, axes = plt.subplots(2, 2, figsize=(12, 10))145146for idx, N in enumerate(N_test):147row, col = divmod(idx, 2)148149# Angular range around first order150theta_center = np.arcsin(lambda1 / d)151theta = np.linspace(theta_center - 0.01, theta_center + 0.01, 3000)152153# Calculate patterns for both lines154I1 = grating_intensity(theta, lambda1, N, d, a)155I2 = grating_intensity(theta, lambda2, N, d, a)156I_total = I1 + I2157158axes[row, col].plot(np.rad2deg(theta), I1, 'b-', linewidth=1, alpha=0.7, label='D1')159axes[row, col].plot(np.rad2deg(theta), I2, 'r-', linewidth=1, alpha=0.7, label='D2')160axes[row, col].plot(np.rad2deg(theta), I_total, 'k-', linewidth=1.5, label='Total')161162# Resolution criterion163R_needed = lambda1 / delta_lambda164R_actual = N # First order165resolved = "Resolved" if R_actual >= R_needed else "Unresolved"166167axes[row, col].set_xlabel('Angle (degrees)')168axes[row, col].set_ylabel('Intensity')169axes[row, col].set_title(f'N = {N}, R = {R_actual} ({resolved})')170axes[row, col].legend(fontsize=8)171axes[row, col].grid(True, alpha=0.3)172173plt.tight_layout()174save_plot('sodium_resolution.pdf',175'Resolution of sodium D-lines with different numbers of grating lines.')176177# Calculate required N for Rayleigh resolution178N_required = int(np.ceil(lambda1 / delta_lambda))179\end{pycode}180181\section{Multiple Diffraction Orders}182\begin{pycode}183# Analyze multiple diffraction orders184d = 2e-6 # 500 lines/mm for more visible orders185a = d / 3 # Smaller fill factor186N = 200187wavelength = 550e-9188189theta = np.linspace(-1.2, 1.2, 8000)190I = grating_intensity(theta, wavelength, N, d, a)191192fig, axes = plt.subplots(2, 2, figsize=(12, 10))193194# Full pattern195axes[0, 0].plot(np.rad2deg(theta), I, 'b-', linewidth=0.5)196axes[0, 0].set_xlabel('Angle (degrees)')197axes[0, 0].set_ylabel('Intensity')198axes[0, 0].set_title('Multiple Diffraction Orders')199axes[0, 0].grid(True, alpha=0.3)200201# Mark and label orders202order_angles = []203order_intensities = []204for m in range(-3, 4):205sin_theta = m * wavelength / d206if abs(sin_theta) <= 1:207theta_m = np.arcsin(sin_theta)208order_angles.append(np.rad2deg(theta_m))209210# Find peak intensity at this order211idx = np.argmin(np.abs(theta - theta_m))212order_intensities.append(I[idx])213214axes[0, 0].annotate(f'm={m}', xy=(np.rad2deg(theta_m), I[idx]),215xytext=(np.rad2deg(theta_m), I[idx] + 0.1),216ha='center', fontsize=8)217218# Order intensities comparison219valid_orders = list(range(-3, 4))220axes[0, 1].bar(valid_orders[:len(order_intensities)], order_intensities,221color='green', alpha=0.7, edgecolor='black')222axes[0, 1].set_xlabel('Diffraction Order m')223axes[0, 1].set_ylabel('Peak Intensity')224axes[0, 1].set_title('Intensity vs Diffraction Order')225axes[0, 1].grid(True, alpha=0.3)226227# Blaze effect: fill factor variation228fill_factors = [0.2, 0.3, 0.5, 0.7]229for ff in fill_factors:230a_test = d * ff231I_test = grating_intensity(theta, wavelength, N, d, a_test)232axes[1, 0].plot(np.rad2deg(theta), I_test, linewidth=0.5,233label=f'a/d = {ff}', alpha=0.7)234235axes[1, 0].set_xlabel('Angle (degrees)')236axes[1, 0].set_ylabel('Intensity')237axes[1, 0].set_title('Effect of Fill Factor')238axes[1, 0].legend(fontsize=8)239axes[1, 0].grid(True, alpha=0.3)240axes[1, 0].set_xlim([-70, 70])241242# Angular dispersion across orders243wavelengths = np.linspace(400e-9, 700e-9, 100)244colors_spectrum = plt.cm.rainbow(np.linspace(0, 1, len(wavelengths)))245246for m in [1, 2, 3]:247angles = []248valid_wavelengths = []249for wl in wavelengths:250sin_theta = m * wl / d251if abs(sin_theta) <= 1:252angles.append(np.rad2deg(np.arcsin(sin_theta)))253valid_wavelengths.append(wl * 1e9)254255if len(angles) > 0:256axes[1, 1].plot(valid_wavelengths, angles, linewidth=2, label=f'm = {m}')257258axes[1, 1].set_xlabel('Wavelength (nm)')259axes[1, 1].set_ylabel('Diffraction Angle (degrees)')260axes[1, 1].set_title('Angular Dispersion')261axes[1, 1].legend()262axes[1, 1].grid(True, alpha=0.3)263264plt.tight_layout()265save_plot('multiple_orders.pdf',266'Analysis of multiple diffraction orders and angular dispersion.')267\end{pycode}268269\section{Blazed Grating Simulation}270\begin{pycode}271def blazed_grating_intensity(theta, wavelength, N, d, blaze_angle):272"""Blazed grating with specified blaze angle."""273# Phase from grating period274alpha = np.pi * d * np.sin(theta) / wavelength275276# Blaze envelope centered on blaze angle277beta_blaze = np.pi * d * (np.sin(theta) - np.sin(blaze_angle)) / wavelength278beta_blaze = np.where(np.abs(beta_blaze) < 1e-10, 1e-10, beta_blaze)279280# Intensities281I_blaze = (np.sin(beta_blaze) / beta_blaze)**2282283alpha = np.where(np.abs(alpha) < 1e-10, 1e-10, alpha)284I_grating = (np.sin(N * alpha) / np.sin(alpha))**2285286return I_blaze * I_grating / N**2287288# Blazed grating parameters289d = 1.5e-6290N = 300291wavelength = 550e-9292293# Blaze angle for maximum in first order294blaze_angle = np.arcsin(wavelength / d)295296theta = np.linspace(-0.6, 0.6, 5000)297298# Compare blazed vs non-blazed299I_blazed = blazed_grating_intensity(theta, wavelength, N, d, blaze_angle)300I_normal = grating_intensity(theta, wavelength, N, d, d/2)301302fig, axes = plt.subplots(2, 2, figsize=(12, 10))303304# Comparison305axes[0, 0].plot(np.rad2deg(theta), I_normal, 'b-', linewidth=0.5, label='Symmetric')306axes[0, 0].plot(np.rad2deg(theta), I_blazed, 'r-', linewidth=0.5, label='Blazed')307axes[0, 0].set_xlabel('Angle (degrees)')308axes[0, 0].set_ylabel('Intensity')309axes[0, 0].set_title('Blazed vs Symmetric Grating')310axes[0, 0].legend()311axes[0, 0].grid(True, alpha=0.3)312313# Different blaze angles314blaze_angles_deg = [10, 20, 30]315for ba_deg in blaze_angles_deg:316ba = np.deg2rad(ba_deg)317I = blazed_grating_intensity(theta, wavelength, N, d, ba)318axes[0, 1].plot(np.rad2deg(theta), I, linewidth=0.5, label=f'Blaze = {ba_deg}$^\\circ$')319320axes[0, 1].set_xlabel('Angle (degrees)')321axes[0, 1].set_ylabel('Intensity')322axes[0, 1].set_title('Effect of Blaze Angle')323axes[0, 1].legend(fontsize=8)324axes[0, 1].grid(True, alpha=0.3)325326# Efficiency at different wavelengths327wavelengths_test = np.linspace(400e-9, 700e-9, 50)328first_order_efficiency = []329second_order_efficiency = []330331for wl in wavelengths_test:332blaze = np.arcsin(wl / d)333theta_1 = np.arcsin(wl / d)334theta_2 = np.arcsin(2 * wl / d) if 2*wl/d <= 1 else 0335336# Calculate intensity at first and second order337I1 = blazed_grating_intensity(np.array([theta_1]), wl, N, d, blaze)[0]338if theta_2 > 0:339I2 = blazed_grating_intensity(np.array([theta_2]), wl, N, d, blaze)[0]340else:341I2 = 0342343first_order_efficiency.append(I1)344second_order_efficiency.append(I2)345346axes[1, 0].plot(wavelengths_test*1e9, first_order_efficiency, 'b-',347linewidth=2, label='1st order')348axes[1, 0].plot(wavelengths_test*1e9, second_order_efficiency, 'r--',349linewidth=2, label='2nd order')350axes[1, 0].set_xlabel('Wavelength (nm)')351axes[1, 0].set_ylabel('Efficiency')352axes[1, 0].set_title('Order Efficiency vs Wavelength')353axes[1, 0].legend()354axes[1, 0].grid(True, alpha=0.3)355356# Grating groove profile357x_groove = np.linspace(0, 3*d*1e6, 300)358y_groove = np.mod(x_groove, d*1e6) * np.tan(blaze_angle)359360axes[1, 1].plot(x_groove, y_groove, 'k-', linewidth=2)361axes[1, 1].fill_between(x_groove, 0, y_groove, alpha=0.3)362axes[1, 1].set_xlabel('Position ($\\mu$m)')363axes[1, 1].set_ylabel('Height ($\\mu$m)')364axes[1, 1].set_title(f'Blazed Groove Profile (blaze = {np.rad2deg(blaze_angle):.1f}$^\\circ$)')365axes[1, 1].grid(True, alpha=0.3)366367plt.tight_layout()368save_plot('blazed_grating.pdf',369'Blazed grating analysis showing efficiency enhancement.')370\end{pycode}371372\section{Spectroscopy Application}373\begin{pycode}374# Simulate a spectrum with multiple emission lines375emission_lines = {376'H-alpha': 656.3e-9,377'H-beta': 486.1e-9,378'Na-D1': 589.0e-9,379'Na-D2': 589.6e-9,380'Hg-green': 546.1e-9381}382383d = 1e-6384N = 1000385a = d / 2386387# Full spectrum388theta_full = np.linspace(0.2, 0.8, 10000)389390fig, axes = plt.subplots(2, 2, figsize=(12, 10))391392# Individual line patterns393I_total = np.zeros_like(theta_full)394colors = ['red', 'blue', 'orange', 'darkorange', 'green']395396for (name, wl), color in zip(emission_lines.items(), colors):397I = grating_intensity(theta_full, wl, N, d, a)398I_total += I399400if name in ['H-alpha', 'H-beta', 'Na-D1', 'Hg-green']:401axes[0, 0].plot(np.rad2deg(theta_full), I, color=color,402linewidth=1, alpha=0.7, label=name)403404axes[0, 0].set_xlabel('Angle (degrees)')405axes[0, 0].set_ylabel('Intensity')406axes[0, 0].set_title('Individual Emission Lines')407axes[0, 0].legend(fontsize=8)408axes[0, 0].grid(True, alpha=0.3)409410# Combined spectrum411axes[0, 1].plot(np.rad2deg(theta_full), I_total, 'k-', linewidth=0.5)412axes[0, 1].set_xlabel('Angle (degrees)')413axes[0, 1].set_ylabel('Total Intensity')414axes[0, 1].set_title('Combined Emission Spectrum')415axes[0, 1].grid(True, alpha=0.3)416417# Wavelength calibration418# Convert angle to wavelength (first order)419wavelength_scale = d * np.sin(theta_full) * 1e9 # nm420421axes[1, 0].plot(wavelength_scale, I_total, 'k-', linewidth=0.5)422axes[1, 0].set_xlabel('Wavelength (nm)')423axes[1, 0].set_ylabel('Intensity')424axes[1, 0].set_title('Calibrated Spectrum')425axes[1, 0].grid(True, alpha=0.3)426axes[1, 0].set_xlim([400, 700])427428# Mark line positions429for name, wl in emission_lines.items():430axes[1, 0].axvline(x=wl*1e9, color='r', linestyle='--', alpha=0.3)431432# Peak finding and identification433peaks, properties = find_peaks(I_total, height=0.01, distance=50)434peak_wavelengths = wavelength_scale[peaks]435peak_intensities = I_total[peaks]436437axes[1, 1].scatter(peak_wavelengths, peak_intensities, c='red', s=50)438axes[1, 1].set_xlabel('Wavelength (nm)')439axes[1, 1].set_ylabel('Peak Intensity')440axes[1, 1].set_title('Detected Peaks')441axes[1, 1].grid(True, alpha=0.3)442axes[1, 1].set_xlim([400, 700])443444# Annotate peaks445for i, (wl, intensity) in enumerate(zip(peak_wavelengths, peak_intensities)):446if 400 < wl < 700:447axes[1, 1].annotate(f'{wl:.1f}', (wl, intensity),448textcoords="offset points", xytext=(0, 10),449ha='center', fontsize=7)450451plt.tight_layout()452save_plot('spectroscopy_application.pdf',453'Spectroscopy application showing emission line identification.')454455# Count identified peaks456n_peaks_found = len([wl for wl in peak_wavelengths if 400 < wl < 700])457\end{pycode}458459\section{Results Summary}460461\subsection{Grating Specifications}462\begin{pycode}463print(r'\begin{table}[htbp]')464print(r'\centering')465print(r'\caption{Grating Parameters and Performance}')466print(r'\begin{tabular}{lc}')467print(r'\toprule')468print(r'Parameter & Value \\')469print(r'\midrule')470print(f'Grating period & {d*1e6:.2f} $\\mu$m \\\\')471print(f'Lines per mm & {1/(d*1e3):.0f} \\\\')472print(f'Number of lines illuminated & {N} \\\\')473print(f'Resolving power (1st order) & {N} \\\\')474print(f'Required N for Na D-lines & {N_required} \\\\')475print(f'Angular dispersion (1st order) & {1e9/(d*np.cos(np.arcsin(550e-9/d))):.2f} nm/rad \\\\')476print(r'\bottomrule')477print(r'\end{tabular}')478print(r'\end{table}')479\end{pycode}480481\subsection{Emission Lines Detected}482\begin{pycode}483print(r'\begin{table}[htbp]')484print(r'\centering')485print(r'\caption{Emission Line Identification}')486print(r'\begin{tabular}{lcc}')487print(r'\toprule')488print(r'Line & Wavelength (nm) & First Order Angle \\')489print(r'\midrule')490491for name, wl in emission_lines.items():492angle = np.rad2deg(np.arcsin(wl / d))493print(f'{name} & {wl*1e9:.1f} & {angle:.2f}$^\\circ$ \\\\')494495print(r'\bottomrule')496print(r'\end{tabular}')497print(r'\end{table}')498\end{pycode}499500\section{Statistical Summary}501Key diffraction grating results:502\begin{itemize}503\item Grating lines per mm: \py{f"{1/(d*1e3):.0f}"}504\item Resolving power (N=1000): \py{f"{N}"}505\item Minimum resolvable wavelength difference: \py{f"{550/N:.3f}"} nm506\item Required N for sodium D-lines: \py{f"{N_required}"}507\item Blaze angle for 550 nm: \py{f"{np.rad2deg(np.arcsin(550e-9/d)):.2f}"}$^\circ$508\item Spectral peaks identified: \py{f"{n_peaks_found}"}509\end{itemize}510511\section{Conclusion}512This computational analysis demonstrates the principles of diffraction grating spectroscopy.513The resolving power scales linearly with the number of illuminated grating lines, enabling514high-resolution spectral analysis. Blazed gratings concentrate diffracted energy into specific515orders, improving efficiency. The grating equation provides accurate wavelength calibration516for spectroscopic measurements. These techniques are fundamental to atomic spectroscopy,517astronomical observations, and analytical chemistry applications.518519\end{document}520521522