Introduction

Spectrometers play a crucial role in scientific research and numerous industrial applications1,2. However, traditional spectrometers typically comprise bulky mechanical parts such as optical gratings and Michelson interferometers3. Therefore, the miniaturization of spectrometers while retaining high spectral resolution, broad spectrum sensing, and fast response, at low cost, is a subject of intense research interest due to potential applications in portable and wearable optoelectronics4,5,6,7,8,9,10,11,12,13,14,15. Common spectrometer miniaturization strategies rely on integrated detector arrays and separate optical elements with wavelength-dependent optical properties, including compact interferometers4,12,16, quantum dots5,12, photonic crystals8,10, and metasurfaces6,13,17. Despite recent advances, miniaturizing these spectrometers down to the micrometer scale remains challenging due to limitations imposed by the optical path length11. Recently, a computational spectroscopy technology that leverages reconstructive mathematical algorithms has been established, allowing for the fabrication of detector-only spectrometers without separate optics. These approaches include various photodetectors and photodetector arrays such as bandgap engineered nanowire arrays14,18, and two-dimensional (2D) van der Waals (vdW) materials7 and heterostructures11,15 with gate-tunable and wavelength-dependent photoresponsivity. However, the commercialization and practical applications of miniaturized spectrometers and imaging systems rely on their integration with silicon chips19,20, which are often constructed with von Neumann architectures21 where the spectral sensing, storage, and processing modules are spatially separated22. This leads to high energy consumption23 and slow processing speeds due to the storage-wall problem24.

In this work, we demonstrate the possibility of fabricating a miniaturized spectrometer using a single SnS2/ReSe2 vdW heterostructure with the capabilities of photodetection, spectrum reconstruction, spectral imaging, and detectivity within the visible spectral range. By leveraging the gate-tunable photoresponse, reconstructive algorithms, and compressed sensing methodologies, we demonstrate a miniaturized spectrometer and spectral imager with a footprint of merely 19 μm, a bandwidth from 400 to 800 nm, a spectral resolution of 5 nm, and a 104 s long-term image memory. Additionally, our miniaturized spectrometer not only serves as storage but also has processing capabilities when alternate laser and gate pulses are applied. Our approach represents a significant step towards single-detector computational spectrometers beyond von Neumann architectures.

Results

Device arrangement and photocurrent mechanism

Figure 1a displays a vertically stacked SnS2/ReSe2 heterostructure, used in this experiment with an active region of approximately 28-nm-thick SnS2 and 40-nm-thick ReSe2 (Supplementary Fig. 1). The vdW flakes were mechanically exfoliated from high quality single crystals, verified by Raman spectroscopy and high-resolution transmission electron microscopy (HRTEM) characterization (Fig. 1b–d). The overlapped region (green plot) exhibited both materials’ characteristic Raman peaks, indicating the presence of two distinct materials25,26,27,28. The contact interface showed a typical type-II band structure (Supplementary Figs. 2 and 3) and the individual SnS2 and ReSe2 both showed strong light absorption within the visible spectrum range (Supplementary Fig. 4), resulting a strong photoresponse to visible light. Our vdW heterostructure device achieves a large photocurrent (Iph) of approximately 0.6 μA (Fig. 1e), with the highest photoresponsivity (R) calculated to be approximately 200 A/W at a gate voltage (Vg) of 50 V and an incident laser power density (Pin) of 0.22 mW/cm2 (Supplementary Fig. 5). The device exhibited a high specific detectivity (D*) of 3.4 × 1012 cm Hz1/2 W−1 due to its ultralow dark current in the off state (Vg < 2 V, Supplementary Fig. 5). The photocurrent of our device increased linearly with incident light power in the low power density range (<0.8 mW/cm2), and its slope depends on the gate voltage (Fig. 1g), laying an important foundation for its application in spectrometry, as discussed later14.

Fig. 1: Characterization of van der Waals (vdW) spectrometers.
figure 1

a Schematic of the vertically stacked SnS2/ReSe2 vdW heterostructure device on a gated Si/SiO2 substrate. Vds: drain-source voltage; Vg: gate voltage. In the upper right is an optical image of the device with a 5 μm scale bar. b Raman spectra of a SnS2/ReSe2 heterostructure in different regions. The vertical dashed lines highlight the positions of corresponding Raman peaks. c High-resolution transmission electron microscopy (HRTEM) image of mechanically exfoliated SnS2 and (d) ReSe2 layers, where red arrows highlight the positions of vacancies. The insets show the corresponding selected area electron diffraction (SAED) images. Scale bar for HRTEM, 2 nm. Scale bar for SAED, 2 nm−1. e Transfer curves of the device for 635 nm laser illumination with different incident power densities (Pin) at Vds = 1 V. f Photocurrent (Iph) as a function of light wavelength at various gate voltages from −20 V to 20 V. The Iph are normalized to the maximum values at each Vg. Solid lines are guides to the eye (adjacent-averaging smoothing of the data points). g Photocurrent of the device as a function of laser power density at different gate voltages. Solid lines are linear fittings to the corresponding data points.

