Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 2ee1ad6

Browse files
authored
Merge pull request #30 from analogdevicesinc/custom-filters-ad9361
Add custom filters in AD936X objects
2 parents 22a2ace + 5ad7a45 commit 2ee1ad6

File tree

7 files changed

+230
-15
lines changed

7 files changed

+230
-15
lines changed

+adi/+AD9361/Base.m

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
channelCount = 2;
1616
end
1717

18+
properties (Nontunable, Logical)
19+
%EnableCustomFilter Enable Custom Filter
20+
% Enable use of custom filter file to set SamplingRate,
21+
% RFBandwidth, and FIR in datapaths
22+
EnableCustomFilter = false;
23+
end
24+
25+
properties (Nontunable)
26+
%CustomFilterFileName Custom Filter File Name
27+
% Path to custom filter file created from filter wizard
28+
CustomFilterFileName = '';
29+
end
30+
1831
properties (Abstract)
1932
%CenterFrequency Center Frequency
2033
% RF center frequency, specified in Hz as a scalar. The
@@ -69,7 +82,23 @@ function delete(obj)
6982
end
7083
obj.channelCount = value;
7184
end
72-
85+
% Check EnableCustomFilter
86+
function set.EnableCustomFilter(obj, value)
87+
validateattributes( value, { 'logical' }, ...
88+
{ }, ...
89+
'', 'EnableCustomFilter');
90+
obj.EnableCustomFilter = value;
91+
end
92+
% Check CustomFilterFileName
93+
function set.CustomFilterFileName(obj, value)
94+
validateattributes( value, { 'char' }, ...
95+
{ }, ...
96+
'', 'CustomFilterFileName');
97+
obj.CustomFilterFileName = value;
98+
if obj.EnableCustomFilter && obj.ConnectedToDevice %#ok<MCSUP>
99+
writeFilterFile(obj);
100+
end
101+
end
73102
end
74103

75104
%% API Functions
@@ -101,6 +130,16 @@ function teardownLibad9361(~)
101130
end
102131
end
103132

133+
function writeFilterFile(obj)
134+
fir_data_file = obj.CustomFilterFileName;
135+
fir_data_str = fileread(fir_data_file);
136+
obj.setAttributeRAW('voltage0','filter_fir_en','0',false);
137+
obj.setAttributeRAW('voltage0','filter_fir_en','0',true);
138+
obj.setDeviceAttributeRAW('filter_fir_config',fir_data_str);
139+
obj.setAttributeRAW('voltage0','filter_fir_en','1',true);
140+
obj.setAttributeRAW('voltage0','filter_fir_en','1',false);
141+
end
142+
104143
end
105144

106145
%% External Dependency Methods

+adi/+AD9361/Rx.m

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
'', 'RFBandwidth');
190190
end
191191
obj.RFBandwidth = value;
192-
if obj.ConnectedToDevice
192+
if obj.ConnectedToDevice && ~obj.EnableCustomFilter
193193
id = 'voltage0';
194194
obj.setAttributeLongLong(id,'rf_bandwidth',value,strcmp(obj.Type,'Tx'),30);
195195
end
@@ -207,7 +207,7 @@
207207
end
208208

