main content

implement digital downconverter for fpga -凯发k8网页登录

this example shows how to design a digital downconverter (ddc) for radio communication applications such as lte, and generate hdl code.

introduction

ddcs are widely used in digital communication receivers to convert radio frequency (rf) or intermediate frequency (if) signals to baseband. the ddc operation shifts the signal to a lower frequency and reduces its sampling rate to facilitate subsequent processing stages. the ddc in this example performs complex frequency translation followed by sample rate conversion using a four-stage filter chain. the example starts by designing the ddc with dsp system toolbox™ functions in floating point. then, each stage is converted to fixed point, and used in a simulink® model that generates synthesizable hdl code. the example uses these two test signals to demonstrate and verify the ddc operation:

  • a sinusoid that is modulated onto a 32 mhz if carrier.

  • an lte downlink signal with a bandwidth of 1.4 mhz modulated onto a 32 mhz if carrier.

the example compares the signal quality at the output of the floating-point ddc with the signal quality at the output of the fixed-point ddc.

finally, the example presents an implementation of the filter chain for fpgas, and synthesis results.

this example uses ddctestutils, a helper class that contains functions for generating stimulus and analyzing the ddc output. for more information, see the ddctestutils.m file.

ddc structure

the ddc consists of a numerically controlled oscillator (nco), mixer, and decimating filter chain. the filter chain consists of a cascade integrator-comb (cic) decimator, cic gain correction, a cic compensation decimator (fir), a halfband fir decimator, and a final fir decimator.

the overall response of the filter chain is equivalent to that of a single decimation filter with the same specification. however, splitting the filter into multiple decimation stages results in a more efficient design that uses fewer hardware resources.

the cic decimator provides a large initial decimation factor, which enables subsequent filters to work at lower rates. the cic compensation decimator improves the spectral response by compensating for the cic droop while decimating by two. the halfband is an intermediate decimator, and the final decimator implements the precise fpass and fstop characteristics of the ddc. the lower sampling rates near the end of the chain mean the later filters can optimize resource use by sharing multipliers.

this figure shows a block diagram of the ddc.

the sample rate of the input to the ddc is 122.88 msps, and the output sample rate is 1.92 msps. these rates give an overall decimation factor of 64. lte receivers use 1.92 msps as the typical sampling rate for cell search and master information block (mib) recovery. the ddc filters are designed to suit this application. the ddc is optimized to run at a clock rate of 122.88 mhz.

ddc design

this section explains how to design the ddc using floating-point operations and filter-design functions in matlab®.

ddc parameters

this example designs the ddc filter characteristics to meet these specifications for the given input sampling rate and carrier frequency.

fsin = 122.88e6;    % sampling rate of ddc input
fsout = 1.92e6;     % sampling rate of ddc output
fc = 32e6;          % carrier frequency
fpass = 540e3;      % passband frequency, equivalent to 36x15khz lte subcarriers
fstop = 700e3;      % stopband frequency
ap = 0.1;           % passband ripple
ast = 60;           % stopband attenuation

cic decimator

the first filter stage is a cic decimator because of its ability to efficiently implement a large decimation factor. the response of a cic filter is similar to a cascade of moving average filters, but a cic filter uses no multiplication or division. as a result, the cic filter has a large dc gain.

cicparams.decimationfactor = 8;
cicparams.differentialdelay = 1;
cicparams.numsections = 3;
cicparams.fsout = fsin/cicparams.decimationfactor;
cicfilt = dsp.cicdecimator(cicparams.decimationfactor, ...
    cicparams.differentialdelay,cicparams.numsections)       %#ok<*nopts>
cicgain = gain(cicfilt)
cicfilt = 
  dsp.cicdecimator with properties:
      decimationfactor: 8
     differentialdelay: 1
           numsections: 3
    fixedpointdatatype: 'full precision'
cicgain =
   512

because the cic gain is a power of two, a hardware implementation can easily correct for the gain factor by using a shift operation. for analysis purposes, the example represents the gain correction in matlab with a one-tap dsp.firfilter system object™.

