Export CCS3.3 data and use MATLAB to deal with the method

Source: Internet
Author: User

The CCS3.3 is a DSP integrated development environment (IDE). When doing DSP development, it is the verification algorithm. It is often necessary to use MATLAB for algorithm validation, and the validation algorithm requires data. Thus, one way to interact is to:

    1. Using the DSP Development Board to connect to CCS
    2. Use "File->data->save." In the CCS3.3 menu. function to export DSP in-memory data into the PC's. dat file
    3. Use MATLAB to read. dat files for data processing

Here's how to read a dat file exported by CCS using MATLAB:

% =========================================================================% Read *dat file of CCS3.3% xiahouzuoxin% 2014.04.21% =========================================================================% clc;clear all;close all;%    dialog box select *.dat file [Fname,pname]=uigetfile (... {' *.dat '; '  *. * '}, ' Input *.dat File '); fid = fopen (FullFile (Pname,fname)); Fseek (FID, 21,-1); % go to file header, 21 bytes. For example, 1651 1 80000006 0 100% read Resolution FM = 4;SWITCH (FM) Case 4 in 4Byte format, such as 0x 80000000 x = Textscan (FID, '%2s%8          S ');            Z (:, 1) = Hex2dec (x{2}); Case 2% read in 2Byte format.          such as 0x 8000 0000 x = Textscan (FID, '%2s%4s%4s ');        Z (:, 1) = Hex2dec (x{3});    Z (:, 2) = Hex2dec (x{2}); Case 1% read in 1Byte format.          0x x = Textscan (FID, '%2s%2s%2s%2s%2s ');        Z (:, 1) = Hex2dec (x{5});        Z (:, 2) = Hex2dec (x{4});        Z (:, 3) = Hex2dec (x{3});    Z (:, 4) = Hex2dec (x{2}); otherwise z = [];endif ~isempty (z)% place the data processing code here Endfclose (FID);

In the program, the default DSP memory data storage format is an integer type, and for floating-point DSP such as tms320c6713b, often in memory is a float or double stored in the format,

Then. We also need an operation that translates to floating point numbers. So I wrote a function that was converted to the float type,

function y = integer2float (x, ishex)% ======================================================== =================% Some data y is originally float type. In memory is stored in float format% and now reads it from memory as an integer to X percent This function is used to convert an integer read-out to y% ishex~=0 for input to hexadecimal format% Note: To complete the function, you must understand the format of the IEEE floating-point number xiahouzuoxin% 2014.04.21% =========================================================================if Nargin = = 2 if (ishex) x = Hex2dec (x); Endend[h W] = size (x), y = zeros (h,w), for i = 1:h for j = 1:w sign = bitget (x (i,j), 32); exponent = Bitget (x (i,j), 24:31) * 2.^ (0:7). '; Fraction = Bitget (x (i,j), 1:23) * 2.^ ( -23:-1). '; Y (i,j) = ( -1) ^sign * (1+fraction) * 2^ (exponent-127); EndEnd 

Depending on the input situation (can be 16 binary string representation or decimal number, but must be ≤8bytes), use to give a sample:

>> x=‘4565A012‘>> y=integer2float(x,1);>> x = 23974881923;>> y = integer2float(x)

Later found that Matlab has already had the corresponding method,

y = typecast(uint32(z),‘single‘);

The ability to convert z directly into a single-precision floating-point number. For more information, please see

>> help typecast

Export CCS3.3 data and use MATLAB to deal with the method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.