209209
obj.SamplingRate = value;
210-
if obj.ConnectedToDevice
210+
if obj.ConnectedToDevice && ~obj.EnableCustomFilter
211211
if libisloaded('libad9361')
212212
calllib('libad9361','ad9361_set_bb_rate',obj.iioDevPHY,int32(value));
213213
else
@@ -294,27 +294,36 @@ function setupInit(obj)
294294
% Do writes directly to hardware without using set methods.
295295
% This is required sine Simulink support doesn't support
296296
% modification to nontunable variables at SetupImpl
297+
298+
% Gains
297299
obj.setAttributeRAW('voltage0','gain_control_mode',obj.GainControlModeChannel0,false);
298300
if obj.channelCount>2
299301
obj.setAttributeRAW('voltage1','gain_control_mode',obj.GainControlModeChannel1,false);
300302
end
303+
if strcmp(obj.GainControlModeChannel0,'manual')
304+
obj.setAttributeLongLong('voltage0','hardwaregain',obj.GainChannel0,false);
305+
end
306+
if strcmp(obj.GainControlModeChannel1,'manual') && (obj.channelCount>2)
307+
obj.setAttributeLongLong('voltage1','hardwaregain',obj.GainChannel1,false);
308+
end
309+
% Trackings
301310
obj.setAttributeBool('voltage0','quadrature_tracking_en',obj.EnableQuadratureTracking,false);
302311
obj.setAttributeBool('voltage0','rf_dc_offset_tracking_en',obj.EnableRFDCTracking,false);
303312
obj.setAttributeBool('voltage0','bb_dc_offset_tracking_en',obj.EnableBasebandDCTracking,false);
304313
id = sprintf('altvoltage%d',strcmp(obj.Type,'Tx'));
305314
obj.setAttributeLongLong(id,'frequency',obj.CenterFrequency ,true,4);
306-
if libisloaded('libad9361')
307-
calllib('libad9361','ad9361_set_bb_rate',obj.iioDevPHY,int32(obj.SamplingRate));
315+
% Sample rates and RF bandwidth
316+
if ~obj.EnableCustomFilter
317+
if libisloaded('libad9361')
318+
calllib('libad9361','ad9361_set_bb_rate',obj.iioDevPHY,int32(obj.SamplingRate));
319+
else
320+
obj.setAttributeLongLong('voltage0','sampling_frequency',obj.SamplingRate,true,4);
321+
obj.setAttributeLongLong('voltage0','rf_bandwidth',obj.RFBandwidth ,strcmp(obj.Type,'Tx'));
322+
end
308323
else
309-
obj.setAttributeLongLong('voltage0','sampling_frequency',obj.SamplingRate,true,4);
310-
obj.setAttributeLongLong('voltage0','rf_bandwidth',obj.RFBandwidth ,strcmp(obj.Type,'Tx'));
311-
end
312-
if strcmp(obj.GainControlModeChannel0,'manual')
313-
obj.setAttributeLongLong('voltage0','hardwaregain',obj.GainChannel0,false);
314-
end
315-
if strcmp(obj.GainControlModeChannel1,'manual') && (obj.channelCount>2)
316-
obj.setAttributeLongLong('voltage1','hardwaregain',obj.GainChannel1,false);
324+
writeFilterFile(obj);
317325
end
326+
318327
end
319328

320329
end

+adi/+AD9361/Tx.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109

110110
end
111111
obj.RFBandwidth = value;
112-
if obj.ConnectedToDevice
112+
if obj.ConnectedToDevice && ~obj.EnableCustomFilter
113113
id = 'voltage0';
114114
obj.setAttributeLongLong(id,'rf_bandwidth',value,strcmp(obj.Type,'Tx'),30);
115115
end
@@ -127,7 +127,7 @@
127127

128128
end
129129
obj.SamplingRate = value;
130-
if obj.ConnectedToDevice
130+
if obj.ConnectedToDevice && ~obj.EnableCustomFilter
131131
if libisloaded('libad9361')
132132
calllib('libad9361','ad9361_set_bb_rate',obj.iioDevPHY,int32(value));
133133
else

+adi/+common/Attribute.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,14 @@ function setAttributeRAW(obj,id,attr,value,isOutput)
5050
end
5151
end
5252

53+
function setDeviceAttributeRAW(obj,attr,value)
54+
phydev = getDev(obj, obj.phyDevName);
55+
bytes = iio_device_attr_write(obj,phydev,attr,value);
56+
if bytes <= 0
57+
status = -1;
58+
cstatus(obj,status,['Attribute write failed for : ' attr ' with value ' value]);
59+
end
60+
end
61+
5362
end
5463
end

+adi/+common/RxTx.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
% Hide unused parameters when in specific modes
2626
function flag = isInactivePropertyImpl(obj, prop)
2727
flag = strcmpi(prop,'enIO');
28+
% TX/RX
29+
if isprop(obj,'EnableCustomFilter')
30+
flag = flag || strcmpi(prop,'CustomFilterFileName') && ~obj.EnableCustomFilter;
31+
if obj.EnableCustomFilter
32+
flag = flag || strcmpi(prop,'RFBandwidth');
33+
flag = flag || strcmpi(prop,'SamplingRate');
34+
end
35+
end
2836
% TX
2937
if isprop(obj,'DataSource')
3038
flag = flag || strcmpi(prop,'DDSFrequencies') &&...

