Search the Community

Showing results for tags 'plot'.

• Search By Tags

Type tags separated by commas.

Forums

• News
• New Users Introduction
• Announcements
• Digilent Technical Forums
• FPGA
• Digilent Microcontroller Boards
• Non-Digilent Microcontrollers
• Scopes & Instruments
• LabVIEW
• FRC
• Other
• General Discussion
• Project Vault
• Learn
• Suggestions & Feedback
• Sales Questions
• Off Topic
• Educators
• Technical Based Off-Topic Discussions

Interests

Found 2 results

1. Hi, I'm working on a WaveForms script which would be able to generate chart with the frequency profile of a liquid. For this, I need to use a Wavegen and a Scope: first I need to set the generator to a certain frequency and then I'd like to check the power of that signal on the scope. Between the probes of the generator and the scope there will be the liquid I would like to test. I created a basic script to step from 1 Hz to 150 Hz, check that signal with the scope, repeat this loop 5 times, and calculate the min, max and average values at each frequency. Although the script works, I have a few questions: * I couldn't find any documentation about the Scope.Channelx.fftmagnitude and fftfrequency arrays. Where should I look for them? Are there any other properties related to the FFT configuration? * Is there a way to set the number of BINs and samples of the scope's FFT? * Can I somehow use the Goertzel algorithm instead of FFT? (The Görtzel algorithm is designed to tell us the power of a signal at one predefined frequency. https://en.wikipedia.org/wiki/Goertzel_algorithm) I would need this to get the power for the exact Hz value I define, and not the closest one I have from the FFT like I do it now. * Is there a way to change the color/style of the charts? Here is the script itself, but bear in mind that it is just the very first version const hzmax = 150; // the maximum frequency to measure const csamples = 5; // the number of samples to measure for each frequency const cdatapoints = 150; // chart X-axis resolution (currently: 1 datapoint / 1 Hz) var datapoints = new Array(4); // datapoint array datapoints = new Array(cdatapoints); // max datapoints = new Array(cdatapoints); // avg datapoints = new Array(cdatapoints); // min datapoints = new Array(cdatapoints * csamples); // raw data // clear the raw data array for(var j = 0; j < cdatapoints * csamples; j++) { datapoints[j] = 0; } // generate the freqeuncies to measure var frequencies = new Array(cdatapoints); for(var j = 0; j < cdatapoints; j++) { frequencies[j] = j+1; } { // configure plot plot1.X.Units.text = "Hz"; plot1.X.Offset.value = -hzmax/2 plot1.X.Range.value = hzmax; plot1.Y1.AutoScale.checked = false; plot1.Y2.AutoScale.checked = false; plot1.Y3.AutoScale.checked = false; plot1.Y4.AutoScale.checked = false; const vmax = 1.00; const vmin = 0.98; var offset = -(vmin + (vmax - vmin)/2); var range = (vmax - vmin); plot1.Y1.Offset.value = offset; plot1.Y2.Offset.value = offset; plot1.Y3.Offset.value = offset; plot1.Y4.Offset.value = offset; plot1.Y1.Range.value = range; plot1.Y2.Range.value = range; plot1.Y3.Range.value = range; plot1.Y4.Range.value = range; } { // configure wavegen Wavegen1.Channel1.Mode.text = "Simple"; Wavegen1.Channel1.Simple.Type.text = "Sine"; } { // configure scope Scope1.BufferSize.value = 1; Scope1.Buffer.value = 1; Scope1.Time.Mode.text = "Shift"; Scope1.Channel1.checked = true; Scope1.Channel2.checked = false; } Wavegen1.run(); for (var n=0; n<csamples; n++) { Scope1.Time.Samples.value = 1024; for (var i=0; i<hzmax; i++) { // change the frequency to the next one var frequency = frequencies[i]; Wavegen1.Channel1.Simple.Frequency.text = frequency; Scope1.Time.Rate.value = frequency * 256; print("Frequency: ",frequency," Hz | Running @ ",Scope1.Time.Rate.value," Hz | ", Scope1.Time.Samples.value," samples"); // take a single sample Scope1.single(); Scope1.wait(); // check out the FFT values var rgmag = Scope1.Channel1.fftmagnitude; var rghz = Scope1.Channel1.fftfrequency; var c = rgmag.length; var minHzDistance = frequency; // check all the FFT values, and get the one closest to our inspected frequency for(var j = 0; j < c; j++) { var hz = rghz[j] var hzDistance = frequency - hz; if (hzDistance < 0) { hzDistance = -hzDistance; } if (hzDistance <= minHzDistance) { minHzDistance = hzDistance; datapoints[i*csamples + n] = rgmag[j]; } } // calculate the min, max, avg values var rgmin = 1000.0; var rgavg = 0.0; var rgmax = 0.0; var validsamples = 0; for(var j = 0; j < csamples; j++) { currentsample = datapoints[i*csamples + j]; if (currentsample != 0) { if (currentsample < rgmin) { rgmin = currentsample; } if (currentsample > rgmax) { rgmax = currentsample; } rgavg += currentsample; validsamples++; } } rgavg /= validsamples; print("Min:",rgmin," V | Avg:",rgavg," V | Max:",rgmax," V | error: +/-",minHzDistance," Hz"); print(); // save the calculated data into their arrays datapoints[i] = rgmax; datapoints[i] = rgavg; datapoints[i] = rgmin; // check if the error if too high if (minHzDistance > 0.5) { Scope1.Time.Samples.value *= 2; i--; } // plot the most recent values on the chart plot1.Y1.data = datapoints; // max plot1.Y2.data = datapoints; // avg plot1.Y3.data = datapoints; // min } }