Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion +adi/+AD9081/Base.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
% Dependent
function value = get.SamplingRate(obj)
if obj.ConnectedToDevice
value = double(obj.getAttributeLongLong('voltage0_i','sampling_frequency',obj.isOutput));
value = double(obj.getAttributeLongLong('voltage0_i','sampling_frequency',obj.isOutput,obj.iioDev));
else
value = NaN;
end
Expand Down
135 changes: 76 additions & 59 deletions test/AD9081HWTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
properties
uri = 'ip:analog.local';
author = 'ADI';
board = 'zynqmp-zcu102-rev10-ad9081-vm8-l4';
end

methods(TestClassSetup)
Expand Down Expand Up @@ -83,7 +84,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,...
Expand All @@ -92,15 +93,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,...
Expand All @@ -109,15 +104,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);
Expand All @@ -128,27 +133,17 @@ 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, ...
'num_coarse_attr_channels', cdc, ...
'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,...
Expand All @@ -157,16 +152,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,testCase.board+"_TwoChanDDS_Chan1");
freqEst2 = testCase.estFrequencyMax(out(:,2),srRx,true,testCase.board+"_TwoChanDDS_Chan2");
% freqEst1 = meanfreq(double(real(out(:,1))),rx.SamplingRate);
% freqEst2 = meanfreq(double(real(out(:,2))),rx.SamplingRate);

Expand All @@ -181,14 +191,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(...
Expand All @@ -200,24 +220,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);
Expand All @@ -226,23 +238,35 @@ function testAD9081RxWithTxData(testCase)
end

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(...
Expand All @@ -255,25 +279,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,testCase.board+"_TwoChanData_Chan1");
freqEst2 = testCase.estFrequencyMax(out(:,2),srRx,true,testCase.board+"_TwoChanData_Chan2");
% freqEst = meanfreq(double(real(out)),rx.SamplingRate);

testCase.verifyTrue(valid);
Expand Down
5 changes: 5 additions & 0 deletions test/HardwareTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
methods(TestClassSetup)
function UpdateURIFromEnv(testCase)
urienv = getenv('IIO_URI');
boardenv = getenv('board');
if ~isempty(urienv)
fprintf('Overriding default URI with: %s\n',urienv);
testCase.uri = urienv;
end
if isprop(testCase, 'board') && ~isempty(boardenv)
fprintf('Overriding default board name with: %s\n',boardenv);
testCase.board = boardenv;
end
end
end

Expand Down
Loading