Skip to content

Commit

Permalink
Add ad7768 signal tests
Browse files Browse the repository at this point in the history
Signed-off-by: Julia Pineda <[email protected]>
  • Loading branch information
jpineda3 committed Oct 2, 2023
1 parent 0747304 commit 643d4fb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
4 changes: 2 additions & 2 deletions +adi/+AD7768/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
Timeout = Inf
kernelBuffersCount = 2
dataTypeStr = 'int32'
phyDevName = 'ad7768'
devName = 'ad7768'
phyDevName = 'cf_axi_adc'
devName = 'cf_axi_adc'
end

properties (Nontunable, Hidden, Constant)
Expand Down
61 changes: 57 additions & 4 deletions test/AD7768Tests.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
classdef AD7768Tests < HardwareTests

properties(TestParameter)
end

properties
uri = 'ip:analog-2.local';
uri = 'ip:192.168.10.172';
author = 'ADI';
end

properties(TestParameter)
% start frequency. stop frequency, step, tolerance, repeats
signal_test = {{1000,100000,2500,0.015,1}};
sample_rate = {'256000', '128000', '64000', ...
'32000', '16000', '8000', '4000', ...
'2000', '1000'};
end

methods(TestClassSetup)
% Check hardware connected
Expand All @@ -14,6 +20,17 @@ function CheckForHardware(testCase)
testCase.CheckDevice('ip',Device,testCase.uri(4:end),false);
end
end

methods (Static)
function freq = estFrequencyMax(data,fs)
nSamp = length(data);
FFTRxData = fftshift(10*log10(abs(fft(data))));
df = fs/nSamp; freqRangeRx = (0:df:fs/2-df).';
% Disregard DC
[~,ind] = maxk(FFTRxData(end-length(freqRangeRx)+1:end,:),2);
freq = max(freqRangeRx(ind));
end
end

methods (Test)

Expand All @@ -23,6 +40,42 @@ function testAD7768Smoke(testCase)
adc.release();
testCase.assertTrue(sum(abs(double(data)))>0);
end

function testAD7768_Signal(testCase,signal_test)
% Signal source setup
m2k_class = instr_m2k();
m2k = m2k_class.connect(getenv('M2K_URI'), false);
siggen = m2k_class.create_instr(m2k, "siggen");
% ADC setup
adc = adi.AD7768.Rx;
adc.uri = testCase.uri;
adc.EnabledChannels = [1 2 3 4 5 6 7 8];

start = signal_test{1};
stop = signal_test{2};
step = signal_test{3};
tol = signal_test{4};
repeats = signal_test{5};
numints = round((stop-start)/step);
for ii = 1:repeats
ind = randi([0, numints]);
frequency = start+(step*ind);
m2k_class.control(siggen, 0, [frequency, 0.5, 0.5, 0]);
m2k_class.control(siggen, 1, [frequency, 0.5, 0.5, 0]);
for k = 1:5
data = adc();
end
for ch = adc.EnabledChannels
%FIXME: estFrequencyMax returns 'MATLAB:UndefinedFunction'
freqEst = estFrequencyMax(double(data(ch)),str2double(adc.SampleRate));
testCase.assertTrue(sum(abs(double(data(ch))))>0);
testCase.verifyEqual(freqEst,frequency,'RelTol',tol,...
'Frequency of signal unexpected')
end
end
adc.release();
m2k_class.contextClose();
end

end

Expand Down

0 comments on commit 643d4fb

Please sign in to comment.