Skip to content

Commit fb2caa7

Browse files
committed
review comments addressed
1 parent e0c07d0 commit fb2caa7

2 files changed

Lines changed: 10 additions & 19 deletions

File tree

src/nirfsa/examples/nirfsa_getting_started_iq.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,27 @@ def example(resource_name, options, iq_carrier_frequency, reference_level, numbe
1212
rfsa_session.reference_level = reference_level
1313
rfsa_session.iq_carrier_frequency = iq_carrier_frequency
1414
rfsa_session.number_of_samples = number_of_samples
15-
rfsa_session.iq_rate = 1e6
1615

17-
iq_data_array = np.zeros(number_of_samples, dtype=np.complex128)
16+
# Do something useful with the data.
17+
# We will present average power: 10log(((I^2 + Q ^2) / 2R) * 1000), where
18+
# R = 50 Ohms.
1819

20+
iq_data_array = np.zeros(number_of_samples, dtype=np.complex128)
1921
wfm_info = rfsa_session.read_iq_single_record_into(iq_data_array)
20-
2122
samples = np.asarray(wfm_info.samples)
2223
accumulator = 0.0
23-
24-
# Do something useful with the data.
25-
# We will present average power: 10log(((I^2 + Q ^2) / 2R) * 1000), where
26-
# R = 50 Ohms.
2724
if len(samples) > 0:
2825
for sample in samples:
2926
magnitude_squared = sample.real * sample.real + sample.imag * sample.imag
30-
3127
# we need to handle this because log(0) return a range error.
3228
if magnitude_squared == 0.0:
3329
magnitude_squared = 0.00000001
34-
3530
accumulator += 10.0 * np.log10((magnitude_squared / (2.0 * 50.0)) * 1000.0)
36-
3731
print('Average power = %0.1f dBm' % (accumulator / len(samples)))
3832

3933

4034
def _main(argsv):
41-
parser = argparse.ArgumentParser(description='Acquires a power spectrum using NI-RFSA.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
35+
parser = argparse.ArgumentParser(description='Acquires IQ data using NI-RFSA.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
4236
parser.add_argument('-n', '--resource-name', default='PXI1Slot2', help='Resource name of the NI RF signal analyzer.')
4337
parser.add_argument('-c', '--iq-carrier-frequency', default=1e9, type=float, help='IQ carrier frequency in Hz.')
4438
parser.add_argument('-r', '--reference-level', default=0.0, type=float, help='Reference level in dBm.')

src/nirfsa/examples/nirfsa_getting_started_spectrum.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
import sys
55

66

7-
def example(resource_name, options, center_frequency, span, reference_level, number_of_spectral_lines):
7+
def example(resource_name, options, center_frequency, span, reference_level):
88
with nirfsa.Session(resource_name=resource_name, id_query=False, reset_device=False, options=options) as rfsa_session:
99
# Configurations
1010
rfsa_session.acquisition_type = nirfsa.AcquisitionType.SPECTRUM
1111
rfsa_session.reference_level = reference_level
1212
rfsa_session.resolution_bandwidth = 10e3
13-
1413
rfsa_session.configure_spectrum_frequency(center_frequency=center_frequency, span=span)
15-
rfsa_session.number_of_spectral_lines = number_of_spectral_lines
1614

17-
spectrum_buf = np.zeros(rfsa_session.number_of_spectral_lines, dtype=np.float64)
15+
spectrum_buffer = np.zeros(rfsa_session.number_of_spectral_lines, dtype=np.float64)
1816

19-
spectrum_info = rfsa_session.read_power_spectrum_into(spectrum_buf, timeout=10.0)
17+
spectrum_info = rfsa_session.read_power_spectrum_into(spectrum_buffer, timeout=10.0)
2018

2119
# Do something useful with the data.
2220
# We will find the highest peak in a bin, which is not the actual highest
@@ -39,10 +37,9 @@ def _main(argsv):
3937
parser.add_argument('-c', '--center-frequency', default=1e9, type=float, help='Center frequency in Hz.')
4038
parser.add_argument('-s', '--span', default=100e6, type=float, help='Span in Hz.')
4139
parser.add_argument('-r', '--reference-level', default=0.0, type=float, help='Reference level in dBm.')
42-
parser.add_argument('-l', '--number-of-spectral-lines', default=1024, type=int, help='Number of spectral lines to acquire.')
4340
parser.add_argument('-op', '--option-string', default='', type=str, help='Option string for the session.')
4441
args = parser.parse_args(argsv)
45-
example(args.resource_name, args.option_string, args.center_frequency, args.span, args.reference_level, args.number_of_spectral_lines)
42+
example(args.resource_name, args.option_string, args.center_frequency, args.span, args.reference_level)
4643

4744

4845
def main():
@@ -55,7 +52,7 @@ def test_example():
5552

5653

5754
def test_main():
58-
cmd_line = ['--resource-name', 'simulated5841', '--center-frequency', '1e9', '--span', '100e6', '--reference-level', '-10', '--number-of-spectral-lines', '1024', '--option-string', 'Simulate=1, DriverSetup=Model:5841']
55+
cmd_line = ['--resource-name', 'simulated5841', '--center-frequency', '1e9', '--span', '100e6', '--reference-level', '-10', '--option-string', 'Simulate=1, DriverSetup=Model:5841']
5956
_main(cmd_line)
6057

6158

0 commit comments

Comments
 (0)