Skip to content

Commit

Permalink
Use tx sr for frequency and waveform generation
Browse files Browse the repository at this point in the history
Signed-off-by: Julia Pineda <[email protected]>
  • Loading branch information
jpineda3 committed Jul 17, 2024
1 parent 15e8c89 commit ef946a0
Showing 1 changed file with 74 additions and 58 deletions.
132 changes: 74 additions & 58 deletions test/AD9081HWTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,...
Expand All @@ -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,...
Expand All @@ -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);
Expand All @@ -128,27 +132,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 +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);

Expand All @@ -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(...
Expand All @@ -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);
Expand All @@ -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(...
Expand All @@ -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);
Expand Down

0 comments on commit ef946a0

Please sign in to comment.