Interestingly, photocurrent peaks were observed in the spectrum, which moved from ~580 nm to ~670 nm when the gate voltage was increased from −20 V to 20 V (Fig. 1f). Scanning photocurrent maps under 532, 633, and 785 nm laser illuminations for a fixed laser power of 0.5 mW (Fig. 2a) showed that the SnS2 and ReSe2 regions’ photocurrent decreased with λ, while the photocurrent in the junction area exhibited a peak (Fig. 2b–d). This indicates that the SnS2 and ReSe2 interface dominates the photon absorption and energy conversion process. Moreover, the photocurrent of the junction area is even greater than the sum of the photocurrent in the SnS2 and ReSe2 regions, pointing to the junction’s essential role in establishing the photocurrent. TEM analysis and XPS characterization suggest that our SnS2 possesses ~2% sulfur vacancies, while the ReSe2 has ~2.4 % Re vacancies (Fig. 1c, d and Supplementary Fig. 6). First-principle calculations reveal Re vacancies result in the appearance of three defect bands, labeled DFR1 (0.26 eV below bottom of conduction band (CB)), DRR2 (0.49 eV below the bottom of CB), and DFR3 (0.37 eV above the top of the valence band (VB)). In the case of SnS2 with sulfur vacancies, a single defect band (DFS) emerges, positioned 0.7 eV below the bottom of the CB (Supplementary Fig. 7). Moreover, due to the upward bending of the energy band, hole trapping plays a unique role in the overlapping region as excited holes will move to the overlapped region and electrons move to the nonoverlapped region (Fig. 2e and Supplementary Fig. 8f). Thus, under illumination, holes are excited and move to the overlapping region and some of the holes will be trapped by DFR3, resulting a photogating effect, which would have the effect of enhancing the photocurrent. When the light is switched off, the trapped holes remain and sustain the photocurrent, resulting in a memory effect. This is also key to the electrically tunable memory effect, discussed further in the paper. Moreover, the interfacial trap states, such as neutral traps (NT), are generally observed in 2D heterostructures during the stacking process, which also result in photogating and memory effects (Supplementary Fig. 9). Details of the calculation can be found in Supplementary Note 1. For photodetectors dominated by a photogating effect29, the photocurrent in the interface (\({I}_{{{{{{\rm{interface}}}}}}}\)) can be written as \({I}_{{{{{{\rm{interface}}}}}}}=\frac{\partial {I}_{{{{{{\rm{ds}}}}}}}}{\partial {V}_{{{{{{\rm{g}}}}}}}}\triangle {V}_{{{{{{\rm{g}}}}}}}\), where \(\triangle {V}_{{{{{{\rm{g}}}}}}}\) is the local gate voltage generated by photoexcited carrier trapping at the interface30. In Fig. 2f, the calculated \(\triangle {V}_{{{{{{\rm{g}}}}}}}\) is shown to decrease with increasing gate voltage. We would like to stress that the number of holes trapped depends on the built-in potential at ReSe2 (\({V}_{{{{{{\rm{biR}}}}}}}\)). Increasing Vg, \({V}_{{{{{{\rm{biR}}}}}}}\) decreases, resulting in a decrease in the number of trapped holes, which is consistent with the experimental results. The total photocurrent (\({I}_{{{{{{\rm{ph}}}}}}}\)) has three main contributions: the photocurrents generated in the ReSe2 (\({I}_{{{{{{\rm{R}}}}}}}\)) and SnS2 regions (\({I}_{{{{{{\rm{S}}}}}}}\)), and the photocurrent generated in the overlapping region (\({I}_{{{{{{\rm{interface}}}}}}}\)) due to the photogating effect. As the Au electrode has a much greater work function in comparison with both SnS2 and ReSe2, the built-in potential between Au and ReSe2 (\({\phi }_{{{{{{\rm{B}}}}}}1}\)) is greater than \({V}_{{{{{{\rm{biR}}}}}}}\). Thus, \({I}_{{{{{{\rm{S}}}}}}}\) and \({I}_{{{{{{\rm{R}}}}}}}\) are in opposite directions. Therefore,\(\,{I}_{{{{{{\rm{ph}}}}}}}={I}_{{{{{{\rm{S}}}}}}}-{I}_{{{{{{\rm{R}}}}}}}+{I}_{{{{{{\rm{interface}}}}}}}\). Moreover, \({I}_{{{{{{\rm{interface}}}}}}}=\frac{\partial {I}_{{{{{{\rm{ds}}}}}}}}{\partial {V}_{{{{{{\rm{g}}}}}}}}\triangle {V}_{{{{{{\rm{g}}}}}}}\) is almost constant when far from the photocurrent peak (15 V in Fig. 2f). Thus, the peak of photocurrent can be explained by \({{|I}}_{{{{{{\rm{S}}}}}}}-{I}_{{{{{{\rm{R}}}}}}}|\). Figure 2c plots the \({I}_{{{{{{\rm{R}}}}}}}-{I}_{{{{{{\rm{S}}}}}}}\) and it does show a peak around 600 nm, which is consistent with the photocurrent of the device. Moreover, the built-in potential of the SnS2 side decreases the most with increasing Vg and that in the ReSe2 side remains quite stable (Supplementary Fig. 8e). In other words, the photocurrent decreases much faster with increasing Vg (Supplementary Note 2). Thus, the peak position of the photocurrent moves to longer wavelength with increasing Vg, which is consistent with the experimental observation (Fig. 2f).

Fig. 2: Mechanism of photocurrent.
figure 2

a Scanning photocurrent maps of the heterostructure under 532, 635, and 785 nm (from left to right) laser illumination. Solid and dashed lines show the outlines of SnS2 and ReSe2, respectively. Colored circles indicate typical ReSe2 (blue), heterojunction (red), and SnS2 (green) regions, respectively. Scale bar, 5 μm. bd Photocurrent in the heterostructure extracted from the regions indicated by the corresponding colored circles in (a) as a function of laser wavelength. \({I}_{{{{{{\rm{R}}}}}}}\) and \({I}_{{{{{{\rm{S}}}}}}}\) represent the photocurrents generated in the ReSe2 and SnS2 regions, respectively. e Schematic diagram showing the trap states induced photogating effect. \({\phi }_{{{{{{\rm{B}}}}}}1}\) and \({\phi }_{{{{{{\rm{B}}}}}}2}\) are the built-in potentials between Au and ReSe2 and SnS2, respectively; \({V}_{{{{{{\rm{bi}}}}}}}\) is the built-in potential at the interface of ReSe2 and SnS2; CB and VB represent conduction band and valence band, respectively; \(h\upsilon\) represents the incident photon energy; EF is the fermi level; DFS is the defect band with S vacancies in SnS2; DFR1, DFR2, and DFR3 are three defect bands with Re vacancies in ReSe2. Solid and empty circles represent electrons and holes, respectively. Black straight arrows indicate the directions of \({I}_{{{{{{\rm{R}}}}}}}\) and and \({I}_{{{{{{\rm{S}}}}}}}\); black dotted arrows indicate the excitation of electrons (holes); green curved arrows represent the movement of electrons (holes); double curved arrows indicate the incident photons. f Calculated local gate voltage generated by photoexcited carrier trapping at the interface (\(\triangle {V}_{{{{{{\rm{g}}}}}}}\)) as a function of laser wavelengths at different gate voltages.

