Updated epsilon on unit test. Updated recording use statements on doctest
This commit is contained in:
parent
19484fd1cb
commit
ed576df32d
@ -76,7 +76,7 @@ impl RecordSettings {
|
||||
/// This struct lets a recording run on a stream, waits till the first data arrives and records for a given period of time. Usage:
|
||||
///
|
||||
/// ```
|
||||
/// use lasprs::{RecordSettings, StreamMgr, Recording};
|
||||
/// use lasprs::daq::{RecordSettings, StreamMgr, Recording};
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// fn main() -> anyhow::Result<()> {
|
||||
|
@ -427,18 +427,46 @@ mod test {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tf2() {
|
||||
let nfft = 4800;
|
||||
let distr = Normal::new(1.0, 1.0).unwrap();
|
||||
let mut timedata = Dmat::random((nfft, 1), distr);
|
||||
timedata
|
||||
.push_column(timedata.column(0).mapv(|a| 2. * a).view())
|
||||
.unwrap();
|
||||
// Negative reference channel
|
||||
timedata
|
||||
.push_column(timedata.column(0).mapv(|a| -1. * a).view())
|
||||
.unwrap();
|
||||
|
||||
let mut aps = AvPowerSpectra::build(nfft, None, None, None).unwrap();
|
||||
if let ApsResult::OnlyLastResult(v) = aps.compute_last(&timedata) {
|
||||
let tf = v.tf(0, 1, Some(2));
|
||||
assert_eq!((&tf - 2.0 * Cflt::ONE).sum().abs(), 0.0);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn test_ap() {
|
||||
let nfft = 256;
|
||||
let distr = Normal::new(1.0, 1.0).unwrap();
|
||||
let timedata = Dmat::random((500 * nfft, 1), distr);
|
||||
let timedata = Dmat::random((100 * nfft, 1), distr);
|
||||
let timedata_mean_square = (&timedata * &timedata).sum() / (timedata.len() as Flt);
|
||||
|
||||
for wt in [Some(WindowType::Rect), Some(WindowType::Hann), Some(WindowType::Bartlett), Some(WindowType::Blackman), None] {
|
||||
for wt in [
|
||||
Some(WindowType::Rect),
|
||||
Some(WindowType::Hann),
|
||||
Some(WindowType::Bartlett),
|
||||
Some(WindowType::Blackman),
|
||||
None,
|
||||
] {
|
||||
let mut aps = AvPowerSpectra::build(nfft, wt, None, None).unwrap();
|
||||
if let ApsResult::OnlyLastResult(v) = aps.compute_last(&timedata) {
|
||||
let ap = v.ap(0);
|
||||
assert_abs_diff_eq!((&ap).sum().abs(), timedata_mean_square, epsilon = 4e-3);
|
||||
assert_abs_diff_eq!((&ap).sum().abs(), timedata_mean_square, epsilon = 8e-3);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user