How can i convert matlab code to c++
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Arun
am 12 Apr. 2024
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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!