Spectrum reconstruction

The fabricated SnS2/ReSe2 heterostructure exhibits a gate-tunable spectral response with high responsivity and detectivity across a wide range of wavelengths, making it suitable for use as a spectrometer1. The reconstruction process is briefly outlined in Fig. 3 (see Supplementary Fig. 10 for a detailed workflow diagram). In the non-saturated region (linear region, as shown in Fig. 1g) at a given gate voltage (denoted as Gi), the photocurrent (Ii) can be calculated as an integral of the product of the incident light power density (P(λ)) and the responsivity (Ri(λ)) over the entire spectral range of interest from λ1 to λ2:

$${\int }_{{\lambda }_{1}}^{{\lambda }_{2}}P\left(\lambda \right){R}_{i}\left(\lambda \right)={I}_{i}\,\left(i=1,2,3\ldots,n\right)$$
(1)

where λ1 and λ2 define the operational spectral range of the spectrometer and index i implies different gate voltage values. Here, the unknown spectrum to be determined is denoted by P(λ) and is schematically illustrated by an arbitrary narrowband emission spectrum, represented by the dashed line curve in Fig. 3a. Additionally, three representative responsivity curves corresponding to the three different gate voltages (Gi, Gj and Gk) are sketched in Fig. 3a. Using Eq. (1), we can calculate the photocurrent of the device for a given gate voltage, determined by the integral of the shaded area in Fig. 3b. Figure 3c shows the measured photocurrents at all different gate voltages, where Gi, Gj and Gk are highlighted in different colors. By varying the gate voltage from G1 to Gn, we obtain n integral equations that consider small windows of wavelengths in (1). These equations can be discretized and grouped into a matrix equation:

$$\left(\begin{array}{cccc}{P}_{{\lambda }_{1}} & {P}_{{\lambda }_{2}} & \ldots & {P}_{{\lambda }_{n}}\end{array}\right)\left(\begin{array}{cccc}{R}_{{G}_{1},{\lambda }_{1}} & {R}_{{G}_{2},{\lambda }_{1}} & \cdots & {R}_{{G}_{n},{\lambda }_{1}}\\ {R}_{{G}_{1},{\lambda }_{2}} & {R}_{{G}_{2},{\lambda }_{2}} & \cdots & {R}_{{G}_{n},{\lambda }_{2}}\\ \vdots & \vdots & \ddots & \vdots \\ {R}_{{G}_{1},{\lambda }_{n}} & {R}_{{G}_{2},{\lambda }_{n}} & \cdots & {R}_{{G}_{n},{\lambda }_{n}}\end{array}\right)=\left(\begin{array}{cccc}{I}_{{G}_{1}} & {I}_{{G}_{2}} & \ldots & {I}_{{G}_{n}}\end{array}\right)$$
(2)

or \({{{{{{\bf{P}}}}}}}_{\lambda }\times {R}_{G,\lambda }={{{{{{\bf{I}}}}}}}_{G}\) in a more compact form. To enable accurate reconstruction of an unknown spectrum using the SnS2/ReSe2 heterostructure, we employed prior robust principal component analysis (RPCA) on the responsivity matrix \({R}_{G,\lambda }\) to stabilize the solution against various types of noise and errors. Subsequently, we used a regression model with elastic net regularization to solve the resulting matrix Eq. (2) by minimizing the sum of the squared errors loss function, with the added penalty term being a combination of \({\ell }_{1}\) and \({\ell }_{2}\) (Lasso and Ridge) norms. Details are provided in Methods and Supplementary Figs. 10 and 11.

Fig. 3: Design of vdW spectrometers.
figure 3

a Photoresponsivity (R) curves at three different gate voltages (Gi, Gj and Gk, left axis) and a schematic of an unspecified light spectral density (P) curve (gray dashed line, right axis). λ1 and λ2 define the operational spectral range of the spectrometer. b The photoresponse spectrum (R×P) of the device under unspecified light illumination source at different gate voltages, Gi (blue), Gj (green) and Gk (red). c The integrated photocurrent (I) as a function of gate voltage. Empty circles represent some typical data points in the photocurrent curve. d Spectral reconstruction process of our spectrometer. e Photoresponsivity of the device as a function of gate voltage (G) and light wavelength (λ). f Quasi-monochromatic spectra (FWHM: ~12 nm) reconstructed with our spectrometer (solid curve) and corresponding reference spectra measured using a commercial spectrometer (dashed curve). g The reconstructed 635 nm laser spectrum (FWHM: ~12 nm) and the reference spectrum (FWHM: ~3.5 nm) measured using a commercial spectrometer. h Reconstructed broadband spectrum of a white flashlight from a mobile phone and the reference spectrum.

