Effacer les filtres
Effacer les filtres

How can i convert matlab code to c++

4 vues (au cours des 30 derniers jours)
SAR SAR
SAR SAR le 3 Mar 2020
Commenté : Arun le 12 Avr 2024
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 commentaire
Arun
Arun le 12 Avr 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by