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

Commit 2028c94

Browse files
author
dpu1778
committed
Filter Wizard: Get rid of filter tap iterations for default design functions
In order to make the initialization shorter for MathWorks support package.
1 parent 821a6a0 commit 2028c94

File tree

4 files changed

+142
-294
lines changed

4 files changed

+142
-294
lines changed

AD9361_Filter_Wizard/internal_designrxfilters9361_default.m

Lines changed: 36 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -252,85 +252,47 @@
252252

253253
% Determine the number of taps for RFIR
254254
N = min(16*floor(Fadc/(2*Fout)),128);
255-
tap_store = zeros(N/16,N);
256-
dBripple_actual_vecotr = zeros(N/16,1);
257-
dBstop_actual_vector = zeros(N/16,1);
258-
i = 1;
259255

260-
while (1)
256+
if int_FIR
257+
d = fdesign.arbmag('N,B,F,A',N-1,B,F1,A1,F2,A2);
258+
else
259+
d = fdesign.arbmag('B,F,A,R');
260+
d.NBands = 2;
261+
d.B1Frequencies = F1;
262+
d.B1Amplitudes = A1;
263+
d.B1Ripple = db2mag(-dBstop);
264+
d.B2Frequencies = F2;
265+
d.B2Amplitudes = A2;
266+
d.B2Ripple = db2mag(-dBstop);
267+
end
268+
Hd = design(d,'equiripple','B1Weights',W1,'B2Weights',W2,'SystemObject',false);
269+
ccoef = Hd.Numerator;
270+
M = length(ccoef);
271+
272+
if phEQ ~= -1
273+
sg = 0.5-grid(end:-1:1);
274+
sr = imag(resp(end:-1:1));
275+
sw = weight(end:-1:1);
276+
F3 = sg(1:G/2-Gstop+1)*2;
277+
F4 = sg(G/2-Gstop+2:end)*2;
278+
A3 = sr(1:G/2-Gstop+1);
279+
A4 = sr(G/2-Gstop+2:end);
280+
W3 = sw(1:G/2-Gstop+1);
281+
W4 = sw(G/2-Gstop+2:end);
261282
if int_FIR
262-
d = fdesign.arbmag('N,B,F,A',N-1,B,F1,A1,F2,A2);
263-
else
264-
d = fdesign.arbmag('B,F,A,R');
265-
d.NBands = 2;
266-
d.B1Frequencies = F1;
267-
d.B1Amplitudes = A1;
268-
d.B1Ripple = db2mag(-dBstop);
269-
d.B2Frequencies = F2;
270-
d.B2Amplitudes = A2;
271-
d.B2Ripple = db2mag(-dBstop);
272-
end
273-
Hd = design(d,'equiripple','B1Weights',W1,'B2Weights',W2,'SystemObject',false);
274-
ccoef = Hd.Numerator;
275-
M = length(ccoef);
276-
277-
if phEQ ~= -1
278-
sg = 0.5-grid(end:-1:1);
279-
sr = imag(resp(end:-1:1));
280-
sw = weight(end:-1:1);
281-
F3 = sg(1:G/2-Gstop+1)*2;
282-
F4 = sg(G/2-Gstop+2:end)*2;
283-
A3 = sr(1:G/2-Gstop+1);
284-
A4 = sr(G/2-Gstop+2:end);
285-
W3 = sw(1:G/2-Gstop+1);
286-
W4 = sw(G/2-Gstop+2:end);
287-
if int_FIR
288-
d2 = fdesign.arbmag('N,B,F,A',N-1,B,F3,A3,F4,A4);
289-
else
290-
d2 = fdesign.arbmag('N,B,F,A',M-1,B,F3,A3,F4,A4);
291-
end
292-
Hd2 = design(d2,'equiripple','B1Weights',W3,'B2Weights',W4,'SystemObject',false);
293-
scoef = Hd2.Numerator;
294-
for k = 1:length(scoef)
295-
scoef(k) = -scoef(k)*(-1)^(k-1);
296-
end
283+
d2 = fdesign.arbmag('N,B,F,A',N-1,B,F3,A3,F4,A4);
297284
else
298-
scoef = 0;
285+
d2 = fdesign.arbmag('N,B,F,A',M-1,B,F3,A3,F4,A4);
299286
end
300-
tap_store(i,1:M)=ccoef+scoef;
301-
302-
Hmd = mfilt.firdecim(FIR_decim,tap_store(i,1:M));
303-
if license('test','fixed_point_toolbox') && license('checkout','fixed_point_toolbox')
304-
set(Hmd,'arithmetic','fixed');
305-
Hmd.InputWordLength = 16;
306-
Hmd.InputFracLength = 14;
307-
Hmd.FilterInternals = 'SpecifyPrecision';
308-
Hmd.OutputWordLength = 12;
309-
Hmd.OutputFracLength = 10;
310-
Hmd.CoeffWordLength = 16;
311-
end
312-
rxFilters=cascade(Filter1,Hmd);
313-
314-
% quantitative values about actual passband and stopband
315-
rg_pass = abs(analogresp('Rx',omega(1:Gpass+1),Fadc,b1,a1,b2,a2).*freqz(rxFilters,omega(1:Gpass+1),Fadc));
316-
rg_stop = abs(analogresp('Rx',omega(Gpass+2:end),Fadc,b1,a1,b2,a2).*freqz(rxFilters,omega(Gpass+2:end),Fadc));
317-
dBripple_actual_vecotr(i) = mag2db(max(rg_pass))-mag2db(min(rg_pass));
318-
dBstop_actual_vector(i) = -mag2db(max(rg_stop));
319-
320-
if int_FIR == 0
321-
h = tap_store(1,1:M);
322-
break
323-
elseif dBripple_actual_vecotr(1) > dBripple || dBstop_actual_vector(1) < dBstop
324-
h = tap_store(1,1:N);
325-
break
326-
elseif dBripple_actual_vecotr(i) > dBripple || dBstop_actual_vector(i) < dBstop
327-
h = tap_store(i-1,1:N+16);
328-
break
329-
else
330-
N = N-16;
331-
i = i+1;
287+
Hd2 = design(d2,'equiripple','B1Weights',W3,'B2Weights',W4,'SystemObject',false);
288+
scoef = Hd2.Numerator;
289+
for k = 1:length(scoef)
290+
scoef(k) = -scoef(k)*(-1)^(k-1);
332291
end
292+
else
293+
scoef = 0;
333294
end
295+
h=ccoef+scoef;
334296

