How can i convert matlab code to c++

조회 수: 4 (최근 30일)
SAR SAR
SAR SAR 2020년 3월 3일
댓글: Arun 2024년 4월 12일
Hello, I am new in matlab. I have script that i need to convert to c++. What is the easiest way to do this? Here is the script
fs = 125e6;
f0 = 30e6;
filename = 'filename';
delimiter = ',';
startRow = 2;
formatSpec = '%*s%*s%*s%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%*s%*s%*s%*s%*s%*s%*s%*s%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
fclose(fileID);
xx = table(dataArray{1:end-1}
x = xx;
[num_sample,num_chan] = size(x);
for k = 1:25
end;
cx(:,k) = (hilbert([x{:,k}])).';
%%
for k = 1:num_sample
gen_sin(k) = sin(2*pi*f0*k/fs);
gen_cos(k) = cos(2*pi*f0*k/fs);
end;
cgen=(complex(gen_sin,gen_cos)).'
x_down = cgen.*cx;
Filt = designfilt('lowpassfir','FilterOrder',566,'PassbandFrequency',0.005e6, ...
'StopbandFrequency',1.5e6, ...
'SampleRate',fs);
fcx = filter(Filt,x_down); %
%% Magnitude
mag_fcx=(abs(fcx));
avmag_fcx=(zeros(1,25));
for k = 1:25
num_averag=0;
for kk = 300:1023
avmag_fcx(k)= (avmag_fcx(k)+mag_fcx(kk,k));
end;
avmag_fcx(k)= avmag_fcx(k)/724;
end;
for k = 1:25
dmag_fcx(k)=avmag_fcx(1)/avmag_fcx(k); % множитель калибровочный
end;
log_dmag_fcx=20*log(dmag_fcx);
%% Angles
ang_fcx=(angle(fcx))*180/pi;
for k = 1:25
for kk = 1:1024
if ang_fcx(kk,k)<0
ang_fcx2(kk,k)=360 + ang_fcx(kk,k);
else ang_fcx2(kk,k)= ang_fcx(kk,k);
end;
end;
end;
for kk = 1:1024
for k = 1:25
dang_fcx(kk,k)=ang_fcx2(kk,1) - ang_fcx2(kk,k);
if dang_fcx(kk,k)<0
dang_fcx(kk,k)=360 + dang_fcx(kk,k);
end;
end;
end;
%% Write to file
fid = fopen('filename1','w');
fprintf(fid,'УГОЛ,град');
fprintf(fid,'\t');
fprintf(fid,'АМПЛИТУДА,разы');
fprintf(fid,'\n');
status = fclose(fid);
  댓글 수: 1
Arun
Arun 2024년 4월 12일
MATLAB Coder is used to generate C and C++ code from MATLAB code. If it is already installed use the MATLAB coder app under Apps tab in MATLAB. It will guide you through steps to generate C++ code.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by