Conversion of complex number in to fixedpoint representation
조회 수: 23 (최근 30일)
이전 댓글 표시
i want to convert array of complex number in to fixed point (Q1.14) . how to do this things
(0.5590 + 0.1757i,
0.1771 + 0.9121i,
0.9884 + 0.1842i,
0.4145 + 0.8949i,
0.1781 + 0.0133i,
0.8541 + 0.2089i,
0.6628 + 0.1040i,
0.5400 + 0.5972i,
0.4648 + 0.0715i,
0.3596 + 0.8972i,
0.3479 + 0.9052i,
0.3308 + 0.7455i,
0.7069 + 0.2999i,
0.7640 + 0.2425i,
0.0567 + 0.1967i,
0.4460 + 0.6754i,
0.8985 + 0.7363i,
0.9995 + 0.1341i,
0.8182 + 0.0538i)
i wrote code for this but i don't know it is right or not
my code is
fid = fopen('1.txt', 'rt');
x = textscan(fid, '%f');
fprintf(fid, '%f%+fi\n', real(x{:,1}), imag(x{:,1}))
fclose(fid);
x{1}
%%convert complexdata into 32bit binary
re = real(x{:,1});
im = imag(x{:,1});
n = uint32(((re<0) + abs(re)) * 2^15) * 2^16 + uint32(((im<0) + abs(im)) * 2^15)
d=dec2bin(n(:,1),32)
답변 (1개)
Dimitris Kalogiros
2018년 9월 12일
편집: Dimitris Kalogiros
2018년 9월 12일
An example:
clear; clc; close all;
% a complex number
x=0.3435637634857634+1i*0.66735646778675;
% parameters for fixed point conversion
wordLength=15;
sign=0; % unsigned numbers
fractionalPart=14;
% covertion to fixed point
X=fi(x,sign,wordLength, fractionalPart);
% how to access values
Xre=real(X);
disp('binary word: '); disp(Xre.bin); fprintf('\n');
disp('real world value, as a string: '); disp(Xre.Value); fprintf('\n');
disp('fixed point value: '); disp(Xre.data); fprintf('\n');
% comparison with floating arithmetic values
disp('----------------');
disp('rounding error: ')
disp( X.data-x )
Conversion to fi-objects is controlled from muny parameters, I suggest to have a look at mathwork's help files
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!