A spectral sensor for near-infrared spectroscopy, which is used for distinguishing and/or recognizing objects and/or materials, wherein the spectral sensor comprises a computing and memory unit and is configured to operate in a learning mode and in an operating mode, wherein the spectral sensor is configured to perform one or more measurements of intensity values of a first spectrum of wavelengths in the learning mode and at least one measurement of intensity values of a second spectrum of wavelengths in the operating mode, wherein the second spectrum is fully included in the first spectrum but comprises fewer wavelengths than the first spectrum, wherein the spectral sensor is configured to itself determine the wavelengths of the second spectrum by means of a first principal component analysis of the measurements of the first spectrum and, in the first principal component analysis, to calculate two principal components (22, 24) as well as the first and second charges (28, 30) associated with the principal components (22, 24), characterized in that the spectral sensor is further configured - to calculate a charge difference for each wavelength of the first spectrum as the difference of the first and second charges (28, 30) of the same wavelength, and - to select those wavelengths for the second spectrum which have the largest charge difference, for which purpose the spectral sensor is configured - (a) to define the number of wavelengths to be selected, - (b) when selecting the wavelengths for the second spectrum, first to select the wavelength having the largest charge difference and then to decrease charge differences of wavelengths adjacent to the selected wavelength, and - (c) subsequently, based on the decreased charge differences, to select a further wavelength having the then largest charge difference and then to decrease charge differences of wavelengths adjacent to the further selected wavelength, wherein the computing unit is adapted to perform the steps necessary for determining the wavelengths of the second spectrum. the spectral sensor is configured to perform one or more measurements of intensity values of a first spectrum of wavelengths in the learning mode and at least one measurement of intensity values of a second spectrum of wavelengths in the operating mode, wherein the second spectrum is fully included in the first spectrum but comprises fewer wavelengths than the first spectrum, wherein the spectral sensor is configured to itself determine the wavelengths of the second spectrum by means of a first principal component analysis of the measurements of the first spectrum and, in the first principal component analysis, to calculate two principal components (22, 24) as well as the first and second charges (28, 30) associated with the principal components (22, 24), characterized in that the spectral sensor is further configured - to calculate a charge difference for each wavelength of the first spectrum as the difference of the first and second charges (28, 30) of the same wavelength, and - to select those wavelengths for the second spectrum which have the largest charge difference, for which purpose the spectral sensor is configured - (a) to define the number of wavelengths to be selected, - (b) when selecting the wavelengths for the second spectrum, first to select the wavelength having the largest charge difference and then to decrease charge differences of wavelengths adjacent to the selected wavelength, and - (c) subsequently, based on the decreased charge differences, to select a further wavelength having the then largest charge difference and then to decrease charge differences of wavelengths adjacent to the further selected wavelength, - to calculate a charge difference for each wavelength of the first spectrum as the difference of the first and second charges (28, 30) of the same wavelength, and - to select those wavelengths for the second spectrum which have the largest charge difference, for which purpose the spectral sensor is configured - (a) to define the number of wavelengths to be selected, - (b) when selecting the wavelengths for the second spectrum, first to select the wavelength having the largest charge difference and then to decrease charge differences of wavelengths adjacent to the selected wavelength, and - (c) subsequently, based on the decreased charge differences, to select a further wavelength having the then largest charge difference and then to decrease charge differences of wavelengths adjacent to the further selected wavelength, wherein the computing unit is adapted to perform the steps necessary for determining the wavelengths of the second spectrum.