cicgaincorr = dsp.firfilter('numerator',1/cicgain)
cicgaincorr = 
  dsp.firfilter with properties:
            structure: 'direct form'
      numeratorsource: 'property'
            numerator: 0.0020
    initialconditions: 0
  use get to show all properties

display the magnitude response of the cic filter with and without gain correction by using fvtool. for analysis, combine the cic filter and the gain correction filter into a dsp.filtercascade system object. cic filters use fixed-point arithmetic internally, so fvtool plots both the quantized and unquantized responses.

ddcplots.cicdecim = fvtool(...
    cicfilt, ...
    dsp.filtercascade(cicfilt,cicgaincorr), ...
    'fs',[fsin,fsin]);
legend(ddcplots.cicdecim, ...
    'cic no correction', ...
    'cic with gain correction');

cic droop compensation filter

because the magnitude response of the cic filter has a significant droop within the passband region, the example uses a fir-based droop compensation filter to flatten the passband response. the droop compensator has the same properties as the cic decimator. this filter implements decimation by a factor of two, so you must also specify bandlimiting characteristics for the filter. use the design function to return a filter system object with the specified characteristics.

compparams.r = 2;                                % cic compensation decimation factor
compparams.fpass = fstop;                        % cic compensation passband frequency
compparams.fsout = cicparams.fsout/compparams.r; % new sampling rate
compparams.fstop = compparams.fsout - fstop;     % cic compensation stopband frequency
compparams.ap = ap;                              % same passband ripple as overall filter
compparams.ast = ast;                            % same stopband attenuation as overall filter
compspec = fdesign.decimator(compparams.r,'ciccomp', ...
    cicparams.differentialdelay, ...
    cicparams.numsections, ...
    cicparams.decimationfactor, ...
    'fp,fst,ap,ast', ...
    compparams.fpass,compparams.fstop,compparams.ap,compparams.ast, ...
    cicparams.fsout);
compfilt = design(compspec,'systemobject',true)
compfilt = 
  dsp.firdecimator with properties:
   main
    decimationfactor: 2
     numeratorsource: 'property'
           numerator: [-0.0398 -0.0126 0.2901 0.5258 0.2901 -0.0126 -0.0398]
           structure: 'direct form'
  use get to show all properties

plot the combined response of the cic filter (with gain correction) and droop compensation.

ddcplots.ciccomp = fvtool(...
    dsp.filtercascade(cicfilt,cicgaincorr,compfilt), ...
    'fs',fsin,'legend','off');

halfband decimator

the halfband filter provides efficient decimation by two. halfband filters are efficient because approximately half of their coefficients are equal to zero, and those multipliers are excluded from the hardware implementation.

hbparams.fsout = compparams.fsout/2;
hbparams.transitionwidth = hbparams.fsout - 2*fstop;
hbparams.stopbandattenuation = ast;
hbspec = fdesign.decimator(2,'halfband',...
    'tw,ast', ...
    hbparams.transitionwidth, ...
    hbparams.stopbandattenuation, ...
    compparams.fsout);
hbfilt = design(hbspec,'systemobject',true)
hbfilt = 
  dsp.firdecimator with properties:
   main
    decimationfactor: 2
     numeratorsource: 'property'
           numerator: [0.0089 0 -0.0565 0 0.2977 0.5000 0.2977 0 -0.0565 ... ]
           structure: 'direct form'
  use get to show all properties

plot the response of the ddc up to the halfband filter output.

ddcplots.halfbandfir = fvtool(...
    dsp.filtercascade(cicfilt,cicgaincorr,compfilt,hbfilt), ...
    'fs',fsin,'legend','off');

final fir decimator

the final fir implements the detailed passband and stopband characteristics of the ddc. this filter has more coefficients than the earlier fir filters, but because it operates at a lower sampling rate it can use resource sharing for an efficient hardware implementation.

add 3 db of headroom to the stopband attenuation so that the ddc still meets the specification after fixed-point quantization. this value was found empirically by using fvtool.

finalspec = fdesign.decimator(2,'lowpass', ...
    'fp,fst,ap,ast',fpass,fstop,ap,ast 3,hbparams.fsout);