test/AD9361Tests.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ function testAD9361Rx(testCase)
2525
testCase.verifyGreaterThan(sum(abs(double(out))),0);
2626
end
2727

28+
function testAD9361RxCustomFilter(testCase)
29+
% Test Rx DMA data output
30+
rx = adi.AD9361.Rx('uri',testCase.uri);
31+
rx.channelCount = 2;
32+
rx.EnableCustomFilter = true;
33+
rx.CustomFilterFileName = 'customAD9361filter.ftr';
34+
[out, valid] = rx();
35+
rx.release();
36+
testCase.verifyTrue(valid);
37+
testCase.verifyGreaterThan(sum(abs(double(out))),0);
38+
end
39+
2840
function testAD9361RxWithTxDDS(testCase)
2941
% Test DDS output
3042
tx = adi.AD9361.Tx('uri',testCase.uri);

test/customAD9361filter.ftr

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Generated with AD9361 Filter Design Wizard 16.1.3-g22a2ace
2+
# MATLAB 9.5.0.944444 (R2018b), 09-Jan-2019 20:50:49
3+
# Inputs:
4+
# Data Sample Frequency = 3000000 Hz
5+
TX 3 GAIN 0 INT 4
6+
RX 3 GAIN -12 DEC 4
7+
RTX 768000000 96000000 48000000 24000000 12000000 3000000
8+
RRX 768000000 96000000 48000000 24000000 12000000 3000000
9+
BWTX 2521541
10+
BWRX 2521551
11+
87,197
12+
-74,-92
13+
102,342
14+
-128,-41
15+
-63,253
16+
-302,-96
17+
-350,-12
18+
-568,-345
19+
-620,-369
20+
-718,-611
21+
-637,-571
22+
-533,-607
23+
-284,-397
24+
-41,-234
25+
237,63
26+
407,235
27+
490,392
28+
402,347
29+
211,226
30+
-78,-48
31+
-346,-301
32+
-544,-537
33+
-573,-596
34+
-437,-510
35+
-136,-224
36+
227,135
37+
565,512
38+
748,738
39+
718,768
40+
446,528
41+
7,104
42+
-489,-421
43+
-876,-854
44+
-1028,-1073
45+
-858,-952
46+
-396,-516
47+
255,154
48+
894,842
49+
1322,1345
50+
1365,1455
51+
970,1106
52+
204,337
53+
-723,-637
54+
-1537,-1533
55+
-1949,-2034
56+
-1776,-1930
57+
-987,-1159
58+
245,111
59+
1587,1544
60+
2611,2682
61+
2932,3107
62+
2317,2545
63+
798,1006
64+
-1310,-1200
65+
-3438,-3481
66+
-4892,-5104
67+
-5016,-5358
68+
-3375,-3766
69+
114,-214
70+
5115,4956
71+
10912,11001
72+
16547,16903
73+
21012,21595
74+
23479,24191
75+
23479,24191
76+
21012,21595
77+
16547,16903
78+
10912,11001
79+
5115,4956
80+
114,-214
81+
-3375,-3766
82+
-5016,-5358
83+
-4892,-5104
84+
-3438,-3481
85+
-1310,-1200
86+
798,1006
87+
2317,2545
88+
2932,3107
89+
2611,2682
90+
1587,1544
91+
245,111
92+
-987,-1159
93+
-1776,-1930
94+
-1949,-2034
95+
-1537,-1533
96+
-723,-637
97+
204,337
98+
970,1106
99+
1365,1455
100+
1322,1345
101+
894,842
102+
255,154
103+
-396,-516
104+
-858,-952
105+
-1028,-1073
106+
-876,-854
107+
-489,-421
108+
7,104
109+
446,528
110+
718,768
111+
748,738
112+
565,512
113+
227,135
114+
-136,-224
115+
-437,-510
116+
-573,-596
117+
-544,-537
118+
-346,-301
119+
-78,-48
120+
211,226
121+
402,347
122+
490,392
123+
407,235
124+
237,63
125+
-41,-234
126+
-284,-397
127+
-533,-607
128+
-637,-571
129+
-718,-611
130+
-620,-369
131+
-568,-345
132+
-350,-12
133+
-302,-96
134+
-63,253
135+
-128,-41
136+
102,342
137+
-74,-92
138+
87,197

0 commit comments

Comments
 (0)