335297
Hmd = mfilt.firdecim(FIR_decim,h);
336298
if license('test','fixed_point_toolbox') && license('checkout','fixed_point_toolbox')
@@ -374,4 +336,4 @@
374336
tohwrx.CoefficientSize = length(h);
375337
tohwrx.Decimation = FIR_decim;
376338
tohwrx.Gain = gain;
377-
tohwrx.RFBandwidth = round(Fpass*2);
339+
tohwrx.RFBandwidth = round(Fpass*2);

AD9361_Filter_Wizard/internal_designrxfilters9361_default2.m

Lines changed: 35 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -266,85 +266,47 @@
266266

267267
% Determine the number of taps for RFIR
268268
N = min(16*floor(Fadc/(2*Fout)),128);
269-
tap_store = zeros(N/16,N);
270-
dBripple_actual_vecotr = zeros(N/16,1);
271-
dBstop_actual_vector = zeros(N/16,1);
272-
i = 1;
273269

274-
while (1)
270+
if int_FIR
271+
d = fdesign.arbmag('N,B,F,A',N-1,B,F1,A1,F2,A2);
272+
else
273+
d = fdesign.arbmag('B,F,A,R');
274+
d.NBands = 2;
275+
d.B1Frequencies = F1;
276+
d.B1Amplitudes = A1;
277+
d.B1Ripple = db2mag(-dBstop);
278+
d.B2Frequencies = F2;
279+
d.B2Amplitudes = A2;
280+
d.B2Ripple = db2mag(-dBstop);
281+
end
282+
Hd = design(d,'equiripple','B1Weights',W1,'B2Weights',W2,'SystemObject',false);
283+
ccoef = Hd.Numerator;
284+
M = length(ccoef);
285+
286+
if phEQ ~= -1
287+
sg = 0.5-grid(end:-1:1);
288+
sr = imag(resp(end:-1:1));
289+
sw = weight(end:-1:1);
290+
F3 = sg(1:G/2-Gstop+1)*2;
291+
F4 = sg(G/2-Gstop+2:end)*2;
292+
A3 = sr(1:G/2-Gstop+1);
293+
A4 = sr(G/2-Gstop+2:end);
294+
W3 = sw(1:G/2-Gstop+1);
295+
W4 = sw(G/2-Gstop+2:end);
275296
if int_FIR
276-
d = fdesign.arbmag('N,B,F,A',N-1,B,F1,A1,F2,A2);
277-
else
278-
d = fdesign.arbmag('B,F,A,R');
279-
d.NBands = 2;
280-
d.B1Frequencies = F1;
281-
d.B1Amplitudes = A1;
282-
d.B1Ripple = db2mag(-dBstop);
283-
d.B2Frequencies = F2;
284-
d.B2Amplitudes = A2;
285-
d.B2Ripple = db2mag(-dBstop);
286-
end
287-
Hd = design(d,'equiripple','B1Weights',W1,'B2Weights',W2,'SystemObject',false);
288-
ccoef = Hd.Numerator;
289-
M = length(ccoef);
290-
291-
if phEQ ~= -1
292-
sg = 0.5-grid(end:-1:1);
293-
sr = imag(resp(end:-1:1));
294-
sw = weight(end:-1:1);
295-
F3 = sg(1:G/2-Gstop+1)*2;
296-
F4 = sg(G/2-Gstop+2:end)*2;
297-
A3 = sr(1:G/2-Gstop+1);
298-
A4 = sr(G/2-Gstop+2:end);
299-
W3 = sw(1:G/2-Gstop+1);
300-
W4 = sw(G/2-Gstop+2:end);
301-
if int_FIR
302-
d2 = fdesign.arbmag('N,B,F,A',N-1,B,F3,A3,F4,A4);
303-
else
304-
d2 = fdesign.arbmag('N,B,F,A',M-1,B,F3,A3,F4,A4);
305-
end
306-
Hd2 = design(d2,'equiripple','B1Weights',W3,'B2Weights',W4,'SystemObject',false);
307-
scoef = Hd2.Numerator;
308-
for k = 1:length(scoef)
309-
scoef(k) = -scoef(k)*(-1)^(k-1);
310-
end
297+
d2 = fdesign.arbmag('N,B,F,A',N-1,B,F3,A3,F4,A4);
311298
else
312-
scoef = 0;
299+
d2 = fdesign.arbmag('N,B,F,A',M-1,B,F3,A3,F4,A4);
313300
end
314-
tap_store(i,1:M)=ccoef+scoef;
315-
316-
Hmd = mfilt.firdecim(FIR_decim,tap_store(i,1:M));
317-
if license('test','fixed_point_toolbox') && license('checkout','fixed_point_toolbox')
318-
set(Hmd,'arithmetic','fixed');
319-
Hmd.InputWordLength = 16;
320-
Hmd.InputFracLength = 14;
321-
Hmd.FilterInternals = 'SpecifyPrecision';
322-
Hmd.OutputWordLength = 12;
323-
Hmd.OutputFracLength = 10;
324-
Hmd.CoeffWordLength = 16;
325-
end
326-
rxFilters=cascade(Filter1,Hmd);
327-
328-
% quantitative values about actual passband and stopband
329-
rg_pass = abs(analogresp('Rx',omega(1:Gpass+1),Fadc,b1,a1,b2,a2).*freqz(rxFilters,omega(1:Gpass+1),Fadc));
330-
rg_stop = abs(analogresp('Rx',omega(Gpass+2:end),Fadc,b1,a1,b2,a2).*freqz(rxFilters,omega(Gpass+2:end),Fadc));
331-
dBripple_actual_vecotr(i) = mag2db(max(rg_pass))-mag2db(min(rg_pass));
332-
dBstop_actual_vector(i) = -mag2db(max(rg_stop));
333-
334-
if int_FIR == 0
335-
h = tap_store(1,1:M);
336-
break
337-
elseif dBripple_actual_vecotr(1) > dBripple || dBstop_actual_vector(1) < dBstop
338-
h = tap_store(1,1:N);
339-
break
340-
elseif dBripple_actual_vecotr(i) > dBripple || dBstop_actual_vector(i) < dBstop
341-
h = tap_store(i-1,1:N+16);
342-
break
343-
else
344-
N = N-16;
345-
i = i+1;
301+
Hd2 = design(d2,'equiripple','B1Weights',W3,'B2Weights',W4,'SystemObject',false);
302+
scoef = Hd2.Numerator;
303+
for k = 1:length(scoef)
304+
scoef(k) = -scoef(k)*(-1)^(k-1);
346305
end
306+
else
307+
scoef = 0;
347308
end
309+
h=ccoef+scoef;
348310