finalfilt = design(finalspec,'equiripple','systemobject',true)
finalfilt = 
  dsp.firdecimator with properties:
   main
    decimationfactor: 2
     numeratorsource: 'property'
           numerator: [9.3365e-04 0.0013 9.3466e-04 -5.3189e-04 -0.0022 ... ]
           structure: 'direct form'
  use get to show all properties

visualize the overall magnitude response of the ddc.

ddcfilterchain           = dsp.filtercascade(cicfilt,cicgaincorr,compfilt,hbfilt,finalfilt);
ddcplots.overallresponse = fvtool(ddcfilterchain,'fs',fsin,'legend','off');

fixed-point conversion

the frequency response of the floating-point ddc filter chain now meets the specification. next, quantize each filter stage to use fixed-point types and analyze them to confirm that the filter chain still meets the specification.

filter quantization

this example uses 16-bit coefficients, which are sufficient to meet the specification. using fewer than 18 bits for the coefficients minimizes the number of dsp blocks that are required for an fpga implementation. the input to the ddc filter chain is 16-bit data with 15 fractional bits. the filter outputs are 18-bit values, which provide extra headroom and precision in the intermediate signals.

for the cic decimator, choosing the 'minimum section word lengths' fixed-point data type option automatically optimizes the internal wordlengths based on the output wordlength and other cic parameters.

cicfilt.fixedpointdatatype = 'minimum section word lengths';
cicfilt.outputwordlength = 18;

configure the fixed-point properties of the gain correction and fir-based system objects. the object uses the default roundingmethod and overflowaction property values ('floor' and 'wrap' respectively).

% cic gain correction
cicgaincorr.fullprecisionoverride = false;
cicgaincorr.coefficientsdatatype = 'custom';
cicgaincorr.customcoefficientsdatatype = numerictype(fi(cicgaincorr.numerator,1,16));
cicgaincorr.outputdatatype = 'custom';
cicgaincorr.customoutputdatatype = numerictype(1,18,16);
% cic droop compensation
compfilt.fullprecisionoverride = false;
compfilt.coefficientsdatatype = 'custom';
compfilt.customcoefficientsdatatype = numerictype([],16,15);
compfilt.productdatatype = 'full precision';
compfilt.accumulatordatatype = 'full precision';
compfilt.outputdatatype = 'custom';
compfilt.customoutputdatatype = numerictype([],18,16);
% halfband
hbfilt.fullprecisionoverride = false;
hbfilt.coefficientsdatatype = 'custom';
hbfilt.customcoefficientsdatatype = numerictype([],16,15);
hbfilt.productdatatype = 'full precision';
hbfilt.accumulatordatatype = 'full precision';
hbfilt.outputdatatype = 'custom';
hbfilt.customoutputdatatype = numerictype([],18,16);
% fir
finalfilt.fullprecisionoverride = false;
finalfilt.coefficientsdatatype = 'custom';
finalfilt.customcoefficientsdatatype = numerictype([],16,15);
finalfilt.productdatatype = 'full precision';
finalfilt.accumulatordatatype = 'full precision';
finalfilt.outputdatatype = 'custom';
finalfilt.customoutputdatatype = numerictype([],18,16);

fixed-point analysis

inspect the quantization effects with fvtool. you can analyze the filters individually or in a cascade. fvtool shows the quantized and unquantized (reference) responses overlayed. for example, this figure shows the effect of quantizing the final fir filter stage.

ddcplots.quantizedfir = fvtool(finalfilt, ...
    'fs',hbparams.fsout,'arithmetic','fixed');

redefine the ddcfilterchain cascade object to include the fixed-point properties of the individual filters. then, use fvtool to analyze the entire filter chain and confirm that the quantized ddc still meets the specification.

ddcfilterchain = dsp.filtercascade(cicfilt, ...
    cicgaincorr,compfilt,hbfilt,finalfilt);
ddcplots.quantizedddcresponse = fvtool(ddcfilterchain, ...
    'fs',fsin,'arithmetic','fixed');
legend(ddcplots.quantizedddcresponse, ...
    'ddc filter chain');

hdl-optimized simulink model

the next step in the design flow is to implement the ddc in simulink using blocks that support hdl code generation.

model configuration