To determine the responsivity matrix \({R}_{G,\lambda }\), we utilized a tunable light source with a wavelength ranging from 400 to 800 nm and 81 sampling points, measured at 81 different voltages from −20 V to 20 V. The resulting 81 × 81 \({R}_{G,\lambda }\) matrix is shown in Fig. 3e, exhibiting a tunable response within the visible and near-infrared spectrum range, enabling broadband spectrum reconstruction. To demonstrate the SnS2/ReSe2 heterostructure’s capability for reconstructing different types of spectra, we measured a series of quasi-monochromatic spectra in the range of 400 ~ 800 nm with our single-heterostructure spectrometer, which agree well with reference spectra acquired using a commercial spectrometer, verifying the broad spectral range of our device (Fig. 3f). We also demonstrate the reconstruction of 532 nm and 635 nm laser spectra in Supplementary Fig. 12 and Fig. 3g, respectively. Note, while recording the corresponding current values, we continuously illuminated the device with light for 1 min to stabilize the photocurrent, and then swept the gate voltage from -20 V to 20 V (sweep rate 1 V/s). Thus, the time required to measure a single complete spectrum is approximately 100 s, which can be reduced by decreasing the illuminating time, increasing the sweep rate, or/and using compressive sensing techniques. The full-width at half-maximum (FWHM) of the reconstructed laser spectrum’s was about 12 nm, with an optimal resolution of 11.3 nm according to the Nyquist–Shannon sampling theorem31. Note, although the Shannon-Nyquist theorem is primarily concerned with the sampling and reconstruction of time-dependent signals, in this work, this theorem is extended to the spatial frequency content of the signal and applied to the wavelength sampling. To further showcase device’s ability for broadband spectrum reconstruction, we measured the spectrum of a white flashlight from a mobile phone, as shown in Fig. 3h, revealing excellent agreement between the reconstructed and measured reference spectra. We also used the lowest irradiance suppliable by the apparatus available to us (23 μW/cm2) and a faithful reconstruction was produced with such low power density (Supplementary Fig. 13). We measured around 10 devices, and all showed essentially similar capabilities to reconstruct visible light spectra. An imaging array was also fabricated, using chemical vapor deposition (CVD) grown SnS2 and ReSe2 (Supplementary Fig. 14). Although all the devices worked properly, further optimization is needed to improve their performance.

Compressed sensing

Improving the resolution of a spectrometer is a key challenge in developing advanced spectroscopy techniques. The resolution of a spectrometer is limited by the number of sampling points, as previously discussed. However, the number of sampling points cannot be increased indefinitely due to the numerical properties of the responsivity matrix \({R}_{G,\lambda }\). To overcome this limitation and achieve a higher resolution32,33, we employ compressed sensing. For this, we utilized the singular value decomposition (SVD) technique, a well-known compression technique to achieve full spectrum reconstruction from surprisingly few p measurements of \({I}_{G}\) as described in the Methods section. In our case, a singular value (\({\sigma }_{i}\)) represents the contribution of each feature of \({R}_{G,\lambda }\). To determine the optimal number of sensors p or, alternatively, distinct gate voltage values for measurements, we followed methodology similar to that used by ref. 34. through QR decomposition and column pivoting. By gradually decreasing the p value from 81 to 9 and comparing the mean square error (\({{{{{\rm{MSE}}}}}}=\frac{1}{n}{\sum }_{i=1}^{n}{({I}_{G}-{\widetilde{I}}_{G})}^{2}\)), where \({\widetilde{I}}_{G}\) represent the reconstructed photocurrent from the p sensors, \({I}_{G}\) is the original photocurrent curve, and n = 81. Figure 4a shows the singular values \({\sigma }_{r}\) and the optimal modal is noted to occur for this system at \(r=9\), capturing 99% of the main features of \({R}_{G,\lambda }\) (\(\frac{\mathop{\sum }\nolimits_{i=1}^{r}{\sigma }_{i}}{\mathop{\sum }\nolimits_{i=1}^{n}{\sigma }_{i}}\times 100\)). Figure 4b, c shows measurement matrices for a random and optimized sampling obtained by QR decomposition and column pivoting. The reconstructed photocurrents versus gate voltage\(\,{\widetilde{I}}_{G}\) from a random and optimized sampling for \(p=9\) are shown in Fig. 4d. Compressed sensing leads to a more accurate reconstruction of the measured photocurrent than the randomly sampled system. One can also see that the estimated error for the optimized sampling is much smaller than that for the randomly selected one (Fig. 4e). Our results demonstrate that compressed sensing enables us to reconstruct the photocurrent versus gate voltage from merely 9 selected points (minimum 9 sensors) out of a total of 81, which is around 12% of our original sampling. The optimized sampling corresponds to gate voltages located where the first derivative \({{{{{\rm{d}}}}}}I/{{{{{\rm{d}}}}}}{V}_{{{{{{\rm{g}}}}}}}\) shows the largest variation (Fig. 4b, c). To ensure accurate compressed sensing, as shown in Fig. 4f, we reconstructed our spectrum using random and optimized sampling with elastic net regression as described in the Methods section. We observed that the spectrum reconstructed from the optimized sampling agrees well with the measured reference spectrum, whereas the reconstruction from random sampling shows an erroneous spectrum. Furthermore, we demonstrate that we can reconstruct the spectrum of a red LED with only 9 points, with very little difference compared to the reconstructed spectrum with \(n=81\) and the reference spectrum (Fig. 4g).

Fig. 4: vdW spectrometers improved with compressed sensing.
figure 4

