Repository navigation
Adding Digital Filtering example for NI-SCOPE #2234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ni-jfitzger
merged 24 commits into
ni:master
from
NI-velmurugan:users/velmurugan/add-niscope-digital-filtering
Nov 20, 2026
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
119c95d
Adding Digital Filtering in NI-Scope
NI-velmurugan f306d98
Merge branch 'master' into users/velmurugan/add-niscope-digital-filte…
NI-velmurugan 45bc826
Fixing PR comments
NI-velmurugan 6cbab9f
Trigger CI build
NI-velmurugan 1feb0e0
Merge branch 'master' into users/velmurugan/add-niscope-digital-filte…
NI-velmurugan 005888b
Updating the graph label and order
NI-velmurugan 33f1690
Trigger CI build
NI-velmurugan 31cef6d
Trigger CI build
NI-velmurugan b1831f4
Trigger CI build
NI-velmurugan f09fa96
Trigger CI build
NI-velmurugan 32c6789
Removed Graph plotting
NI-velmurugan 6260ae1
removing continuous option
NI-velmurugan 5ff15cc
Adding Source Waveform example in NI-Digital
NI-velmurugan b151b5e
Revert "Adding Source Waveform example in NI-Digital"
NI-velmurugan 2f84162
Merge branch 'ni:master' into master
NI-velmurugan 62c5e13
Merge branch 'master' into users/velmurugan/add-niscope-digital-filte…
NI-velmurugan 9c0be70
Trigger CI build
NI-velmurugan cbf1c6e
Trigger CI build
NI-velmurugan f4fbbe0
Trigger CI build
NI-velmurugan 32cff26
Trigger CI build
NI-velmurugan 3836077
Merge remote-tracking branch 'refs/remotes/origin/users/velmurugan/ad…
NI-velmurugan a9381bd
Trigger CI build
NI-velmurugan 2c7e685
Address review comments: rename channels, FFT units and add result co…
NI-velmurugan d5dbad2
Trigger CI build
NI-velmurugan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #!/usr/bin/python | ||
|
|
||
| import argparse | ||
| import niscope | ||
| import sys | ||
|
|
||
| FILTERS = { | ||
| 'NONE': niscope.ArrayMeasurement.NO_MEASUREMENT, | ||
| 'FIR': niscope.ArrayMeasurement.WINDOWED_FIR_FILTER, | ||
| 'BESSEL': niscope.ArrayMeasurement.BESSEL_FILTER, | ||
| 'BUTTERWORTH': niscope.ArrayMeasurement.BUTTERWORTH_FILTER, | ||
| 'CHEBYSHEV': niscope.ArrayMeasurement.CHEBYSHEV_FILTER, | ||
| } | ||
| FFT_AMP_SPECTRUM_UNITS = { | ||
| 'VOLTS_RMS': niscope.ArrayMeasurement.FFT_AMP_SPECTRUM_VOLTS_RMS, | ||
| 'DB': niscope.ArrayMeasurement.FFT_AMP_SPECTRUM_DB, | ||
| } | ||
|
|
||
|
|
||
| def example( | ||
| resource_name, channel_names, options, min_sample_rate, min_record_length, | ||
| filter_name, filter_type, cutoff_frequency, center_frequency, width, | ||
| fir_taps, fir_window, iir_order, fft_amp_spectrum_units, total_iterations, | ||
| ): | ||
| print(f'Starting acquisition on resource {resource_name}, for {total_iterations} iterations.') | ||
| with niscope.Session(resource_name=resource_name, options=options) as session: | ||
| session.configure_vertical(range=2.0, coupling=niscope.VerticalCoupling.DC) | ||
| session.configure_horizontal_timing(min_sample_rate=min_sample_rate, min_num_pts=min_record_length, ref_position=50.0, num_records=1, enforce_realtime=True) | ||
|
|
||
| channels = session.channels[channel_names] | ||
| channels.meas_filter_type = niscope.FilterType[filter_type] | ||
| channels.meas_filter_cutoff_freq = cutoff_frequency | ||
| channels.meas_filter_center_freq = center_frequency | ||
| channels.meas_filter_width = width | ||
| channels.meas_filter_taps = fir_taps | ||
| channels.meas_fir_filter_window = niscope.FIRFilterWindow[fir_window] | ||
| channels.meas_filter_order = iir_order | ||
| channels.meas_filter_transient_waveform_percent = 20.0 | ||
| channels.meas_filter_ripple = 0.5 | ||
|
|
||
| iterations = 0 | ||
| while iterations < total_iterations: | ||
| # The filter runs as a processing step before any other measurement; it is added and cleared on every acquisition | ||
| channels.add_waveform_processing(FILTERS[filter_name]) | ||
| try: | ||
| with session.initiate(): | ||
| channels.fetch_array_measurement(niscope.ArrayMeasurement.NO_MEASUREMENT) # Filtered waveform | ||
| channels.fetch_array_measurement(FFT_AMP_SPECTRUM_UNITS[fft_amp_spectrum_units]) # Spectrum | ||
| finally: | ||
| channels.clear_waveform_processing() | ||
| iterations += 1 | ||
|
|
||
| print('Completed {} acquisitions.'.format(iterations)) | ||
|
|
||
|
|
||
| def _main(argsv): | ||
| parser = argparse.ArgumentParser(description='Applies a digital filter to acquired waveforms and computes the filtered waveform and its FFT amplitude spectrum.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
| parser.add_argument('-n', '--resource-name', default='PXI1Slot3', help='Specifies the resource name of the device to initialize.') | ||
| parser.add_argument('-c', '--channels', default='0', help='Comma-separated list of channels to acquire') | ||
| parser.add_argument('-l', '--min-record-length', default=4096, type=int, help='Specifies the minimum number of points you require in the waveform record for each channel.') | ||
| parser.add_argument('-sr', '--min-sample-rate', default=10000000.0, type=float, help='Specify the sampling rate for the acquisition in Samples per second.') | ||
| parser.add_argument('-f', '--filter', default='CHEBYSHEV', choices=FILTERS.keys(), type=str.upper, help='Filter to apply') | ||
| parser.add_argument('-fft', '--fft-amp-spectrum-units', default='DB', choices=FFT_AMP_SPECTRUM_UNITS.keys(), type=str.upper, help='Units of the FFT amplitude spectrum') | ||
| parser.add_argument('-ft', '--filter-type', default='LOWPASS', choices=niscope.FilterType.__members__.keys(), type=str.upper, help='Specifies the type of filter, for both IIR and FIR filters.') | ||
| parser.add_argument('-cf', '--cutoff-frequency', default=2500000.0, type=float, help='Specifies the cutoff frequency in hertz for filters of type lowpass and highpass.') | ||
| parser.add_argument('-cc', '--center-frequency', default=500000.0, type=float, help='The center frequency in hertz for filters of type bandpass and bandstop.') | ||
| parser.add_argument('-w', '--width', default=100000.0, type=float, help='Specifies the width of bandpass and bandstop type filters in hertz.') | ||
| parser.add_argument('-t', '--fir-taps', default=25, type=int, help='Defines the number of taps (coefficients) for an FIR filter.') | ||
| parser.add_argument('-fw', '--fir-window', default='HANNING', choices=niscope.FIRFilterWindow.__members__.keys(), type=str.upper, help='Specifies the FIR window type.') | ||
| parser.add_argument('-o', '--iir-order', default=2, type=int, help='Specifies the order of an IIR filter.') | ||
| parser.add_argument('--total-iterations', default=100, type=int, help='Number of acquisitions to perform before stopping.') | ||
| parser.add_argument('-op', '--option-string', default='', type=str, help='Specifies initialization commands.') | ||
| args = parser.parse_args(argsv) | ||
| example( | ||
| args.resource_name, args.channels, args.option_string, args.min_sample_rate, args.min_record_length, | ||
| args.filter, args.filter_type, args.cutoff_frequency, args.center_frequency, args.width, | ||
| args.fir_taps, args.fir_window, args.iir_order, args.fft_amp_spectrum_units, args.total_iterations, | ||
| ) | ||
|
|
||
|
|
||
| def main(): | ||
| _main(sys.argv[1:]) | ||
|
|
||
|
|
||
| def test_example(): | ||
| options = {'simulate': True, 'driver_setup': {'Model': '5164', 'BoardType': 'PXIe', }, } | ||
| example( | ||
| 'PXI1Slot2', '0', options, 10000000.0, 4096, | ||
| 'CHEBYSHEV', 'LOWPASS', 2500000.0, 500000.0, 100000.0, | ||
| 25, 'HANNING', 2, 'DB', 2, | ||
| ) | ||
|
|
||
|
|
||
| def test_main(): | ||
| cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:5164; BoardType:PXIe', '--total-iterations', '2', ] | ||
| _main(cmd_line) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.