the model relies on variables in the matlab workspace to configure the blocks and settings. it uses the same filter chain variables defined earlier in the example. next, define the nco characteristics and the input signal. the example uses these characteristics to configure the nco block.

specify the desired frequency resolution and calculate the number of accumulator bits that are required to achieve the desired resolution. set the desired spurious free dynamic range, and then define the number of quantized accumulator bits. the nco uses the quantized output of the accumulator to address the sine lookup table. also compute the phase increment that the nco uses to generate the specified carrier frequency. the nco applies phase dither to those accumulator bits that are removed during quantization.

nco.fd = 1;
nco.accwl =  nextpow2(fsin/nco.fd) 1;
sfdr  = 84;
nco.quantaccwl = ceil((sfdr-12)/6);
nco.phaseinc = round((-fc*2^nco.accwl)/fsin);
nco.numditherbits = nco.accwl-nco.quantaccwl;

the input to the ddc comes from the ddcin variable. for now, assign a dummy value for ddcin so that the model can compute its data types. during testing, ddcin provides input data to the model.

ddcin = 0; %#ok

you can create a sample-based signal by setting up the framesize to 1, and output each individual sample as it is received. for a higher input sampling frequency or power reducing consideration, this design could also realize frame-based processing, and the framesize should be modified accordingly. in this case, we're showing a case for the framesize of 4.

framesize = 4;

model structure

this figure shows the top level of the ddc simulink model. the model imports the ddcin variable from the matlab workspace by using a signal from workspace block, converts the input signal to 16-bit values, and applies the signal to the ddc. you can generate hdl code from the hdl_ddc subsystem.

modelname = 'ddcforltehdl';
open_system(modelname);
set_param(modelname,'simulationcommand','update');
set_param(modelname,'open','on');

the hdl_ddc subsystem implements the ddc filter. first, the nco block generates a complex phasor at the carrier frequency. this signal goes to a mixer that multiplies the phasor with the input signal. then, the output of the mixer is passed to the filter chain and decimated to 1.92 msps.

set_param([modelname '/hdl_ddc'],'open','on');

nco block parameters

the nco block in the model is configured with the parameters defined in the nco structure. this figure shows both tabs of the nco block parameters dialog.

cic decimation and gain correction

the first filter stage is a cic decimator that is implemented with a cic decimator block. the block parameters are set to the cicparams structure values. to implement the gain correction, the model selects the gain correction parameter. the image shows the block parameters for the cic decimator block.

the model configures the filters by using the properties of the corresponding system objects. the cic compensation, halfband decimation, and final decimation filters operate at effective sample rates that are lower than the clock rate by factors of 8, 16, and 32, respectively. the model implements these sample rates by using the valid input signal to indicate which samples are valid at each rate. the signals in the filter chain all have the same simulink sample time.

the cic compensation, halfband decimation, and final decimation filters are each implemented by an fir decimator. by setting the minimum number of cycles between valid input samples parameter, we can use the invalid cycles between input samples. for example,the spacing between every input of cic compensation decimator is 8, which equals the decimation factor. so the cic compensation decimator has the minimum number of cycles between valid input samples set to ceil(cicparams.decimationfactor/framesize), which equals 2 cycles. the image shows the block parameters for the cic compensation decimation block.

the fir decimator block fully reuses the multipliers in time over the number of clock cycles you specify. for framesize is 4, the cic compensation decimation filter with complex input data would use 4 multipliers. the halfband decimation uses 4 multipliers, and the final decimation uses 12 multipliers. for framesize is 1, since the inputs spacing of cic compensation decimation and halfband decimation are larger than their filter length, those two decimators only require 2 multipliers. and the final decimation needs 4 multipliers at that time.

sinusoid on carrier test and verification

to test the ddc, modulate a 40 khz sinusoid onto the carrier frequency and pass the modulated sine wave through the ddc. then, measure the spurious- free dynamic range (sfdr) of the resulting tone and the sfdr of the nco output. plot the sfdr of the nco and the fixed-point ddc output.

