From 75a20210d0633f1b69ccc3232362994ae440f691 Mon Sep 17 00:00:00 2001 From: Julia Pineda Date: Thu, 23 May 2024 10:56:57 +0800 Subject: [PATCH] Use tx sr for frequency and waveform generation Signed-off-by: Julia Pineda --- test/AD9081HWTests.m | 132 ++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 58 deletions(-) diff --git a/test/AD9081HWTests.m b/test/AD9081HWTests.m index aa75b137..c2e97158 100644 --- a/test/AD9081HWTests.m +++ b/test/AD9081HWTests.m @@ -83,7 +83,7 @@ function testAD9081Rx(testCase) function testAD9081RxWithTxDDS(testCase) % Test DDS output tx = adi.AD9081.Tx('uri',testCase.uri); - [cdc, fdc, dc] = tx.GetDataPathConfiguration(); + [cdc, fdc, dc, srTx] = tx.GetDataPathConfiguration(); testCase.log(sprintf('cdc: %d, fdc: %d, dc: %d',cdc, fdc, dc)) tx = adi.AD9081.Tx(... 'uri',testCase.uri,... @@ -92,15 +92,9 @@ function testAD9081RxWithTxDDS(testCase) 'num_fine_attr_channels', fdc, ... 'num_dds_channels', fdc*2); tx.DataSource = 'DDS'; - toneFreq = 45e6; -% tx.DDSFrequencies = repmat(toneFreq,2,2); -% tx.DDSScales = repmat(0.9,2,2); - tx.DDSSingleTone(toneFreq, 0.1, 1); -% tx.NCOEnables(:) = 1; - tx(); - pause(1); + rx = adi.AD9081.Rx('uri',testCase.uri); - [cdc, fdc, dc] = rx.GetDataPathConfiguration(); + [cdc, fdc, dc, srRx] = rx.GetDataPathConfiguration(); testCase.log(sprintf('cdc: %d, fdc: %d, dc: %d',cdc, fdc, dc)) rx = adi.AD9081.Rx(... 'uri',testCase.uri,... @@ -109,15 +103,25 @@ function testAD9081RxWithTxDDS(testCase) 'num_fine_attr_channels', fdc); rx.EnabledChannels = 1; valid = false; + + toneFreq = rand(1) * srRx / 2; +% tx.DDSFrequencies = repmat(toneFreq,2,2); +% tx.DDSScales = repmat(0.9,2,2); + tx.DDSSingleTone(toneFreq, 0.1, 1); +% tx.NCOEnables(:) = 1; + tx(); + pause(1); + for k=1:10 [out, valid] = rx(); end - sr = rx.SamplingRate; + % sr = rx.SamplingRate; rx.release(); + tx.release(); % plot(real(out)); % testCase.estFrequency(out,rx.SamplingRate); - freqEst = meanfreq(double(real(out)),sr); + freqEst = meanfreq(double(real(out)),srRx); testCase.verifyTrue(valid); testCase.verifyGreaterThan(sum(abs(double(out))),0); @@ -128,7 +132,7 @@ function testAD9081RxWithTxDDS(testCase) function testAD9081RxWithTxDDSTwoChan(testCase) % Test DDS output tx = adi.AD9081.Tx('uri',testCase.uri); - [cdc, fdc, dc, sr] = tx.GetDataPathConfiguration(); + [cdc, fdc, dc, srTx] = tx.GetDataPathConfiguration(); tx = adi.AD9081.Tx(... 'uri',testCase.uri,... 'num_data_channels', dc, ... @@ -136,19 +140,9 @@ function testAD9081RxWithTxDDSTwoChan(testCase) 'num_fine_attr_channels', fdc, ... 'num_dds_channels', fdc*2); tx.DataSource = 'DDS'; - toneFreq1 = sr/4; - toneFreq2 = sr/5; -% tx.DDSFrequencies = [toneFreq1,toneFreq1,toneFreq2,toneFreq2;... -% 0,0,0,0]; -% tx.DDSScales = [1,1,1,1;0,0,0,0].*0.029; - tx.DDSPhases = [90000,0,90000,0; 0,0,0,0]; - tx.DDSFrequencies = repmat(horzcat([toneFreq1,toneFreq1], ... - [toneFreq2,toneFreq2]),2,1); - tx.DDSScales = repmat([1,1;0,0].*0.029,1,2); - tx(); - pause(1); + rx = adi.AD9081.Rx('uri',testCase.uri); - [cdc, fdc, dc] = rx.GetDataPathConfiguration(); + [cdc, fdc, dc, srRx] = rx.GetDataPathConfiguration(); testCase.log(sprintf('cdc: %d, fdc: %d, dc: %d',cdc, fdc, dc)) rx = adi.AD9081.Rx(... 'uri',testCase.uri,... @@ -157,16 +151,31 @@ function testAD9081RxWithTxDDSTwoChan(testCase) 'num_fine_attr_channels', fdc); rx.EnabledChannels = [1 2]; valid = false; + + toneFreqs = rand(2) * srRx / 2; + toneFreq1 = toneFreqs(1); + toneFreq2 = toneFreqs(2); +% tx.DDSFrequencies = [toneFreq1,toneFreq1,toneFreq2,toneFreq2;... +% 0,0,0,0]; +% tx.DDSScales = [1,1,1,1;0,0,0,0].*0.029; + tx.DDSPhases = [90000,0,90000,0; 0,0,0,0]; + tx.DDSFrequencies = repmat(horzcat([toneFreq1,toneFreq1], ... + [toneFreq2,toneFreq2]),2,1); + tx.DDSScales = repmat([1,1;0,0].*0.029,1,2); + tx(); + pause(1); + for k=1:10 [out, valid] = rx(); end - sr = rx.SamplingRate; + % sr = rx.SamplingRate; rx.release(); + tx.release(); % plot(real(out)); % testCase.estFrequency(out,sr); - freqEst1 = testCase.estFrequencyMax(out(:,1),sr,true,'TwoChanDDS_Chan1'); - freqEst2 = testCase.estFrequencyMax(out(:,2),sr,true,'TwoChanDDS_Chan2'); + freqEst1 = testCase.estFrequencyMax(out(:,1),srRx,true,'TwoChanDDS_Chan1'); + freqEst2 = testCase.estFrequencyMax(out(:,2),srRx,true,'TwoChanDDS_Chan2'); % freqEst1 = meanfreq(double(real(out(:,1))),rx.SamplingRate); % freqEst2 = meanfreq(double(real(out(:,2))),rx.SamplingRate); @@ -181,14 +190,24 @@ function testAD9081RxWithTxDDSTwoChan(testCase) function testAD9081RxWithTxData(testCase) tx = adi.AD9081.Tx('uri',testCase.uri); - [cdc, fdc, dc, sr] = tx.GetDataPathConfiguration(); + [cdc, fdc, dc, srTx] = tx.GetDataPathConfiguration(); + + rx = adi.AD9081.Rx('uri',testCase.uri); + [cdc, fdc, dc, srRx] = rx.GetDataPathConfiguration(); + testCase.log(sprintf('cdc: %d, fdc: %d, dc: %d',cdc, fdc, dc)) + rx = adi.AD9081.Rx(... + 'uri',testCase.uri,... + 'num_data_channels', dc, ... + 'num_coarse_attr_channels', cdc, ... + 'num_fine_attr_channels', fdc); + rx.EnabledChannels = 1; % Test Tx DMA data output - amplitude = 2^15; frequency = sr/6; + amplitude = 2^15; frequency = rand(1) * srRx / 2; swv1 = dsp.SineWave(amplitude, frequency); swv1.ComplexOutput = false; swv1.SamplesPerFrame = 2^20; - swv1.SampleRate = sr; + swv1.SampleRate = srTx; y = swv1(); tx = adi.AD9081.Tx(... @@ -200,24 +219,16 @@ function testAD9081RxWithTxData(testCase) tx.DataSource = 'DMA'; tx.EnableCyclicBuffers = true; tx(y); - rx = adi.AD9081.Rx('uri',testCase.uri); - [cdc, fdc, dc] = rx.GetDataPathConfiguration(); - testCase.log(sprintf('cdc: %d, fdc: %d, dc: %d',cdc, fdc, dc)) - rx = adi.AD9081.Rx(... - 'uri',testCase.uri,... - 'num_data_channels', dc, ... - 'num_coarse_attr_channels', cdc, ... - 'num_fine_attr_channels', fdc); - rx.EnabledChannels = 1; for k=1:10 [out, valid] = rx(); end - sr = rx.SamplingRate; + % sr = rx.SamplingRate; rx.release(); + tx.release(); % plot(real(out)); - freqEst = meanfreq(double(real(out)),sr); + freqEst = testCase.estFrequencyMax(double(real(out)),srRx); testCase.verifyTrue(valid); testCase.verifyGreaterThan(sum(abs(double(out))),0); @@ -228,21 +239,33 @@ function testAD9081RxWithTxData(testCase) function testAD9081RxWithTxDataTwoChan(testCase) tx = adi.AD9081.Tx('uri',testCase.uri); - [cdc, fdc, dc, sr] = tx.GetDataPathConfiguration(); + [cdc, fdc, dc, srTx] = tx.GetDataPathConfiguration(); + + rx = adi.AD9081.Rx('uri',testCase.uri); + [cdc, fdc, dc, srRx] = rx.GetDataPathConfiguration(); + testCase.log(sprintf('cdc: %d, fdc: %d, dc: %d',cdc, fdc, dc)) + rx = adi.AD9081.Rx(... + 'uri',testCase.uri,... + 'num_data_channels', dc, ... + 'num_coarse_attr_channels', cdc, ... + 'num_fine_attr_channels', fdc); + rx.EnabledChannels = [1,2]; + % Test Tx DMA data output - amplitude = 2^15; toneFreq1 = sr/5; + toneFreqs = rand(2) * srRx / 2; + amplitude = 2^15; toneFreq1 = toneFreqs(1); swv1 = dsp.SineWave(amplitude, toneFreq1); swv1.ComplexOutput = false; swv1.SamplesPerFrame = 2^20; - swv1.SampleRate = sr; + swv1.SampleRate = srTx; y1 = swv1(); - amplitude = 2^15; toneFreq2 = sr/8; + amplitude = 2^15; toneFreq2 = toneFreqs(2); swv1 = dsp.SineWave(amplitude, toneFreq2); swv1.ComplexOutput = false; swv1.SamplesPerFrame = 2^20; - swv1.SampleRate = sr; + swv1.SampleRate = srTx; y2 = swv1(); tx = adi.AD9081.Tx(... @@ -255,25 +278,18 @@ function testAD9081RxWithTxDataTwoChan(testCase) tx.EnableCyclicBuffers = true; tx.EnabledChannels = [1,2]; tx([y1,y2]); - rx = adi.AD9081.Rx('uri',testCase.uri); - [cdc, fdc, dc] = rx.GetDataPathConfiguration(); - testCase.log(sprintf('cdc: %d, fdc: %d, dc: %d',cdc, fdc, dc)) - rx = adi.AD9081.Rx(... - 'uri',testCase.uri,... - 'num_data_channels', dc, ... - 'num_coarse_attr_channels', cdc, ... - 'num_fine_attr_channels', fdc); - rx.EnabledChannels = [1,2]; + for k=1:10 [out, valid] = rx(); end - sr = rx.SamplingRate; + % sr = rx.SamplingRate; rx.release(); + tx.release(); % plot(real(out)); % testCase.estFrequency(out,rx.SamplingRate); - freqEst1 = testCase.estFrequencyMax(out(:,1),sr,true,'TwoChanData_Chan1'); - freqEst2 = testCase.estFrequencyMax(out(:,2),sr,true,'TwoChanData_Chan2'); + freqEst1 = testCase.estFrequencyMax(out(:,1),srRx,true,'TwoChanData_Chan1'); + freqEst2 = testCase.estFrequencyMax(out(:,2),srRx,true,'TwoChanData_Chan2'); % freqEst = meanfreq(double(real(out)),rx.SamplingRate); testCase.verifyTrue(valid);