MATLAB Function for the I/Q Convolver

Typically, at this point you would create or edit a MATLAB function that meets Link for ModelSim requirements. For this tutorial, open and examine the existing file manchester_iqconv.m. This function

  1. Disables resets, marking the start of a cycle.

  2. Establishes a random cycle length of 15, 16, or 17.

    icycle = 15 + floor(rand*3);
    
  3. Generates three vectors of random binary states. One vector represents a data sample. The other two vectors represent the inphase and quadrature waveforms of that data sample.

    samp_vect = randbin(icycle);
    i_wf_vect = randbin(icycle);
    q_wf_vect = randbin(icycle);
    
  4. Uses the function binary_xor to compute the sum of XOR operations on the generated sample and I/Q waveforms and compares the results with the isum and qsum values received from the VHDL entity. Here, computation results produced by MATLAB are being used to verify the convolved results produced by the VHDL model.

    test_isum = binary_xor(i_wf_vect,samp_vect);
    test_qsum = binary_xor(q_wf_vect,samp_vect);    
    if (test_isum ~= bin2dec(oport.isum')),
        disp(['Failed on iteration ' num2str(iters) ',...
        Expected ISUM = 'dec2bin(test_isum,5) ',...
        Received ISUM = ' oport.isum']);
    end
    if (test_qsum ~= bin2dec(oport.qsum')),
        disp(['Failed on iteration ' num2str(iters) ',...
        Expected QSUM = 'dec2bin(test_qsum,5) ',...
        Received QSUM = ' oport.qsum']);
        end
    
  5. Enables resets, marking the end of a cycle.

    iport.reset = '1';
    
  6. Forces the values of the test-generated sample data and I/Q waveforms onto signals connected to the VHDL entity's input ports, samp, i_wf, and q_wf.

    iport.i_wf = i_wf_vect(icycle);
    iport.q_wf = q_wf_vect(icycle);
    iport.samp = samp_vect(icycle);
    

The rest of this section highlights areas of code in manchester_iqconv.m required for MATLAB to verify iqconv.vhd:

  1. Start MATLAB, if it is not already running.

  2. In MATLAB, change your current directory to the directory you created in Setting Up Tutorial Files. If you set up the files elsewhere, adjust the path accordingly:

    cd C:/MyPlayArea
    
  3. Open manchester_iqconv.m in the MATLAB Edit/Debug window. Use the menu option File–>Open and double-click the filename manchester_iqconv.m or enter the edit command as follows:

    edit manchester_iqconv.m
    
  4. Look at line 1. This is where you specify the MATLAB function name and required parameters:

    function [iport,tnext] = manchester_iqconv(oport,tnow,portinfo)
    

    This function definition is significant in that it represents the entity test bench. When coding the function definition, consider the following:

  5. Make note of the data types of ports defined for the entity under simulation. The Link for ModelSim interface converts VHDL data types to comparable MATLAB data types and vice versa. As you develop your MATLAB function, you must know the types of the data that it receives from and needs to return to ModelSim.

    The entity iqconv consists of six input ports of type STD_LOGIC and two output ports of type STD_LOGIC_VECTOR. The interface converts scalar data of type STD_LOGIC to a character that matches the character literal for the corresponding enumerated type. Data of type STD_LOGIC_VECTOR consists of a column vector of characters with one bit per character.

    For more information on interface data type conversions, see Data Type Conversions.

  6. Search for iport.reset. This assignment statement marks the start of a cycle by disabling resets.

  7. Search for oport.isum. This line of code shows how the data that a MATLAB function receives from ModelSim might be converted to a numeric value and compared.

    if (test_isum ~= bin2dec(oport.isum')),
    

    In this case, the function receives STD_LOGIC_VECTOR data on oport.isum. The MATLAB function bin2dec converts the bit vector to a decimal value that can be compared to the numeric value test_isum.

    Just below this area of code, the same conversion is performed for the bit vector oport.qsum.

  8. Search for iport.reset. This assignment statement marks the end of a cycle by enabling a reset.

  9. Search for iport.i_wf. This line of code and the two lines that follow force values onto the signals connected to VHDL entity ports i_wf, q_wf, and samp.

  10. Browse through the rest of manchester_iqconv.m.

  11. Close the MATLAB Edit/Debug window.


Learn more about the latest releases of MathWorks products:

 © 1994-2009 The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS