Abstract
Detecting concealed chemicals and explosives remains a critical challenge in global security. Terahertz time-domain spectroscopy (THz-TDS) offers a promising non-invasive and stand-off detection technique owing to its ability to penetrate optically opaque materials without causing ionization damage. While many chemicals exhibit distinct spectral features in the terahertz range, conventional terahertz-based detection methods often struggle in real-world environments, where variations in sample geometry, thickness, and packaging can lead to inconsistent spectral responses. In this study, we present a chemical imaging system that integrates THz-TDS with deep learning to enable accurate pixel-level identification and classification of different explosives. Operating in reflection mode and enhanced with plasmonic nanoantenna arrays, our THz-TDS system achieves a peak dynamic range of 96 dB and a detection bandwidth of 4.5 THz, supporting practical, stand-off operation. By analyzing individual time-domain pulses with deep neural networks, the system exhibits strong resilience to environmental variations and sample inconsistencies. Blind testing across eight chemicals—including pharmaceutical excipients and explosive compounds—resulted in an average classification accuracy of 99.42% at the pixel level. Notably, the system maintained an average accuracy of 88.83% when detecting explosives concealed under opaque paper coverings, demonstrating its robust generalization capability. These results highlight the potential of combining advanced terahertz spectroscopy with neural networks for highly sensitive and specific chemical and explosive detection in diverse and operationally relevant scenarios.
Similar content being viewed by others
Introduction
The terahertz region of the electromagnetic spectrum, spanning frequencies from ~0.1 to 10 THz, bridges the gap between microwave and far-infrared radiation. This spectral range is particularly attractive due to its unique interactions with a variety of materials. The photon energy of terahertz waves corresponds to the excitation energies of numerous molecular rotational and vibrational transitions, while remaining low enough to avoid ionization damage to samples. As a result, terahertz spectroscopy has emerged as a powerful tool across diverse fields, including biomedical diagnosis1,2,3, security screening4,5,6,7,8,9,10,11,12,13,14, pharmaceutical quality control15,16,17,18, as well as agriculture and food inspection19,20,21,22. The ability of terahertz radiation to penetrate many optically opaque materials—such as paper, clothing, and plastics—makes it especially valuable for the stand-off detection of concealed chemicals. This non-invasive imaging capability enables the identification of hidden threats, such as explosives, without direct contact, thereby improving safety and operational efficiency.
Several technologies are currently employed for explosive detection, including X-ray imaging23,24, millimeter-wave imaging25, mass spectrometry26, ion mobility spectrometry27,28, and hybrid approaches that integrate multiple modalities. While these systems are critical for enhancing security and mitigating threats, each has specific limitations. For example, X-ray scanners and millimeter-wave imagers can indicate the presence of suspicious objects but often lack chemical specificity to confirm the presence of explosives29. Conversely, chemical detection techniques such as mass spectrometry, ion mobility spectrometry, and trained canine units require close proximity to the target, which is often impractical in dynamic or crowded environments. Furthermore, these approaches struggle to detect low-volatility explosives or those embedded in complex matrices, complicating reliable identification.
In light of these limitations, terahertz spectroscopy presents a promising alternative for accurate, stand-off detection of explosives. Of particular interest is terahertz time-domain spectroscopy (THz-TDS), which captures the time-resolved electric field of terahertz radiation, allowing for comprehensive material characterization over a broad spectral range. Numerous studies have shown that many explosives exhibit unique spectral fingerprints in the terahertz domain8,12,30,31,32, permitting their identification through distinct absorption features. Statistical techniques such as principal component analysis (PCA) have been employed to analyze terahertz absorbance spectra for the detection of explosives across varying concentrations33,34, and spectral images have been generated by mapping intensity at selected frequencies34,35,36. In addition, neural networks have been used to enhance target identification accuracy based on terahertz absorption features31,37,38. Despite these advancements, spectral methods relying on the terahertz power spectrum miss the spectral phase information. Thus, they remain susceptible to artifacts from multiple reflections, scattering, and environmental interferences. These effects can distort spectral signatures, even for identical materials. Puc et al.9 studied these challenges by covering explosive chemicals with paper and textiles and found that secondary reflections significantly altered the observed absorption peaks. To address this, time-domain analysis of the terahertz signal has been proposed as a way to mitigate such environmental artifacts. This approach enables the extraction of robust time-domain features for resolving explosive signatures, as demonstrated in recent studies39,40,41. When combined with machine learning, time-domain methods that analyze features such as the relative timing and ratio of reflected pulses can yield accurate classification results; however, their success is primarily limited to ideal samples with simple or controlled geometries42,43. Existing time-domain techniques have not yet achieved pixel-level chemical imaging and classification, which is an important capability to reveal the shape and position of the chemicals in the field of view. Therefore, while substantial progress has been made so far, a robust terahertz imaging system capable of accurate, stand-off explosive detection—independent of sample geometry, size, packaging, or environmental variability—remains a critical unmet need.
To address these challenges and detect concealed explosives, we developed a chemical imaging system that integrates THz-TDS with advanced deep learning techniques. This system enables accurate pixel-level identification of hidden explosives and operates in reflection mode, making it particularly well-suited for stand-off detection in real-world scenarios. A key enabler in the developed THz-TDS system is the use of plasmonic nanoantenna arrays for terahertz generation and detection44,45,46,47,48,49,50,51,52,53,54, which significantly enhance the signal-to-noise ratio compared to the state-of-the-art THz-TDS systems while providing a broad bandwidth (see Supplementary Fig. S1 and Supplementary Table S1). Operating in reflection mode, the THz-TDS system achieves a peak dynamic range of 96 dB and a detection bandwidth of 4.5 THz in 3 s. The terahertz beam is focused onto samples placed on a scanning stage, which is controlled by an XY motorized translation platform used for raster scanning. During the sample interrogation, the system collects multiple reflected pulses from different internal surfaces, analyzing each pulse individually, regardless of their time sequence. This pulse-resolved approach enables chemical identification at the pixel level that is robust to variations in sample geometry, size, and packaging. Compared to conventional methods that rely solely on power spectra, our approach analyzes terahertz time-domain pulses, capturing both amplitude and phase information. This comprehensive analysis enables more accurate identification of chemicals, including hidden explosives. The acquired temporal waveforms for each pixel of a sample field-of-view (FOV) are processed using deep learning models, including convolutional neural networks (CNNs) and transformer architectures, to automatically classify the chemical content of each pixel.
We experimentally demonstrated that our system was capable of detecting eight chemical species, including four pharmaceutical compounds—microcrystalline cellulose (MCC), dibasic calcium phosphate (DCP), mannitol (MAN), and ibuprofen (IBU)—and four explosives—potassium nitrate (KNO₃), pentaerythritol tetranitrate (PETN), cyclotrimethylene trinitramine (RDX), and trinitrotoluene (TNT). In blind testing experiments, the system achieved an average classification accuracy of 99.42% at the pixel level. To further assess the generalization capability of our system, we tested the detection of explosives concealed under paper coverings, yielding an average accuracy of 88.83%. By leveraging deep learning and advanced terahertz spectroscopic imaging, this system offers a highly sensitive and specific platform for rapid, stand-off chemical imaging and target detection. It holds strong potential for applications across pharmaceutical manufacturing, security screening, and industrial quality assurance.
Results
A schematic diagram and the operational principles of the terahertz time-domain spectroscopic imaging system are illustrated in Fig. 1a. The system is driven by a Ti:sapphire laser that generates 135 fs pulses at a central wavelength of 800 nm with a repetition rate of 76 MHz. The laser beam is split into two paths to independently pump and probe the photoconductive terahertz source and detector, both based on plasmonic nanoantenna arrays. Under an applied bias voltage, photo-generated carriers in the active area of the terahertz source drift toward the nanoantenna electrodes, producing sub-picosecond terahertz pulses54. At the detector, photo-generated carriers drift in response to the incident terahertz field, generating a photocurrent proportional to the field strength52. The plasmonic nanoantenna arrays enhance optical absorption near the electrodes through surface plasmon excitation, preserving high quantum efficiency and ultrafast response. This leads to efficient terahertz generation and highly sensitive detection. A mechanical optical delay line in one of the paths introduces a tunable time delay between the pump and probe beams. Terahertz radiation generated at the source is collimated using an off-axis parabolic mirror and then focused onto the sample using a second off-axis parabolic mirror, producing a beam spot with a 2-mm focal size. The sample is positioned on a metallic platform controlled by an XY motorized stage for spatial scanning. The reflected terahertz signal is directed to the detector via a terahertz beam splitter and subsequently focused onto the detector using another off-axis parabolic mirror. The time-domain terahertz electric field at each spatial point of the sample FOV is recorded by measuring the photocurrent from the terahertz detector as a function of the time delay introduced by the optical delay line. Applying a Fourier transform to the time-domain signal yields a broadband power spectrum extending up to 4.5 THz, with a peak dynamic range of 96 dB. This high peak dynamic range enables the robust detection of weak terahertz reflections from irregular and concealed samples in reflection mode. The performance of the system in transmission mode is also evaluated (see Supplementary Fig. S1). Each spectrum is acquired within an integration time of 3 s using pump and probe powers of 600 mW and 150 mW, respectively. The full time-domain response of the sample is obtained by raster scanning the sample FOV and acquiring 10,100 time-domain points at each spatial location.
a Schematic diagram of the terahertz time-domain spectroscopy-based chemical imaging system. The sample is mounted on a metallic stage controlled by a motorized translation stage for raster scanning. b Processing pipeline for chemical classification using terahertz spectral imaging. The workflow incorporates two neural networks: EdgeNet, which identifies sample boundaries/edges, and ClassNet, which performs chemical classification per pixel, generating a class map that preserves the spatial resolution of the edge map. Spatial post-processing in the form of pixel-level majority voting is also applied to enhance the classification accuracy of each chemical image
Using this terahertz spectroscopic imaging system, we analyzed a range of pharmaceutical and explosive materials. The four pharmaceutical compounds—MCC, DCP, MAN, and IBU—were compressed into cylindrical tablets using a hydraulic pellet press. Each tablet had a diameter of 10 mm, with thicknesses ranging from 2 to 4 mm. The four explosives examined—KNO₃, PETN, RDX, and TNT—were not suitable for high-pressure tablet formation due to explosion risk. Instead, they were mounted in an aluminum holder featuring a cylindrical cavity with a 10 mm diameter. The explosive samples placed in the holder had thicknesses between 2 and 4 mm. All samples were raster scanned over a 12 × 12 mm² area with a spatial step size of 1 mm. A 12 × 12 mm² area was scanned in ~447 s. This duration includes a 3-s acquisition time per pixel plus the time needed for stage movements between successive points.
Following data acquisition, the terahertz signals were processed using two dedicated neural networks—which we termed EdgeNet and ClassNet—for chemical identification and classification. Figure 1b illustrates the full data processing pipeline, encompassing the terahertz imaging, neural network inference, and spatial post-processing. First, the system acquires time-domain waveforms corresponding to each chemical sample. These pulses are then extracted and used as inputs to the two neural networks for edge detection and chemical classification.
EdgeNet functions as a binary classifier, distinguishing boundary pixels from non-boundary pixels to identify the presence or absence of edges within the sample FOV. At each pixel location, EdgeNet processes all the extracted terahertz pulses together to make its decisions. In parallel, ClassNet operates on an individual pulse basis, processing each pulse separately to generate probabilistic predictions for the chemical class, including the identification of the background sample holder (metal) if there is no sample for that pixel. For each pixel, these predictions are aggregated using a winner-takes-all strategy, where each pixel is assigned to the class with the highest predicted probability. Finally, the outputs of EdgeNet and ClassNet are integrated through a decision algorithm to determine the final classification of each pixel across the entire sample FOV. To further enhance our image-based classification accuracy, spatial majority voting and morphological operations are applied as post-processing steps (refer to Methods for details). These techniques incorporate local spatial context, helping to suppress inference artifacts and generate cleaner, more accurate chemical images that preserve the true spatial distribution of the material under test.
The distinct input structures for EdgeNet and ClassNet are custom tailored to their specific objectives. EdgeNet leverages the collective information from all the extracted terahertz pulses to make its decisions. This allows the network to identify complex temporal signatures, such as multiple reflections and scattering artifacts, that are characteristic of material boundaries. In contrast, for chemical classification, ClassNet processes each pulse individually, generating probabilistic predictions for the chemical class of each pixel, including the identification of the background sample holder. This approach was designed to preserve the unique spectral features within each reflection that are critical for identifying the chemical type of interest.
When the terahertz beam is focused onto a sample, as illustrated in Fig. 2a, multiple reflected pulses are captured in a single time-domain scan. Typically, four distinct pulses are observed in this reflection-mode setup, denoted as P1, P2, P3, and P4: P1 corresponds to the reflection from the sample’s top surface and contains surface reflectance information; P2 is the reflection from the metal substrate and does not carry chemical information; P3 arises from the sample’s bottom interface and contains key absorption features representative of the material; P4 and subsequent pulses are due to internal multiple reflections and also encode absorption characteristics of the sample under test. For reference, the pulse reflected from the metal background is nearly identical in shape to P2 (see Supplementary Fig. S2). While our analysis focuses on these four primary reflections, a time-domain trace can contain additional pulses. These typically arise from artifacts like edge scattering or from extra layers like a paper cover, which we will detail in subsequent measurements. The relative sequence and timing of these pulses vary depending on how the sample is positioned, and this information is assumed to be unknown to our neural networks.
a Reflected terahertz time-domain response from a KNO₃ sample. When the terahertz beam is incident near the sample edges, at least four distinct reflected pulses are observed. The first pulse (P1) corresponds to the reflection from the sample’s top surface; the second pulse (P2) originates from the metallic background (sample holder); the third pulse (P3) arises from the bottom interface of the sample; and the fourth one (P4) results from an internal reflection following two round trips within the sample. The inset shows the calculated terahertz absorption spectrum of KNO₃, derived from the third and second pulses. b–e Cropped waveforms of the four reflected pulses by pulse extraction algorithm in (a), each with a duration of 13 ps. After performing pulse extraction for every pixel across the 12 mm × 12 mm raster scan area, f–i represent the color maps of the peak amplitude values for each pulse (P1–P4)
While the material’s terahertz absorption spectrum can be obtained by calculating the Fourier transform of P3 relative to the reference pulse P2, as illustrated in the inset of Fig. 2a, directly applying a Fourier transform to the entire time-domain waveform can be unreliable, as interfering pulses may distort the spectral signatures. To mitigate this, we adopt a pulse-based chemical classification strategy. This approach significantly improves the robustness of inference by enabling classification that is insensitive to pulse order or temporal spacing—parameters that can fluctuate with changes in the sample geometry, placement, and packaging. Each full time-domain waveform per pixel is segmented into individual pulses with a duration of 13 ps, each consisting of 650 data points, as illustrated in Fig. 2b–e. The 13-ps time window is sufficient to capture a terahertz pulse and provides a spectral resolution of 76.9 GHz, which is adequate for our classification task. After performing the same pulse extraction for every pixel across the FOV, we take the peak amplitude value for each pulse (P1–P4) at each pixel to construct the 2D maps, as shown in Fig. 2f–i. The peak amplitudes of these pulses exhibit strong spatial correlation and track the geometry of the sample. This peak amplitude data is also central to our automated processing pipeline. For pulse extraction, a global detection threshold is applied to all waveforms to consistently identify potential pulses while rejecting noise. Following pulse extraction, the algorithm performs two labeling tasks to generate the training data. First, it categorizes each pulse—distinguishing between sample and background reflections—by using pulse timing in conjunction with prior knowledge of the sample’s structure (only used for training). Second, we determine a sample-specific amplitude threshold to identify edges; this value is set higher than the initial global detection threshold. Any pixel where the detected pulses fall below this second threshold is labeled as an “edge”, representing the weak scattering signals typical of sample boundaries (see Methods for details). These isolated pulses, without their relative time delay information, are used as individual inputs to a neural network trained to predict the chemical composition at each spatial location. This strategy enhances the system’s resilience to environmental variability and enables reliable, pixel-level chemical identification across diverse real-world scenarios, including concealed chemicals.
Figure 3 illustrates the architectures of the two neural networks used in our chemical imaging and classification pipeline: EdgeNet and ClassNet. EdgeNet (Fig. 3a) is designed for binary edge detection and is implemented using a 4-layer transformer encoder55. It accepts an input tensor of size 8 × 650, where each row corresponds to a distinct terahertz pulse; if less than 8 pulses are available per pixel, zeros are padded for the remaining pulse entries. Self-attention-based feature extraction is applied to extract features across the pulse set56, followed by a mean pooling operation along the sequence dimension. The resulting feature vector is passed through a fully connected layer to generate class probabilities indicating the presence or absence of an edge per pixel within the sample FOV. Notably, we did not incorporate temporal positional encoding, which is commonly used in transformer architectures, as the order of the input pulses may be unknown or not repeatable in real-world scenarios (e.g., for concealed chemicals). This design choice improves the model’s robustness to unknown variations in pulse ordering. The internal structure of the transformer encoder (Fig. 3b) consists of layer normalization, a multi-head self-attention mechanism, and a feedforward multilayer perceptron (MLP), connected through residual pathways to facilitate gradient flow. The multi-head attention module (Fig. 3c) comprises eight parallel attention heads (h = 8), each computing scaled dot-product attention over the input sequence.
a EdgeNet is built on a transformer backbone for edge detection; it outputs the probabilities of 2 classes: Edge/Other. b The internal structure of the transformer encoder, featuring a multi-head self-attention mechanism. c The schematic of a multi-head attention. d ClassNet, implemented using a CNN for multi-class chemical classification. EdgeNet leverages the global contextual modeling capabilities of transformers to accurately detect sample boundaries, while ClassNet utilizes the local feature extraction strengths of CNNs to enable efficient and robust chemical identification within the sample FOV. B: batch size
ClassNet (Fig. 3d), in contrast, is used for multi-class chemical classification at each pixel and is based on a CNN architecture57. It processes individual terahertz pulses through two 1D convolutional layers with ReLU activation and max pooling. The resulting feature maps are flattened and passed through two fully connected layers. A final softmax layer produces the probability distribution over the target chemical classes per pixel. Together, EdgeNet and ClassNet provide complementary capabilities—enabling accurate spatial boundary detection of the sample under test and robust pixel-level chemical classification within our spectroscopic imaging framework.
We trained both ClassNet and EdgeNet using pharmaceutical and explosive samples. To evaluate their generalization capability, the models were tested on entirely new, previously unseen samples and data. Figure 4 summarizes the blind classification results for these chemical test samples. In Fig. 4a, we present representative images of unknown chemical samples alongside the corresponding ground truth labels, model predictions before the spatial majority voting, and refined predictions after applying spatial majority voting for eight material classes: DCP, MCC, IBU, MAN, KNO₃, PETN, RDX, and TNT (see Methods for details). While the raw predictions from the two networks already demonstrated high classification performance, spatial majority voting further improved the results by mitigating spatially isolated pixel-level misclassifications, while also enhancing the edge detection accuracy, correctly revealing the boundaries of chemical objects. The overall pixel-level classification performance of our approach is quantitatively captured in the confusion matrix shown in Fig. 4b, which demonstrates consistent high accuracy across all chemical classes with minimal cross-class confusion. Specifically, the model achieved pixel-level classification accuracies of 99.48%, 98.26%, 100%, 100%, 100%, 100%, 99.57%, and 98.89% for DCP, MCC, IBU, MAN, KNO₃, PETN, RDX, and TNT, respectively. The average accuracy, including the background region (i.e., the sample holder, without a chemical), reached 99.42%. In addition, Fig. 4c demonstrates our model’s strong performance on spatially irregular and cracked test samples, even though it was trained exclusively on intact, regular samples. This successful generalization is rooted in our pulse-based approach. The full time-domain waveforms for intact versus cracked samples differ in pulse timing and relative amplitudes (see Supplementary Fig. S3). However, the characteristic shape of the crucial P3 pulse remains consistent between them. Because our network analyzes individual pulse shapes, it correctly identifies the material despite these structural irregularities. Furthermore, our model demonstrates its generalization capability by accurately predicting four different types of cracked pharmaceutical samples in the same FOV (see Supplementary Fig. S5). These results underscore the robustness of our classification pipeline, highlighting its ability to handle challenging and previously unseen sample conditions.
a Representative input images, ground truth labels, model predictions before spatial majority voting, and refined predictions after spatial majority voting for DCP, MCC, IBU, MAN, KNO₃, PETN, RDX, and TNT. b Confusion matrix summarizing the classification performance across all the chemical classes. c Ground truth and model predictions for cracked, irregularly shaped pharmaceutical samples, demonstrating the models’ ability to generalize to new test samples despite being trained exclusively on intact, regular samples
We further evaluated the performance of our classification pipeline on concealed chemical samples, where the substances were hidden beneath a visibly opaque paper cover and not detectable under standard illumination or visible or IR-based machine vision, as illustrated in Fig. 5. Importantly, the network models were trained exclusively on uncovered samples; thus, this evaluation tests their external generalization capability in realistic scenarios where chemical substances may be obscured within envelopes, packages/bags, or other visually inaccessible environments. Figure 5a shows a schematic of the experimental setup, in which each sample is covered/obscured by paper. Representative ground truth labels and our model predictions (after spatial majority voting) for four hidden explosives—KNO₃, PETN, RDX, and TNT—are shown in Fig. 5b. Despite the paper-based concealment, our models accurately recover the spatial distributions of these chemicals and specifically identify the type of chemicals.
a Schematic illustration of chemical classification through a visibly opaque paper cover; the explosive samples were hidden, i.e., remained undetected under visible illumination. b Ground truth labels and model predictions after spatial majority voting for KNO₃, PETN, RDX, and TNT. c Confusion matrix summarizing the classification performance for the concealed explosive samples. d Sample pictures with and without concealment, and our network predictions for a scenario involving multiple types of concealed chemicals within the same field of view. Note that the models were trained exclusively on uncovered samples
The confusion matrix in Fig. 5c summarizes the classification results, with the model achieving accuracies of 76.20% (KNO₃), 94.42% (PETN), 98.64% (RDX), and 87.90% (TNT). The average accuracy, including the background class, is 88.83%. Additionally, Fig. 5d showcases the model’s performance in a more complex scenario: identifying multiple types of chemicals concealed under a paper cover within the same FOV. While the cover introduces an additional reflection pulse (see Supplementary Fig. S4), the key pulses of interest retain their characteristic shapes after our extraction process. Consequently, the model successfully differentiates between all hidden chemical regions, highlighting its robustness and generalization under challenging and practically relevant imaging conditions.
Discussion
We developed a terahertz time-domain spectroscopic imaging system integrated with deep learning models to enable robust chemical classification of pharmaceutical and explosive materials. A step size of 1 mm was used for raster scanning, which represents a trade-off between the acquisition speed and the classification performance. A finer step size provides spatial redundancy that improves prediction accuracy through majority voting, whereas a larger step size reduces the scanning time at the cost of degraded performance (see Supplementary Fig. S6). We employed a pulse-based analysis method instead of using the full time-dependent spectrum to improve computational efficiency, model robustness, and signal fidelity. The full spectrum is computationally prohibitive due to its length and temporal sparsity, and the long-range dependencies between reflected pulses are poorly suited for standard 1D CNNs. Our pulse-based analysis strategy effectively decouples chemical identification from confounding physical variables like sample geometry, dimensions, and packaging. We achieve this by individually segmenting and analyzing each reflected terahertz pulse from the sample. The foundation of this approach is that a material’s characteristic pulse shape—which carries the essential chemical information—remains remarkably consistent, even if other factors like sample thickness or packaging change. This enables our network to accurately identify materials under previously unseen conditions. The collected individual pulses are used as independent inputs to train neural networks, which were employed for automated chemical classification and edge detection of unknown samples. Spatial majority voting and morphological operations were applied as post-processing steps to further enhance the classification performance of our chemical imaging system.
Our pipeline achieved high classification accuracy on various chemical samples, reaching an average accuracy of 99.42% across eight chemical classes and the background category. The trained models also demonstrated strong generalization capabilities to previously unseen conditions, such as cracked and spatially irregular samples, despite being trained exclusively on intact ones. Furthermore, we validated the system’s external generalization performance by testing it on concealed explosive chemicals hidden beneath opaque paper covers without knowing whether the pulse comes from the sample or the paper cover in the same scanned trace, achieving accurate classification even under these more challenging scenarios. Specifically, we trained the neural networks exclusively on visible samples while reserving concealed cases solely for blind testing. This strategy was adopted to more faithfully represent real-world scenarios, where concealment conditions are variable and often differ from any training set. By structuring the dataset in this way, we were able to rigorously evaluate the external generalization of our models under stringent and realistic conditions.
One limitation of the current study is that the models were trained solely on unconcealed (visible) samples, while the chemical classification of the concealed samples relied entirely on the model’s ability to generalize to new types of samples. Although our overall accuracy remained high for such concealed explosives, the performance for KNO₃ was notably lower than for other explosives, suggesting that certain chemicals may be more sensitive to concealment-related subtle signal variations. Future studies could explore the trade-off between overall generalization capability and the potential gains in robustness achieved by augmenting the training set with concealed or partially obscured samples, which may improve model performance under more diverse and realistic conditions. While our method successfully identifies multiple spatially distinct chemicals in the same FOV, another potential future direction is the quantitative analysis of the concentrations of co-localized mixtures within a single pixel. Future development could focus on a cascaded framework to first detect the presence of a mixture and then estimate constituent concentrations of each chemical that is identified. Additionally, optimizing network architectures or incorporating self-supervised pretraining strategies may reduce the dependence on large labeled datasets. Expanding the diversity of the training dataset—by adding more chemical types, irregular sample geometries, or varied concealment/packaging materials—would further strengthen the classification accuracy of the proposed system.
Our pulse-based terahertz imaging method provides a powerful tool for obtaining critical chemical intelligence in a non-contact manner. While data acquisition for a 12 × 12 mm² area takes approximately ~7.5 min (~447 s), the subsequent post-processing and pixel-level classification by the neural network are completed in just one second. This capability for non-destructive imaging followed by near-instantaneous digital analysis is ideal for applications in e.g., pharmaceutical quality control and security screening. The system enables the non-destructive analysis of individual tablets and capsules, potentially allowing for the verification of active ingredients and the detection of counterfeit drugs. In the security and forensic domain, it could be used for identifying trace explosives or illicit substances collected on swabs and for inspecting suspicious powders or stains in mail. This provides a powerful tool for obtaining critical chemical intelligence in a non-contact manner.
While the proof-of-concept experiments presented here rely on mechanical raster scanning to capture 2D chemical images, this requirement can be eliminated by replacing the single-pixel terahertz detector with a terahertz focal-plane array based on plasmonic nanoantenna arrays58,59. This advancement could enable significantly faster imaging and reduce the system’s complexity, size, and weight, while preserving the high signal-to-noise ratio and broad bandwidth necessary for accurate spectroscopic analysis and chemical imaging.
Overall, this study demonstrates a powerful framework for terahertz-based chemical imaging, offering a promising pathway toward robust, high-accuracy classification of chemicals in both controlled and operational environments where concealment, packaging, and sample variability pose major challenges. This framework holds strong potential for various applications in e.g., security screening, pharmaceutical quality control, and non-destructive testing, where rapid and reliable material identification is critical.
Materials and methods
Terahertz time-domain spectroscopy system
A mode-locked Ti: sapphire laser (Coherent Mira 900) was used to generate an optical pulse train with a repetition rate of 76 MHz, a central wavelength of 800 nm, and a pulse width of 135 fs. The laser output was split into pump and probe beams using an optical beam splitter. The femtosecond optical pump beam illuminates the photoconductive antenna, generating photocarriers, where the optical absorption is further enhanced by the custom-designed plasmonic structure. An external bias voltage is applied to accelerate these carriers, producing an ultrafast photocurrent that radiates broadband terahertz pulses. The bias voltage is modulated at 100 kHz to enable lock-in detection. The probe beam was routed through an optical delay line (Newport DL125) to a plasmonic photoconductive terahertz detector. The optical powers incident on the emitter and detector were 600 mW and 150 mW, respectively. Terahertz radiation emitted from the source was collimated using a gold-coated off-axis parabolic mirror and subsequently focused onto the sample using a second gold-coated off-axis parabolic mirror. The focused terahertz beam had a spot diameter of ~2 mm at the sample location. The sample was mounted on a copper platform attached to a motorized stage, allowing raster scanning with a step size of 1 mm. Reflected terahertz radiation from the sample was redirected using a 50/50 terahertz beam splitter and focused onto the detector via an additional off-axis parabolic mirror. Similar to terahertz generation, the femtosecond probe beam generates photocarriers in the active area of the photoconductive terahertz detector. The electric field of the incident terahertz pulse acts as a transient bias, accelerating these photocarriers to the antenna electrodes. This acceleration induces a photocurrent that is directly proportional to the terahertz electric field’s amplitude at the precise instant the probe beam arrives. By varying the optical path length between the two branches with the delay line, the time-domain terahertz electric field was retrieved by measuring the photocurrent generated in the terahertz detector. This photocurrent was converted to a voltage and amplified using a transimpedance amplifier (DLPCA-200, FEMTO). The output voltage was then fed into a digital lock-in amplifier (MFLI, Zurich Instruments), and the resulting data were transferred to a computer for post-processing and analysis.
Preparation of chemical samples
The four pharmaceutical materials used in this study were microcrystalline cellulose (VIVAPUR 200), dibasic calcium phosphate dihydrate (EMCOMPRESS), mannitol (PEARLITOL 100 SD), and ibuprofen (DC 100). Each pharmaceutical powder was compressed into a cylindrical tablet using a hydraulic press. The resulting tablets had a diameter of 10 mm and a thickness ranging from 2 mm to 4 mm. The four explosives examined were potassium nitrate (Lab Alley, powder, USP/ACS/FCC grade), pentaerythritol tetranitrate (Dyno Nobel Inc., R24010), cyclotrimethylene trinitramine (Dyno Nobel Inc., ME006), and trinitrotoluene (Dyno Nobel Inc., ME001CA). These materials were placed in a custom-fabricated aluminum mount featuring a central cylindrical hole with a diameter of 10 mm and a depth of 5 mm. For measurements involving concealed explosives, the samples were placed on a polyethylene sheet and enclosed within a plastic square frame to enable the placement of two samples within the FOV. The square frame, fabricated via 3D printing, had a width of 10 mm and a depth of 3 mm. A paper cover with a thickness of 0.18 mm was shaped into a rectangular box with a lateral size of 35 mm × 35 mm and a height of 10 mm to conceal the samples during testing.
Pulse extraction and training data generation
We automatically extract individual pulses from each time-domain waveform using a peak detection function configured with an 8% amplitude threshold (relative to a reference reflection from background region) and a minimum separation of 650 data points, which corresponds to 13 ps. After the pulse extraction step, we perform a semi-automated labeling process for network training and label creation. We first identify the background-reflected pulse (P2) by its consistent arrival time across the scanned area and label it as “background”. All other detected pulses (e.g., P1, P3, P4) are assigned a specific chemical label based on a priori knowledge of the sample being scanned. However, signals at the sample boundaries are dominated by scattering and are significantly weaker than reflections from the sample’s center. Since different chemicals exhibit varying reflectance and transmission properties, the absolute intensity of these edge-scattering artifacts varies depending on the material. To account for this, we determine an amplitude threshold by analyzing the peak intensity distribution of each material. This threshold is set higher than the initial noise-rejection threshold but lower than the typical bulk sample intensity. Consequently, any pixel containing pulses that are detected but fall below this second threshold is labeled as an “edge”. The final output is a training dataset composed of these labeled, isolated pulses, which are collectively used to train and validate the neural network for pixel-level classification of chemical types, edges, and background.
Integrated chemical classification pipeline and spatial post-processing of chemical images
EdgeNet identifies edge pixels by analyzing spatial boundary information across all the detected pulses (per pixel), whereas ClassNet operates on individual pulses to generate per-pixel chemical class probabilities. The outputs from EdgeNet and ClassNet are integrated via a conditional decision rule. Specifically, pixels identified by EdgeNet as potential edges and simultaneously exhibiting a maximum class probability (assigned by ClassNet) below a predefined threshold (empirically set to 0.95) are classified as “Edge.” All other pixels retain their original labels assigned by ClassNet. This integrated inference procedure is applied iteratively across the entire sample FOV to generate an initial chemical classification map. To reduce potential misclassifications and further enhance inference robustness, a post-processing step is performed that incorporates spatial majority voting and morphological filtering. Majority voting is applied within a 3 × 3 neighborhood of each pixel to enforce local consistency. Morphological operations based on eight connected pixel structures are then used to eliminate spatially isolated errors and remove spurious regions. This refinement step yields spatially consistent classification results, producing chemical images that more accurately represent the true spatial distribution and identity of the target substances across the sample FOV.
Model training setup
EdgeNet and ClassNet were trained separately using Python (v3.8.16) and PyTorch (v1.11, Meta AI) on a workstation equipped with a GeForce RTX 3090 GPU (Nvidia Corp.), an Intel® Core™ i9-12900KF CPU (Intel Corp.), and 64 GB of RAM, running Windows 11 (Microsoft Corp.). Each model was independently optimized using the Adam optimizer60 with a learning rate of 1 × 10−3. Training was performed over 200 epochs with a batch size of 64, requiring ~1.5 h for ClassNet and 2.5 h for EdgeNet.
Data availability
All the data and methods needed to evaluate the conclusions of this work are present in the main text and Supplementary Information. Additional data are available from the corresponding authors upon request. All the deep-learning models used in this work employ standard libraries and scripts that are publicly available in PyTorch.
References
Yang, X. et al. Biomedical applications of terahertz spectroscopy and imaging. Trends Biotechnol. 34, 810–824 (2016).
Sun, Q. S. et al. Recent advances in terahertz technology for biomedical applications. Quant. Imaging Med. Surg. 7, 345–355 (2017).
Cong, M. Y. et al. Biomedical application of terahertz imaging technology: a narrative review. Quant. Imaging Med. Surg. 13, 8768–8786 (2023).
Kemp, M. C. et al. Security applications of terahertz technology. In Proceedings of SPIE 5070, Terahertz for Military and Security Applications (SPIE, 2003).
Grossman, E. et al. Passive terahertz camera for standoff security screening. Appl. Opt. 49, E106–E120 (2010).
Tzydynzhapov, G. et al. New real-time sub-terahertz security body scanner. J. Infrared Millim. Terahertz Waves 41, 632–641 (2020).
Federici, J. F. et al. THz imaging and sensing for security applications—explosives, weapons and drugs. Semiconductor Sci. Technol. 20, S266–S280 (2005).
Kemp, M. C. Explosives detection by terahertz spectroscopy—a bridge too far? IEEE Trans. Terahertz Sci. Technol. 1, 282–292 (2011).
Puc, U. et al. Terahertz spectroscopic identification of explosive and drug simulants concealed by various hiding techniques. Appl. Opt. 54, 4495–4502 (2015).
Palka, N. THz reflection spectroscopy of explosives measured by time domain spectroscopy. Acta Phys. Polonica A 120, 713–715 (2011).
Alexander, N. E. et al. Tera SCREEN: multi-frequency multi-mode Terahertz screening for border checks. In Proceedings of SPIE 9078, Passive and Active Millimeter-Wave Imaging XVII, 907802 (SPIE, 2014).
Davies, A. G. et al. Terahertz spectroscopy of explosives and drugs. Mater. Today 11, 18–26 (2008).
Trofimov, V. A. & Vorontsova, S. A. Efficiency of using the spectral dynamics analysis for pulsed THz spectroscopy of both explosive and other materials. In Proceedings of SPIE 9454, Detection and Sensing of Mines, Explosive Objects, and Obscured Targets XX, 945409 (SPIE, 2015).
Chen, Y. et al. Terahertz spectroscopic uncertainty analysis for explosive mixture components determination using multi-objective micro-genetic algorithm. Adv. Eng. Softw. 42, 649–659 (2011).
Moradikouchi, A. et al. Terahertz frequency-domain sensing combined with quantitative multivariate analysis for pharmaceutical tablet inspection. Int. J. Pharm. 632, 122545 (2023).
Bawuah, P. et al. Terahertz study on porosity and mass fraction of active pharmaceutical ingredient of pharmaceutical tablets. Eur. J. Pharm. Biopharm. 105, 122–133 (2016).
Moradikouchi, A. et al. Terahertz frequency domain sensing for fast porosity measurement of pharmaceutical tablets. Int. J. Pharm. 618, 121579 (2022).
Bawuah, P. et al. Terahertz-based porosity measurement of pharmaceutical tablets: a tutorial. J. Infrared Millim. Terahertz Waves 41, 450–469 (2020).
Afsah-Hejri, L. et al. A comprehensive review on food applications of terahertz spectroscopy and imaging. Compr. Rev. Food Sci. Food Saf. 18, 1563–1621 (2019).
Mathanker, S. K., Weckler, P. R. & Wang, N. Terahertz (THz) applications in food and agriculture: a review. Trans. ASABE 56, 1213–1226 (2013).
Afsah-Hejri, L. et al. Terahertz spectroscopy and imaging: a review on agricultural applications. Comput. Electron. Agric. 177, 105628 (2020).
Browne, M. et al. Prediction of leaf water potential and relative water content using terahertz radiation spectroscopy. Plant Direct 4, e00197 (2020).
Harding, G. X-ray scatter tomography for explosives detection. Radiat. Phys. Chem. 71, 869–881 (2004).
Partridge, T. et al. Enhanced detection of threat materials by dark-field x-ray imaging combined with deep neural networks. Nat. Commun. 13, 4651 (2022).
Martin, C. A. et al. High-resolution passive millimeter-wave security screening using few amplifiers. In Proceedings of SPIE 6548, Passive Millimeter-Wave Imaging Technology X, 654806 (SPIE, 2007).
Yinon, J. Analysis and detection of explosives by mass spectrometry. In Aspects of Explosives Detection (eds, Marshall, M. & Oxley, J. C.) Ch. 8, 147–169 (Elsevier, 2009).
Buryakov, I. A. Detection of explosives by ion mobility spectrometry. J. Anal. Chem. 66, 674–694 (2011).
Shahraki, H., Tabrizchi, M. & Farrokhpor, H. Detection of explosives using negative ion mobility spectrometry in air based on dopant-assisted thermal ionization. J. Hazard. Mater. 357, 1–9 (2018).
Caygill, J. S., Davis, F. & Higson, S. P. J. Current trends in explosive detection techniques. Talanta 88, 14–29 (2012).
Ball, C. D., Ronningen, T. J. & Oesterling, L. C. Terahertz spectral signatures of explosive materials and precursors. In Proceedings of SPIE 7324, Atmospheric Propagation VI, 73240Z (SPIE, 2009).
Zhou, Q. L. et al. Studies on the detection and identification of the explosives in the terahertz range. In Proceedings of SPIE 6840, Terahertz Photonics, 68400Z (SPIE, 2008).
Chen, J. et al. Absorption coefficients of selected explosives and related compounds in the range of 0.1-2.8 THz. Opt. Express 15, 12060–12067 (2007).
Demirağ, Y., Bütün, B. & Özbay, E. Plasmonic enhanced terahertz time-domain spectroscopy system for identification of common explosives. In Proceedings of SPIE 10210, Next-Generation Spectroscopic Technologies X, 1021012 (SPIE, 2017).
Sleiman, J. B. et al. Qualitative and quantitative analysis of explosives by terahertz time-domain spectroscopy: application to imaging. In Proceedings of the 2014 39th International Conference on Infrared, Millimeter, and Terahertz waves (IRMMW-THz), 1-2 (IEEE, 2014).
Startsev, M. A. & Elezzabi, A. Y. Terahertz frequency continuous-wave spectroscopy and imaging of explosive substances. Int. Sch. Res. Not. 2013, 419507 (2013).
Fischer, B. et al. Chemical recognition in terahertz time-domain spectroscopy and imaging. Semiconductor Sci. Technol. 20, S246–S253 (2005).
Liu, W. T., Li, J. W. & Yang, W. Detection and identification of explosives and illicit drugs by terahertz spectroscopy technology. In Proceedings of the 2010 IEEE International Geoscience and Remote Sensing Symposium, 3576–3579 (IEEE, 2010).
Cielecki, P. P., Kristensen, M. H. & Skovsen, E. Analysis and classification of frequency-domain terahertz reflection spectra using supervised and unsupervised dimensionality reduction methods. J. Infrared Millim. Terahertz Waves 42, 1005–1026 (2021).
Zhang, Z. W. et al. Terahertz time-domain spectroscopy for explosive imaging. Optik 118, 325–329 (2007).
Trofimov, V. A. & Varentsova, S. A. A possible way for the detection and identification of dangerous substances in ternary mixtures using THz pulsed spectroscopy. Sensors 19, 2365 (2019).
Shen, Y. C. et al. Detection and identification of explosives using terahertz pulsed spectroscopic imaging. Appl. Phys. Lett. 86, 241116 (2005).
Cacciari, I. & Corradi, G. Common plastics THz classification via artificial neural networks: a discussion on a class of time domain features. Optical Mater. 117, 111134 (2021).
Ehrhorn, M. Terahertz Spectroscopy Under Extreme Conditions. PhD thesis (Technical University of Denmark, 2025).
Lu, P. K. et al. Bias-free terahertz generation from a silicon-compatible photoconductive emitter operating at telecommunication wavelengths. Appl. Phys. Lett. 120, 261107 (2022).
Lu, P. K., Turan, D. & Jarrahi, M. High-power terahertz pulse generation from bias-free nanoantennas on graded composition InGaAs structures. Opt. Express 30, 1584–1598 (2022).
Yardimci, N. T., Turan, D. & Jarrahi, M. Efficient photoconductive terahertz detection through photon trapping in plasmonic nanocavities. APL Photonics 6, 080802 (2021).
Turan, D. et al. Wavelength conversion through plasmon-coupled surface states. Nat. Commun. 12, 4641 (2021).
Turan, D., Yardimci, N. T. & Jarrahi, M. Plasmonics-enhanced photoconductive terahertz detector pumped by Ytterbium-doped fiber laser. Opt. Express 28, 3835–3845 (2020).
Yardimci, N. T. et al. A high-responsivity and broadband photoconductive terahertz detector based on a plasmonic nanocavity. Appl. Phys. Lett. 113, 251102 (2018).
Turan, D. et al. Impact of the metal adhesion layer on the radiation power of plasmonic photoconductive terahertz sources. J. Infrared Millim. Terahertz Waves 38, 1448–1456 (2017).
Yardimci, N. T. et al. A high-power broadband terahertz source enabled by three-dimensional light confinement in a plasmonic nanocavity. Sci. Rep. 7, 4166 (2017).
Yardimci, N. T. & Jarrahi, M. High sensitivity terahertz detection through large-area plasmonic nano-antenna arrays. Sci. Rep. 7, 42667 (2017).
Yardimci, N. T., Lu, H. & Jarrahi, M. High power telecommunication-compatible photoconductive terahertz emitters based on plasmonic nano-antenna arrays. Appl. Phys. Lett. 109, 191103 (2016).
Yardimci, N. T. et al. High-power terahertz generation using large-area plasmonic photoconductive emitters. IEEE Trans. Terahertz Sci. Technol. 5, 223–229 (2015).
Dosovitskiy, A., Beyer, L. & Kolesnikov, A. An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale. In International Conference on Learning Representations (ICLR), (ICLR, 2021).
Vaswani, A. et al. Attention is all you need. In Proceedings of the 31st International Conference on Neural Information Processing Systems, 6000–6010 (Curran Associates Inc., 2017).
O’Shea, K. & Nash, R. An introduction to convolutional neural networks. arXiv Preprint at https://doi.org/10.48550/arXiv.1511.08458 (2015).
Li, X. R. et al. Plasmonic photoconductive terahertz focal-plane array with pixel super-resolution. Nat. Photonics 18, 139–148 (2024).
Li, X. R. et al. High-throughput terahertz imaging: progress and challenges. Light Sci. Appl. 12, 233 (2023).
Kingma, D. P. & Ba, J. Adam: a method for stochastic optimization. In 3rd International Conference on Learning Representations (OpenReview.net, 2015).
Acknowledgements
The authors acknowledge funding from the DARPA FLEX Program Award # HR0011-24-2-0353. Development of the plasmonic nanoantenna arrays used in this work was supported by the Department of Energy (grant # DE-SC0016925).
Author information
Authors and Affiliations
Contributions
X.J. built the THz-TDS setup, prepared the chemical samples, performed the experiment, and collected data. Yuhang L., Yuzhu L. and C.S. developed the deep learning models and carried out data processing. A.O. and M.J. initiated and supervised the research. All authors contributed to the preparation of the manuscript.
Corresponding authors
Ethics declarations
Conflict of interest
M.J. is a co-founder of Lookin Inc. Aydogan Ozcan is an Editor for the journal. The other authors do not have conflicts of interest related to the contents of this manuscript.
Supplementary information
41377_2026_2190_MOESM1_ESM.pdf
Supplementary materials for Detection and imaging of chemicals and hidden explosives using terahertz time-domain spectroscopy and deep learning
Rights and permissions
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.
About this article
Cite this article
Jiang, X., Li, Y., Li, Y. et al. Detection and imaging of chemicals and hidden explosives using terahertz time-domain spectroscopy and deep learning. Light Sci Appl 15, 80 (2026). https://doi.org/10.1038/s41377-026-02190-z
Received:
Revised:
Accepted:
Published:
Version of record:
DOI: https://doi.org/10.1038/s41377-026-02190-z