% initialize random seed before executing any simulations.
rng(0);
% generate a 40 khz test tone, modulated onto the carrier.
ddcin = ddctestutils.generatetesttone(40e3,fc);
% demodulate the test signal with the floating-point ddc.
ddcout = ddctestutils.downconvert(ddcin,fsin,fc,ddcfilterchain);
release(ddcfilterchain);
% demodulate the test signal by running the simulink model.
out = sim(modelname);
% measure the sfdr of the nco, floating-point ddc outputs, and fixed-point
% ddc outputs.
results.sfdrnco = sfdr(real(out.ncoout),fsin);
results.sfdrfloatddc = sfdr(real(ddcout),fsout);
results.sfdrfixedddc = sfdr(real(out.ddcfixedout),fsout);
disp('sfdr measurements');
disp(['   floating-point ddc sfdr: ',num2str(results.sfdrfloatddc) ' db']);
disp(['   fixed-point nco sfdr: ',num2str(results.sfdrnco) ' db']);
disp(['   optimized fixed-point ddc sfdr: ',num2str(results.sfdrfixedddc) ' db']);
fprintf(newline);
% plot the sfdr of the nco and fixed-point ddc outputs.
ddcplots.ncooutsdfr = figure;
sfdr(real(out.ncoout),fsin);
ddcplots.optddcoutsfdr = figure;
sfdr(real(out.ddcfixedout),fsout);
sfdr measurements
   floating-point ddc sfdr: 291.4184 db
   fixed-point nco sfdr: 83.0306 db
   optimized fixed-point ddc sfdr: 110.386 db

lte signal test

you can use an lte test signal to perform more rigorous testing of the ddc. generate a standard-compliant lte waveform by using lte toolbox™ functions. then, downconvert the waveform with the ddc model. use lte toolbox functions to measure the error vector magnitude (evm) of the resulting signals.

rng(0);
% execute this test only if you have the lte toolbox product.
if license('test','lte_toolbox')
    % generate a modulated lte test signal by using the lte toolbox functions.
    [ddcin,siginfo] = ddctestutils.generateltetestsignal(fc);
    % downconvert the signal with the floating-point ddc.
    ddcout = ddctestutils.downconvert(ddcin,fsin,fc,ddcfilterchain);
    release(ddcfilterchain);
    % downconvert the signal with the simulink model, then measure and plot the
    % evm of the floating-point and fixed-point results. pad the input with zeros
    % to represent propagation latency and return the complete result.
    ddcin = [ddcin;zeros(2480*framesize,1)];
    out = sim(modelname);
    results.evmfloat = ddctestutils.measureevm(siginfo,ddcout);
    results.evmfixed = ddctestutils.measureevm(siginfo,out.ddcfixedout(1:length(ddcout)));
    disp('lte error vector magnitude (evm) measurements');
    disp(['   floating-point ddc rms evm: '  num2str(results.evmfloat.rms*100,3) '%']);
    disp(['   floating-point ddc peak evm: ' num2str(results.evmfloat.peak*100,3) '%']);
    disp(['   fixed-point ddc rms evm: '     num2str(results.evmfixed.rms*100,3) '%']);
    disp(['   fixed-point ddc peak evm: '    num2str(results.evmfixed.peak*100,3) '%']);
    fprintf(newline);
end
lte error vector magnitude (evm) measurements
   floating-point ddc rms evm: 0.633%
   floating-point ddc peak evm: 2.44%
   fixed-point ddc rms evm: 0.731%
   fixed-point ddc peak evm: 2.69%

hdl code generation and fpga implementation

to generate the hdl code for this example you must have the hdl coder™ product. use the makehdl and makehdltb commands to generate hdl code and an hdl test bench for the hdl_ddc subsystem. the ddc was synthesized on a xilinx® zynq®-7000 zc706 evaluation board. the table shows the post place-and-route resource utilization results. the design met timing with a clock frequency of 331 mhz.

t = table(...
    categorical({'lut'; 'lutram'; 'ff'; 'bram'; 'dsp'}),...
    categorical({'4341'; '383'; '8248'; '2.0'; '36'}),...
    'variablenames',{'resource','usage'})
t =
  5x2 table
    resource    usage
    ________    _____
     lut        4341 
     lutram     383  
     ff         8248 
     bram       2.0  
     dsp        36   

see also

| |

related topics

    网站地图