349311
Hmd = mfilt.firdecim(FIR_decim,h);
350312
if license('test','fixed_point_toolbox') && license('checkout','fixed_point_toolbox')

AD9361_Filter_Wizard/internal_designtxfilters9361_default.m

Lines changed: 36 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -263,85 +263,47 @@
263263
end
264264

265265
N = min(16*floor(Fdac*DAC_mult/(2*Fin)),Nmax);
266-
tap_store = zeros(N/16,N);
267-
dBripple_actual_vecotr = zeros(N/16,1);
268-
dBstop_actual_vector = zeros(N/16,1);
269-
i = 1;
270266

271-
while (1)
267+
if int_FIR
268+
d = fdesign.arbmag('N,B,F,A',N-1,B,F1,A1,F2,A2);
269+
else
270+
d = fdesign.arbmag('B,F,A,R');
271+
d.NBands = 2;
272+
d.B1Frequencies = F1;
273+
d.B1Amplitudes = A1;
274+
d.B1Ripple = db2mag(-dBstop);
275+
d.B2Frequencies = F2;
276+
d.B2Amplitudes = A2;
277+
d.B2Ripple = db2mag(-dBstop);
278+
end
279+
Hd = design(d,'equiripple','B1Weights',W1,'B2Weights',W2,'SystemObject',false);
280+
ccoef = Hd.Numerator;
281+
M = length(ccoef);
282+
283+
if phEQ ~= -1
284+
sg = 0.5-grid(end:-1:1);
285+
sr = imag(resp(end:-1:1));
286+
sw = weight(end:-1:1);
287+
F3 = sg(1:G/2-Gstop+1)*2;
288+
F4 = sg(G/2-Gstop+2:end)*2;
289+
A3 = sr(1:G/2-Gstop+1);
290+
A4 = sr(G/2-Gstop+2:end);
291+
W3 = sw(1:G/2-Gstop+1);
292+
W4 = sw(G/2-Gstop+2:end);
272293
if int_FIR
273-
d = fdesign.arbmag('N,B,F,A',N-1,B,F1,A1,F2,A2);
274-
else
275-
d = fdesign.arbmag('B,F,A,R');
276-
d.NBands = 2;
277-
d.B1Frequencies = F1;
278-
d.B1Amplitudes = A1;
279-
d.B1Ripple = db2mag(-dBstop);
280-
d.B2Frequencies = F2;
281-
d.B2Amplitudes = A2;
282-
d.B2Ripple = db2mag(-dBstop);
283-
end
284-
Hd = design(d,'equiripple','B1Weights',W1,'B2Weights',W2,'SystemObject',false);
285-
ccoef = Hd.Numerator;
286-
M = length(ccoef);
287-
288-
if phEQ ~= -1
289-
sg = 0.5-grid(end:-1:1);
290-
sr = imag(resp(end:-1:1));
291-
sw = weight(end:-1:1);
292-
F3 = sg(1:G/2-Gstop+1)*2;
293-
F4 = sg(G/2-Gstop+2:end)*2;
294-
A3 = sr(1:G/2-Gstop+1);
295-
A4 = sr(G/2-Gstop+2:end);
296-
W3 = sw(1:G/2-Gstop+1);
297-
W4 = sw(G/2-Gstop+2:end);
298-
if int_FIR
299-
d2 = fdesign.arbmag('N,B,F,A',N-1,B,F3,A3,F4,A4);
300-
else
301-
d2 = fdesign.arbmag('N,B,F,A',M-1,B,F3,A3,F4,A4);
302-
end
303-
Hd2 = design(d2,'equiripple','B1Weights',W3,'B2Weights',W4,'SystemObject',false);
304-
scoef = Hd2.Numerator;
305-
for k = 1:length(scoef)
306-
scoef(k) = -scoef(k)*(-1)^(k-1);
307-
end
294+
d2 = fdesign.arbmag('N,B,F,A',N-1,B,F3,A3,F4,A4);
308295
else
309-
scoef = 0;
296+
d2 = fdesign.arbmag('N,B,F,A',M-1,B,F3,A3,F4,A4);
310297
end
311-
tap_store(i,1:M)=ccoef+scoef;
312-
313-
Hmd = mfilt.firinterp(FIR_interp,tap_store(i,1:M));
314-
if license('test','fixed_point_toolbox') && license('checkout','fixed_point_toolbox')
315-
set(Hmd,'arithmetic','fixed');
316-
Hmd.InputWordLength = 16;
317-
Hmd.InputFracLength = 14;
318-
Hmd.FilterInternals = 'SpecifyPrecision';
319-
Hmd.OutputWordLength = 12;
320-
Hmd.OutputFracLength = 10;
321-
Hmd.CoeffWordLength = 16;
322-
end
323-
txFilters=cascade(Hmd,Filter1);
324-
325-
% quantitative values about actual passband and stopband
326-
rg_pass = abs(freqz(txFilters,omega(1:Gpass+1),Fdac).*analogresp('Tx',omega(1:Gpass+1),Fdac,b1,a1,b2,a2));
327-
rg_stop = abs(freqz(txFilters,omega(Gpass+2:end),Fdac).*analogresp('Tx',omega(Gpass+2:end),Fdac,b1,a1,b2,a2));
328-
dBripple_actual_vecotr(i) = mag2db(max(rg_pass))-mag2db(min(rg_pass));
329-
dBstop_actual_vector(i) = -mag2db(max(rg_stop));
330-
331-
if int_FIR == 0
332-
h = tap_store(1,1:M);
333-
break
334-
elseif dBripple_actual_vecotr(1) > dBripple || dBstop_actual_vector(1) < dBstop
335-
h = tap_store(1,1:N);
336-
break
337-
elseif dBripple_actual_vecotr(i) > dBripple || dBstop_actual_vector(i) < dBstop
338-
h = tap_store(i-1,1:N+16);
339-
break
340-
else
341-
N = N-16;
342-
i = i+1;
298+
Hd2 = design(d2,'equiripple','B1Weights',W3,'B2Weights',W4,'SystemObject',false);
299+
scoef = Hd2.Numerator;
300+
for k = 1:length(scoef)
301+
scoef(k) = -scoef(k)*(-1)^(k-1);
343302
end
303+
else
304+
scoef = 0;
344305
end
306+
h=ccoef+scoef;
345307

346308
if int_FIR == 1 && FIR_interp == 2
347309
R = rem(length(h),32);
@@ -406,4 +368,4 @@
406368
tohwtx.CoefficientSize = length(h);
407369
tohwtx.Interp = FIR_interp;
408370
tohwtx.Gain = gain;
409-
tohwtx.RFBandwidth = round(Fpass*2);
371+
tohwtx.RFBandwidth = round(Fpass*2);

0 commit comments

Comments
 (0)