Forum
Please or Register to create posts and topics.

How to export the "Average Traces" from spectrum to script block?

Hi

This is an spectrum view

How is possible to use ( or export ) the "Average Traces " to script block for do some other proceed ?

 

And also you can see many Traces in Spectrum View , Max hold , Average and...

is it possible to do some arithmetic between them ? for example plot MAX HOLD + AVERAGE or something else ?

 

You can get the Average trace in the script block by adding a DSP processing block of type "Average" and connect it to the script blocks input, then the script block will convert "raw" spectra data fed into its input into a stream of averaged samples at its output:

(there are also other processing blocks like MinHold or MaxHold, see https://v6-forum.aaronia.de/forum/topic/rtsa-suite-pro-java-script-support/ for a list)

import { DSPStream } from "dspstream.js";

// function receives the result of the "Average" processing block and simply forwards it to the script block output

function onPacket(flags, meta, samples) {

let packet = meta;
packet.samples = samples();
DSPStream.sendPacket(0, packet);
}

async function init() {
DSPStream.addBlocks({avg: { type: "Average", config: { avgsamples: 10000, avgpower: true }}).then(() => {
return DSPStream.connectBlocks([{ source: "in0", drain: "avg" }, { source: "avg", drain: "script", input: "in0" }]);
}).then(() => {
DSPStream.receivePackets(0, onPacket);
});
}

function main() {
}

init().then(() => {
main();
});

David3542 has reacted to this post.
David3542
Quote from David3542 on 15/05/2022, 09:02

And also you can see many Traces in Spectrum View , Max hold , Average and...

is it possible to do some arithmetic between them ? for example plot MAX HOLD + AVERAGE or something else ?

There is the "Binary Arithmetic" block for that.

David3542 has reacted to this post.
David3542
Quote from mm_dev on 16/05/2022, 09:55

You can get the Average trace in the script block by adding a DSP processing block of type "Average" and connect it to the script blocks input, then the script block will convert "raw" spectra data fed into its input into a stream of averaged samples at its output:

(there are also other processing blocks like MinHold or MaxHold, see https://v6-forum.aaronia.de/forum/topic/rtsa-suite-pro-java-script-support/ for a list)

import { DSPStream } from "dspstream.js";

// function receives the result of the "Average" processing block and simply forwards it to the script block output

function onPacket(flags, meta, samples) {

let packet = meta;
packet.samples = samples();
DSPStream.sendPacket(0, packet);
}

async function init() {
DSPStream.addBlocks({avg: { type: "Average" }}).then(() => {
return DSPStream.connectBlocks([{ source: "in0", drain: "avg" }, { source: "avg", drain: "script", input: "in0" }]);
}).then(() => {
DSPStream.receivePackets(0, onPacket);
});
}

function main() {
}

init().then(() => {
main();
});

 

 

Thank you for your reply

in the spectrum , Average trace has some good setting

When we use this trace with DSP processing  Block, then is it possible to do this setting ?

could  you please add this setting in your example code ?

Thanks

Changed the code sample to include "Average Samples" and "Average Power" config options. The other options are not available in the script block at this time.