---
title: "From emergent intensity to a fitted spectrum"
description: "Combine continuum placement, instrumental convolution and errors in one observing model, then test wavelength calibration and model mismatch."
canonical_url: "https://sandboxphysics.com/stories/stellar-spectroscopy/from-intensity-to-a-fitted-spectrum/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/stellar-spectroscopy/from-intensity-to-a-fitted-spectrum/"
last_modified: "2026-10-28"
---

[Stellar spectra from dark lines to abundance models](https://sandboxphysics.com/stories/stellar-spectroscopy/)

AC03 · L3

# From emergent intensity to a fitted spectrum

Sandbox Physics · 2026-10-28

Predict the light leaving the gas, predict how the instrument records it, then compare that prediction with saved samples. Continuum placement, instrumental spreading and wavelength calibration enter before a fitted number acquires a physical meaning.

## Before you begin

Read the preceding two chapters. A residual is observation minus prediction; divide by its random standard deviation, square and add to form the weighted sum. Convolution spreads light from one wavelength across neighboring detector wavelengths.

## Write the instrument response before the fit

Let $q(\lambda)$ denote the normalized slab intensity. An ideal instrument would record it directly. A real response $G$ spreads each input across nearby wavelengths; adding those contributions defines a convolution.

The response must integrate to one. A constant continuum then remains constant, and a complete line retains its integrated missing area. The implementation convolves $q-1$ and extends that deficit by zero outside the domain. This supplies a unit continuum beyond the edges instead of creating artificial dark edge pixels.

$$
q_{\rm inst}(\lambda)=\int G(\lambda-\lambda^\prime)q(\lambda^\prime)d\lambda^\prime,\qquad\int G(u)du=1
$$

The response has inverse-wavelength units. A truncated window can still lose area when the response spreads light beyond its boundaries.

Reading: Condon & Ransom, Essential Radio Astronomy, Appendix E · Krumholz, ASTR 4003/8003 (2019), Class 1, Radiative transfer I

## Estimate the continuum with the line

A calibrated spectrum can retain a local slope. Forcing that continuum flat can make a fit move the line or change its depth to compensate. Use $C(\lambda)=a+b x$ locally, where $x$ is a dimensionless wavelength coordinate relative to a fixed origin.

The prediction is $M_i=C(\lambda_i)q_{\rm inst}(\lambda_i)$. At fixed line velocity, width and optical depth, the continuum coefficients remain linear. Solve their two normal equations directly and search only over the nonlinear line parameters.

Set $u_i=q_i$ and $v_i=x_iq_i$, with $q_i=q_{\rm inst}(\lambda_i)$ and weights $w_i=1/\sigma_i^2$. The prediction becomes $a u_i+b v_i$. Differentiate the weighted residual sum with respect to each continuum coefficient. Both derivatives vanish at the minimum, giving the two equations below.

The matrix simply groups two simultaneous equations. Compute the five weighted sums and solve for intercept and slope. Its determinant is nonzero only when the two basis columns provide distinct information: a single wavelength cannot determine both continuum height and slope.

$$
\chi^2=\sum_i\left[\frac{y_i-(a+b x_i)q_{\rm inst}(\lambda_i)}{\sigma_i}\right]^2
$$

Here y is observed intensity and sigma is its random standard deviation. A familiar chi-square interpretation requires an appropriate model of independent errors.

$$
\begin{pmatrix}\sum_i w_i u_i^2&\sum_i w_i u_i v_i\\\sum_i w_i u_i v_i&\sum_i w_i v_i^2\end{pmatrix}\begin{pmatrix}a\\b\end{pmatrix}=\begin{pmatrix}\sum_i w_i u_i y_i\\\sum_i w_i v_i y_i\end{pmatrix}
$$

These are the continuum normal equations at a fixed line model. The outer search then compares the next velocity, width and optical depth.

## A good residual can hide a wrong velocity

The controlled tutorial injects $18\,\mathrm{km\,s^{-1}}$ into a saved synthetic record at resolving power $60000$. Fitting continuum, velocity, Doppler parameter and reference optical depth recovers about $18.0\,\mathrm{km\,s^{-1}}$ with reduced chi-square near $1.04$. This checks recovery from those particular saved samples.

Now add $0.002\,\mathrm{nm}$ to every wavelength without changing intensity or noise. The fitted velocity becomes about $19.2\,\mathrm{km\,s^{-1}}$ with almost the same residual. A shared wavelength zero-point error closely imitates common gas motion.

A specified zero-point uncertainty of $0.0002\,\mathrm{nm}$ corresponds to $0.120\,\mathrm{km\,s^{-1}}$ at five hundred nanometres. More pixels under the same calibration do not average away that common shift.

$$
\delta v\simeq c\frac{\delta\lambda_0}{\lambda_0}
$$

Reducing this common calibration uncertainty requires independent wavelength information.

## Let a real spectrum expose model shortcomings

The observed tutorial pins a CALSPEC Vega spectrum and selects only the optical region identified in its header as STIS observations. Its broad hydrogen line has wings. A simple Gaussian leaves a huge weighted residual when compared with the small statistical errors. Changing the window, continuum or profile changes its apparent center and width.

That is a useful transition from a teaching spectrum to astronomical data. A numerical optimizer needs a physical description that survives residual checks before it can yield reliable stellar parameters. First report line-measurement sensitivity. Interpreting abundance then requires a fuller atmospheric calculation.

Reading: STScI CALSPEC, alpha\_lyr\_stis\_011.fits (25 October 2022) · MAST reference atlases and CALSPEC releases · Amarsi, Liljegren & Nissen (2022), 3D non-LTE iron abundances in FG-type dwarfs, arXiv:2209.13449v3

Saved default prediction for the teaching slab

Uniform layer, fixed ion stage and artificial transitions; no random noise. The saved calculation uses 721 wavelengths and a normalized Gaussian instrument response.

| Layer temperature | $4500\,\mathrm K$ |
| --- | --- |
| Column / reference | $N/N_0=1$ |
| Receding velocity | $12\,\mathrm{km\,s^{-1}}$ |
| Resolving power | $R=60000$ |
| Strong-line center | $500.0200\,\mathrm{nm}$ |
| Total equivalent width | $11.952\,\mathrm{pm}$ |
| Layer / background source ratio | $0.201$ |

## [Compare area with central depth](https://sandboxphysics.com/labs/stellar-absorption-lines/)

1. Hold the layer fixed and change resolving power.
2. Compare central depth with equivalent width and explain why they respond differently.
3. Export both model spectra so the inputs and samples remain together, then examine the observed tutorial.

## Exercises with explanations

1. Why does a shared wavelength zero point survive averaging many pixels?

   Read the explanation

   All pixels move together, like marks on a ruler with a misplaced origin. Independent positive and negative errors could cancel; this common shift cannot.

2. Should a huge reduced chi-square be fixed by rescaling the error bars until it equals one?

   Read the explanation

   First inspect residual structure, continuum, instrument response and omitted physics. Arbitrarily enlarging errors hides evidence of a poor model.

[Previous: Put absorption and emission in one equation](https://sandboxphysics.com/stories/stellar-spectroscopy/absorption-emission-and-growth/) [Next: Fit a frozen calibrated stellar spectrum](https://sandboxphysics.com/stories/stellar-spectroscopy/fit-a-frozen-calibrated-spectrum/)

## Sources and calculation scope

1. [Krumholz, ASTR 4003/8003 (2019), Class 1, Radiative transfer I](https://www.mso.anu.edu.au/~krumholz/teaching/astr8003_s1_2019/notes1.pdf)

   Equations 24–28: integrating factor, formal solution and constant-source slab. Independently derived and checked by numerical transport here.

2. [Condon & Ransom, Essential Radio Astronomy, Appendix E](https://www.cv.nrao.edu/~sransom/web/A5.html)

   Transfer equation 2.27, LTE Kirchhoff relation 2.30 and Planck law 2.86; used at optical wavelengths with the full Planck function.

3. [STScI CALSPEC, alpha\_lyr\_stis\_011.fits (25 October 2022)](https://ssb.stsci.edu/trds/calspec/alpha_lyr_stis_011.fits)

   Pinned FITS header and all 82 selected observed STIS rows from 4750 to 4975 vacuum angstroms. File checksum and exact source rows accompany the tutorial.

4. [MAST reference atlases and CALSPEC releases](https://archive.stsci.edu/hlsp/reference-atlases)

   Data provenance and release context. The exercise deliberately pins version eleven rather than the changing current directory.

5. [Amarsi, Liljegren & Nissen (2022), 3D non-LTE iron abundances in FG-type dwarfs, arXiv:2209.13449v3](https://arxiv.org/pdf/2209.13449v3)

   Version three, 9 December 2022: sections 2.1–2.4 and 3.1, figures 2, 3, 8 and 10. The paper-reading guide checks conventions and sensitivity; it does not rerun the 3D solver.