a Singular values \({\sigma }_{{{{{{\rm{r}}}}}}}\) and the optimal rank truncation threshold at r = 9 (indicated by the vertical dashed line) for the tailored \({\varPsi }_{{{{{{\rm{r}}}}}}}\) basis, extracted from the responsivity matrix RG, λ, where γ is the noise magnitude determined by using the median singular value. b, c Measurement matrices \(C\in {{\mathbb{R}}}^{p\times n}\), where \(p=9\) and \(n=81\) for random and optimized sampling, respectively. d Reconstructed photocurrent versus gate voltage for random sampling (blue line) and optimized sampling (red line), where the (black dashed line is the measured photocurrent. e Discretized error distribution defined by \({I}_{{{{{{\rm{reconstructed}}}}}}}-{I}_{{{{{{\rm{measured}}}}}}}\) for the random (blue points) and optimized sampling (red points). f Spectral reconstruction for a laser excitation source at 632 nm for random and optimized measurement matrices. g Spectral reconstructions for the optimal sampling through compressed sensing with \(p=9\) compared to the reconstructed spectrum with 81 points, and the reference spectrum. h Comparison between our work and other reported miniaturized spectrometers (MoS2/WSe2 vdWH (van der Waals heterostructure)15, ReS2/Au/WSe2 vdWH11, black phosphorus7, single nanowire14, quantum dots5,12, photonic crystal10, structurally colored nanowires18, interferometer4, folded metasurfaces17, perovskite54, spiro-OMeTAD/perovskite55, Voronoi photonic crystal56, thin-film lithium niobate9, disordered photonic chip8, holographic57 and ring resonator58). The horizontal lines represent the operational spectral range. Color variation indicates the difference in resolution. The detailed data can be found in Supplementary Table 1.

We compared our 2D heterostructure spectrometer with other miniaturized spectrometers in terms of their footprints, spectral range, and resolution, as shown in Fig. 4h (see Supplementary Table 1 for details). Compared to separate optical elements, 2D materials-based spectrometers offer distinct advantages in terms of footprint miniaturization7,11,15. Our device has a small footprint of 19 μm and an enhanced spectral resolution of 5 nm, making it comparable to state-of-the-art visible and near-infrared spectrometers. Here, the maximum length along any axis of the heterostructure is considered to be the device footprint. The device has an area of ~220 μm2. Furthermore, the footprint of a 2D materials-based device can be scaled down to sub-micrometer dimensions, and the resolution can be further improved by increasing wavelength sampling points. Our device also has an advantage in processing speed over other computational spectrometers due to the compressed sensing techniques employed. While the spectrum reconstruction capability of our device relies on the nature of SnS2 and ReSe2 with trap states, this approach can be extended to other 2D materials by intentionally introducing trap states34 to expand the spectral range.

Spectral imaging and image memory demonstration

To demonstrate the potential application of our single heterostructure spectrometer for spectral imaging, we designed a spatial scanning system for the device (Fig. 5a). A broadband light source was used to project an image consisting of red, green, blue, and yellow colors, which could be scanned across the x-y plane on the centimeter scale. The reflected light was focused by a lens onto the device, and we measured the photocurrents of each mapping step. The reflected spectrum was then reconstructed using the method discussed above. The reconstructed spectra at two positions indicated in Fig. 5a are shown in Fig. 5b, which are in good agreement with the corresponding reference spectra. All the measured photocurrents were grouped into a three-dimensional \(I(x,y,G)\) data cube (Fig. 5c, e), which was then converted to a spectral data cube \(P(x,y,\lambda )\) by the reconstruction algorithm (Fig. 5d, f). By applying standardized color-matching functions to the spectral cube, we were able to form a pseudocolored image (Fig. 5h) with an accurately recreated colored “BIT” pattern, which was consistent with the original image (Fig. 5g). In this configuration, the image resolution is defined by the mapping step, which was set to around 1 cm. By fabricating device arrays, we could produce large-scale imaging systems with the single-heterostructure device possessing high spatial resolution at the micrometer or nanometer scale35. Our results demonstrate the potential of our single heterostructure spectrometer in spectral imaging, with the ability to accurately reconstruct the reflected spectrum of a colored image. The device’s high spatial resolution at the micrometer or nanometer scale15, when integrated into device arrays, opens up possibilities for large-scale imaging systems.

Fig. 5: Scanning spectral imaging with vdW spectrometers.
figure 5

a Schematic of the spectral imaging system with our spectrometer. b Reconstructed and reference spectra of points 1 and 2 in (a). c The initial photocurrent data cube, consisting of measured photocurrent values at each scanned location and gate voltage. d The spectral data cube converted from (c) using the reconstruction algorithm. A series of (e) photocurrent images and (f) reconstructed images at each scanned location and selected gate voltages. g Original scanned image and (h) reconstructed pseudo-colored spectral image.

We have demonstrated the light detection, spectrum reconstruction, and spectral imaging capabilities of our single-heterostructure device, which can also be achieved in other systems such as quantum dots5,12, nanowires14,18, black phosphorus7 and MoS2/WSe2 heterojunctions15. However, our SnS2/ReSe2 device has a unique feature in producing a gate-tunable photocurrent via trap states at the interface, offering a tantalizing route for the design of image memory36,37. In Fig. 6a, we show the time-dependent variation of current in the device when applying laser illumination and gate pulses. After being illuminated by a 635 nm laser, the current immediately increases sharply and then gradually approaches a set value, indicating a long-term positive persistent photoconductivity (PPC) effect in our device attributed to trap states at the interface38,39(see Supplementary Note 1 for details). To further investigate the time evolution of the PPC as well as the switching action, we used laser pulses (pulse-width ~0.1 s), instead of continuous laser illumination, to excite the photocurrent in the device. As expected, after applying the laser pulses, a large quantity of carriers is produced in the device, leading to a rise in the current (Fig. 6b). The carriers are easily retained beyond the timeframe of minutes in dark conditions, completing a program operation. This state is defined as the ‘optical program state’. These carriers can be eliminated by applying a positive gate pulse, that is, an erase operation, setting the current back to its initial value, which is defined as the ‘electrical erase state’. Figure 6c shows the retention characteristic of the program and the erase state. It is found that the programming and erasing current are clearly retained after 104 s, though a slight decline appears to occur for t < 10 s, after which the current stabilizes (Supplementary Fig. 15). An endurance test of repeated programming and erasing operation was also performed, of which the results are shown in Fig. 6d. It can be observed that both the program and the erase states remain stable even after 1000 cycles. However, such a strong memory effect indicates a slow response speed in our detector. This problem can be simply solved by changing the detection mode from the ‘memory mode’ to the ‘fast mode’ (Fig. 6e, f). At Vds = 0, our device shows a remarkable short-circuit current and a fast response speed (response time ~0.43 ms, Supplementary Fig. 16). This characteristic essentially enables our device to adapt to different application scenarios. To demonstrate its imaging memory capacity, we performed a proof-of-concept demonstration using three different lasers and scanning masks with different patterns in Fig. 6g. We show that the photocurrent at each mapping position can be used to reconstruct the incident light spectra and can also be coherently stored in the device for a long period of time (Fig. 6h), confirming the imaging memory capacity of our device.

Fig. 6: Image memory with vdW spectrometers.
figure 6

a Time-resolved source-drain current of the device under alternate 635 nm laser illumination and positive gate pulse (pulse-width ~0.1 s). The blue shaded area and blue dashed lines indicate the illumination by laser and the application of the gate pulses, respectively. Vds = 1 V, Vg = 20 V, Pin = 0.2 mW/cm2. b Time-resolved Ids of the device under alternate 635 nm laser pulses and positive gate pulses (pulse-widths are both ~0.1 s). The red and blue dashed lines indicate the application of the laser pulses and gate pulses, respectively. Vds = 1 V, Vg = 40 V, Pin = 0.5 mW/cm2. c Retention characteristic of the optoelectronic memory device after applying the program light pulse (red circles, Pin = 12 mW/cm2, pulse-width ~0.1 s) and erase positive gate pulse (blue circles, amplitude 20 V, pulse-width ~0.1 s). The current ratio of program/erase state reaches 103 at Vds = 1 V and Vg = 0. The dotted vertical line represents the time when the laser pulse and gate pulse were applied. d Endurance performance test of the optoelectronic device executed with alternate light pulses (red circles, Pin = 12 mW/cm2, pulse-width ~0.1 s) and gate pulses (blue circles, amplitude 20 V, pulse-width ~0.1 s). Vds = 1 V, Vg = 0. e Schematic representation of the ‘fast mode’ of the device at Vds = 0. f Time resolved current curve of the device under periodic 635 nm laser illumination (Pin = 50 mW/cm2) at Vds = 0 and Vg = 0, showing a fast response and response time measurement of the ‘fast mode’, showing rise and decay times both of 0.43 ms. g Schematic of configuration and principle of the imaging memory system of our device. h Scanning photocurrent images of three different patterns under three different lasers. The upper panel shows the images at the moment the laser pulses is on (t = 0), and the lower panel shows the images at 5 min after the lasers were off (t = 5 min).

Neuromorphic computing spectroscopy

Optical memory effects have been reported by ref. 40. We would like to stress that our device’s memory function is due to interface trap states, making it promising for applications in artificial synapses41, neural networks38,42, machine vision42, and imaging processing43. To demonstrate the multifunctionality of our compact spectrometer, which not only serves as a storage device but also possesses processing capabilities. We applied periodic light pulses (Pin ~ 10 mW/cm2, pulse-width ~1 s) to produce an increment in the conductivity, leading to multiple memory states for data storage. Subsequently, by applying periodic gate voltage pulses (amplitude ~5 V, pulse-width ~2 s), we could decrement the conductivity, thus performing erasure the stored states (Fig. 7a). In this context, the increase and decrease in device conductance are termed as potentiation and depression, respectively. Given that our vdW SnS2/ReSe2 device system changes conductance, it can thus be utilized in a neural network and serve as both a neuron and a synapse. Long-term potentiation (LTP) and depression (LTD) cycles were observed, suggesting that our device mimics the function of a synapse with a nonlinear behavior for training the artificial neural network (ANN) (Fig. 7b and Supplementary Fig. 17). Generally, achieving high classification accuracy often relies on the use of artificial synapses that have linear characteristics. However, in our case, we rely on non-linear LTP induced by blue light stimuli and LTD by voltage gate pulses. To attain a high classification accuracy, it is essential to consider the inherent asymmetric non-linearity of our LTP and LTD as well as considering the complete plasticity range represented by the ratio Imax/Imin. To accomplish this, we used an asymmetric nonlinear relationship to fit the LTP and LTD curves, thereby deriving the nonlinearity (NL) and the weight change of the LTP and LTD, the details are further discussed in Supplementary Note 3. Moreover, the long-term potentiation shape shows a dependency on the incident light, suggesting the possibility of reconstructing the spectrum of incident light with a defined number of memory cells (Fig. 7c). In this study, we simulated a two-layer ANN based on the SnS2/ReSe2 vdW heterostructures synaptic behavior to classify handwritten data on the MNIST data (Fig. 7d). Details of the training process can be found in the Methods section. Figure 7e, f presents the classification accuracies as function of epoch (which represents a single iteration over the complete training dataset) and varying the numbers of synaptic states (ranging from 10 to 40 states). As the synaptic states increase from 10 to 40, the classification accuracy exhibits a gradual improvement, starting at 87% and nearly reaching 90% after just 50 epochs with 40 states. Furthermore, it is noteworthy that employing a greater number of synaptic states results in shorter training times. In Fig. 7f, we have represented the confusion matrix that demonstrates the classification accuracy for each label.

Fig. 7: Neuromorphic computing with vdW spectrometers.
figure 7

a Schematic of the spectral training system for the deep neural networks. A broadband light source, controlled by a signal generator to produce light pulses, was used to project red, green and blue light. The reflected light was focused by a lens onto the device, and we measured the photocurrents of each color. b 40 potentiation and depression states under the control of light blue light pulses (Pin ~ 10 mW/cm2, pulse-width ~1 s) and gate pulses (amplitude ~5 V, pulse-width ~2 s). c Currents of the device under different light illumination as a function of number of pulses. d Two-layer artificial neural network for classifying handwritten digits. e Neuromorphic classification accuracies as a function of number of iterations for 10, 20 and 40 different synaptic states based on the device. f Confusion matrix also known as errors matrix, is used to evaluate the performance of our classifier. The correct classifications are on the diagonal of the matrix, whereas the off diagonal represents the incorrect classifications during the validation test.

Discussion

In-sensor storage and processing capabilities are important for next-generation sensing, but also optical sensing is becoming more reliant on computational systems44. For such technological changes to become a reality, apart from device reconfigurability, advanced algorithms, would be required to reduce the physical complexity of sensors. Therefore, it is important to develop device concepts that can do more with less, with designs that can enable direct multiplexing of sensing and computing functions45. Here, we showed that a single SnS2/ReSe2 van der Waals heterostructure, can provide photodetection, spectrum reconstruction, spectral imaging, and long-term image memory capabilities. By applying light pulses and gate voltage pulses, our miniaturized spectrometer can realize image-encoding and -classification functions based on artificial neural networks. Although, our approach can potentially overcome the limitations of present single-device systems and pave the way for the design of single-detector computational spectrometers beyond von Neumann architectures. This breakthrough could possibly impact the field of optoelectronics, with applications ranging from artificial synapses, neural networks, machine vision, and imaging processing, to spectroscopy and analytical chemistry.

Methods

Device fabrication and characterization

For the fabrication of the vdW heterostructures, a highly n-doped silicon wafer with a 300-nm-thick SiO2 layer was used as the substrate. Heterostructures were fabricated via a standard dry transfer method46. Two types of multilayer vdW materials, ReSe2 and SnS2, were obtained by mechanical exfoliation onto PDMS stamps with scotch tape. Then, they were released onto the prepared substrate to form vertically stacked vdW heterostructures. The heterostructures were annealed in a furnace at 150 °C for 2 h under an Ar (200 sccm) atmosphere to achieve better contact. For the patterning of the electrodes, we utilized standard photolithography and high-vacuum electron-beam evaporation. The thickness of the deposited Ti/Au electrodes was 10/40 nm, respectively. Raman spectra were acquired with a Bruker Senterra confocal spectrometer with an excitation wavelength of 532 nm to identify the properties of SnS2 and ReSe2 as well as their heterostructures. Atomic force microscopy characterization was performed with a Bruker MM8 system and HRTEM characterization was performed using a JEOL JEM-2100 F with a probe size of less than 0.5 nm at a working voltage of 200 kV.

Reconstruction process

Before spectrum reconstruction, the spectral responsivity matrix \({R}_{G,\lambda }\) was decomposed by RPCA (robust principal component analysis) into a structured low–rank matrix \({\widetilde{R}}_{G,\lambda }\) and a sparse matrix \({S}_{G,\lambda }\), thus discarding the outliers and noise as shown in Supplementary Figs. 10 and 11:

$${R}_{G,\lambda }={\widetilde{R}}_{G,\lambda }+{S}_{G,\lambda }$$
(3)

where the principal components of \({\widetilde{R}}_{G,\lambda }\) are robust to the outliers and the noise in \({S}_{{V}_{G},\lambda }\) matrix. We observe that the \({S}_{{V}_{G},\lambda }\) sparse matrix is one to two orders of magnitude lower than the \({\widetilde{R}}_{G,\lambda }\) spectral matrix, and the original spectral matrix RG, λ. In order to reconstruct the unknown spectrum, we use the elastic net regression that minimizes the sum of squared errors by applying a penalty to these coefficients which is a combination of \({\ell }_{1}\) and \({\ell }_{2}\) (Lasso and Ridge) approaches. From Eq. (4), we can see that if α is equal to 1, elastic net regression is the same as Lasso regression. As α decreases toward 0, it approaches the Ridge regression. In our reconstruction, we observe a small \(\alpha\) (0.01), meaning that we are close to Tikhonov regularization. However, we observe that adding a \({\ell }_{1}\) penalization term provides us with a slightly better reconstruction than the Ridge regression alone:

$$\min {\Big\| \hat{R}\cdot \hat{\varphi } \cdot \overrightarrow{\beta }-I\Big\| }_{2}^{2}+\lambda \left(\underbrace{\frac{1-\alpha }{2}{\Big\| \overrightarrow{\beta }\Big\| }_{2}^{2}}_{{\ell }_{2}\,{{{{{\rm{regularization}}}}}}}+\underbrace{\alpha {\Big\| \overrightarrow{\beta }\Big\| }_{1}}_{{\ell }_{1} \, {{{{{\rm{regularization}}}}}}}\right),$$
(4)

where λ is the amount of penalization, which is chosen by cross-validation.

Compressed sensing

The photocurrent values as function of gate voltage \({{{{{{\bf{I}}}}}}}_{G}\in {{\mathbb{R}}}^{n}\) can be represented as a sparse vector \({{{{{\bf{s}}}}}}\in {{\mathbb{R}}}^{n}\) in a transform basis \(\varPsi \in {{\mathbb{R}}}^{n\times n}\):

$${{{{{{\bf{I}}}}}}}_{G}=\varPsi {{{{{\bf{s}}}}}}$$
(5)

Using compressed sensing, it is possible to effectively achieve full spectrum reconstruction from surprisingly few p measurements instead of directly measuring \({{{{{{\bf{I}}}}}}}_{G}\in {{\mathbb{R}}}^{n}\) (which requires n measurements). These few p measurements, denoted as \({{{{{{\bf{I}}}}}}}_{{Gp}}\in {{\mathbb{R}}}^{p}\), can then be used to solve the non-zero elements of the transformed sparse vector s. The relationship between the measurements \({{{{{{\bf{I}}}}}}}_{{Gp}}\in {{\mathbb{R}}}^{p}\) and the compressible signal \({{{{{{\bf{I}}}}}}}_{{Gn}}\in {{\mathbb{R}}}^{n}\) is given by the Eq. (6):

$${{{{{{\bf{I}}}}}}}_{{Gp}}=C{{{{{{\bf{I}}}}}}}_{G}$$
(6)

Where, the measurement matrix \(C\in {{\mathbb{R}}}^{p\times n}\) represents a set of p (sensors) measurements at specific gate voltages.

By combining Eqs. (5) and (6), we obtain the relationship between the compressed measurement \({{{{{{\bf{I}}}}}}}_{{Gp}}\) and the sparse vector s:

$${{{{{{\bf{I}}}}}}}_{{Gp}}=C\varPsi {{{{{\bf{s}}}}}}$$
(7)

In this work, a singular value decomposition technique47,48,49 was used to achieve a highly transformative basis. To do this, we first extracted the low-dimensional pattern of the spectral responsivity matrix \({R}_{G,\lambda }\) through singular value decomposition, leading to a tailored library \({\varPsi }_{r}\in {{\mathbb{R}}}^{n\times r}\), containing the first r columns of Ψ (features or eigenmodes):

$${R}_{{{{{{\rm{G}}}}}},{{{{{\rm{\lambda }}}}}}}=\varPsi \varSigma {V}^{{{{{{\rm{T}}}}}}}={\varPsi }_{r}{\varSigma }_{r}{V}_{r}^{{{{{{\rm{T}}}}}}}$$
(8)

The diagonal elements of the matrix \({\varSigma }_{r}\) are the singular values (\({\sigma }_{i}\)) of \({R}_{G,\lambda }\). The rank r is chosen by optimal hard thresholding to capture the main features and to avoid residual noise in the data50.

Based on the work of ref. 51, in order to find the optimum measurement matrix C, the best possible full reconstruction \({\mathop{I}\limits^{ \sim }}_{G}\,\)(n = 81) is performed by seeking the row of \({\varPsi }_{r}\) corresponding to the best location in the G row space of \({\varPsi }_{r}\) that optimally condition the inversion of \(C{\varPsi }_{r}\). To select the optimum row in the \({\varPsi }_{r}\) tailored basis, we used reduced matrix QR factorization with column pivoting, enabling the decomposition of \({\varPsi }_{r}\) into a unitary matrix Q, upper-triangular matrix R and a column of permutation matrix C such that \({\varPsi }_{r}^{T}{C}^{T}={QR}\), when the number of p sensors is equal to rank r. In the case of the oversampled (p>r), where the number of p exceeds the number of features (eigenmodes) used in the reconstruction52,53, we use the following relationship \({\varPsi }_{r}{\varPsi }_{r}^{{{{{{\rm{T}}}}}}}{C}^{{{{{{\rm{T}}}}}}}={QR}\). After knowing \({\varPsi }_{r}\) and the C matrix, we are able to approximate the sparse vector s with the Moore–Penrose pseudo-inverse \({{{{{\bf{s}}}}}}={\varTheta }^{{{\dagger}} }{{{{{{{\boldsymbol{I}}}}}}}_{G}}_{p}={(C{\Psi }_{r})}^{{{\dagger}} }{{{{{{{\bf{I}}}}}}}_{G}}_{p}\) for \(p > r\) or the inverse \({{{{{\bf{s}}}}}}={\varTheta }^{-1}{{{{{{{\bf{I}}}}}}}_{G}}_{p}={(C{\varPsi }_{r})}^{-1}{{{{{{{\bf{I}}}}}}}_{G}}_{p}\) for \(p=r\). Finally, when the sparse vector s is known, we can reconstruct the photocurrent \({\mathop{I}\limits^{ \sim }}_{G}\) from the Eq. (5).

Neuromorphic computing

To demonstrate the neuromorphic computing capabilities based on our vdW SnS2/ReSe2 devices, which function as both memory and synapses, we employed a simple neural network for a multiclass classification problem. As depicted in Fig. 7d, the neural network is composed of two layers: an input layer with a dimension of 784 (representing each pixel in the 28 × 28 images), and an output layer with 10 neurons, each dedicated to recognizing a specific label (\({f}_{m,n}\)). We trained and tested our neural network by using the MNIST dataset, which contains handwritten digits images (0, 1,…,9).

The training dataset consists of 60,000 images, while the testing dataset contains 10,000 images. During the training process, each input neuron in the input layer receives the corresponding pixel value from the image, assigns it to input vector (\({{{{{{\bf{X}}}}}}}_{i}\)), and converts it into 10 outputs values using the linear relation represented as \({\varSigma }_{n}={\sum }_{i=1}^{784}{{{{{{\bf{X}}}}}}}_{i}{W}_{i,n}\), where \({W}_{i,n}\) denotes the synaptic weight matrix. Initially, the weight matrix was randomly initialized based on our vdW SnS2/ReSe2 synaptic states. To determine the direction of weight updates, the output values \({\varSigma }_{n}\) were transformed by using a Softmax activation function \((\sigma {(\varSigma )}_{i}=\frac{{e}^{{\varSigma }_{i}}}{{\varSigma }_{j=1}^{K}{e}^{{\varSigma }_{j}}})\), resulting in a probability distribution denoted as (\({O}_{m,n}\)). When we compare the label value (\({f}_{m,n}\)) of each image ‘m’ with the probability distribution, it allows us to calculate the delta value \({\delta }_{m,n}={O}_{m,n}-{f}_{m,n}\)). If \({\delta }_{m,n}\) is greater than 0, the synaptic weight (w) is increased; otherwise, the synaptic weight is decreased. The magnitude of the weight changes (\(\triangle w\)) is determined by the fitting formulas (Supplementary Note 3).