Generate a synthetic 1D signal with known ground truth
Source:R/psalsa_gen_synthetic_1d.R
gen_synthetic_1d.RdBuilds a synthetic spectrum (a smooth baseline plus a number of peaks plus
noise) with a known true baseline and known individual peak areas, useful
for testing baseline-estimation code or trying out psalsa() without real
data. This is what tune_psalsa() uses internally to build its synthetic
tuning pool, matched to the characteristics of a real example spectrum;
called directly, it is a standalone generator.
Arguments
- n
Number of points.
- density
Peaks per point; the number of peaks is
max(3, round(density * n))(further reduced bycap_density).- fwhm_range
c(lo, hi): each peak's full width at half maximum (in points) is drawn uniformly from this range.- csnr
Noise scale, roughly the noise standard deviation as a fraction of the signal amplitude
A.0gives an exactly noise-free signal.- peak_shape
Either
"gaussian"or"gex"(an asymmetric, exponentially-modified peak shape typical of chromatography).- A
Amplitude scale for both the baseline and the peaks.
- seed
Random seed, for reproducibility.
- cap_density
If
TRUE(the default), reduces the peak count so peaks have room to stay non-overlapping (densityandfwhm_rangethemselves are left untouched – only how many peaks are actually placed). Peak centers are still placed uniformly at random, so this lowers the odds of overlap rather than guaranteeing it; set toFALSEto allow arbitrarily dense, overlapping peaks.- min_spacing_mult
Only used when
cap_density = TRUE: the peak count is capped so the average spacing between peaks is at leastmin_spacing_multtimes the widest FWHM infwhm_range.
Value
A list with:
ythe synthetic signal,
baseline + peaks + noise.baseline,peaks,noisethe individual components of
y.sigmathe (possibly position-dependent) noise standard deviation used to generate
noise.peak_infoa data frame with one row per individual peak:
height,fwhm,center, the index windowlo:hiwhere that peak alone exceeds 0.1% of its own height, andarea(its exact true area,sum()of that peak's own values over the full signal).
