Conversion of dlmread() using MatLab Coder - Not supported for code generation to C
显示 更早的评论
I have a compensation function that reads in a 2-column csv file. When I run this fuction in the MatLab Coder Generator to convert it to a standalone C function, it states that my dlmread() call, which reads in the csv file, is not supported. I saw that dlmread() should be replaced with readmatrix(), but that is not supported either.
How do I go about converting this call, dlmread() or readmatrix(), over to Matlab code that the MatLab Coder app will recognize? Below is my function:
function x = compensation(band, x, fc)
% Algorithm parameters
fs = 4.5e9; % Sample rate
[Nf, K] = size(x); % Number of SHAPE vectors in the file
if strcmp(band, 'lb')
comp_fn = 'low_band_comp.csv';
elseif strcmp(band, 'hb')
comp_fn = 'high_band_comp.csv';
end
% Calculate the average power spectral density
Xf = fftshift(fft(x, [], 1), 1);
f = [0 : Nf-1]' * fs/Nf - fs/2;
% Read the compensation vector data
F = dlmread(comp_fn);
frq = F(:,1)*1e6; % Convert MHz data to Hz
mag = F(:,2);
% Translate compensation data in frequency
if strcmp(band, 'lb')
frq = frq - fc; % Digital LO
elseif strcmp(band, 'hb')
frq = fc - frq; % f_out = f_lo - f_bb
frq = flipud(frq); % Digital LO
end % Put in ascending order for interpolation
% Normalize compensation data in magnitude
mag = (10.^(mag/10));
mag = mag/mean(mag);
mag = 10*log10(mag);
M = length(mag);
% Interpolate the compensation data
mag_m = ones(Nf,1);
k = 1;
for m = 1 : Nf
if f(m) >= frq(1) && f(m) < frq(M)
if f(m) < frq(k+1) && f(m) >= frq(k)
mag_m(m) = (mag(k+1) - mag(k))*(f(m) - frq(k))/(frq(k+1) - frq(k)) + mag(k);
else
mag_m(m) = (mag(k+1) - mag(k))*(f(m) - frq(k))/(frq(k+1) - frq(k)) + mag(k);
k = k + 1;
end
end
end
figure(3);
plot(frq/1e6, mag, 'b.-');
hold on;
plot(f/1e6, mag_m, 'r.-');
hold off;
title('Compensation Spectrum');
xlabel('Frequency - MHz');
ylabel('Magnitude - dB');
grid on;
% Convert to magnitude scaling values
mag_vec = 10.^(+mag_m/20);
% Apply the compensation vector to frequency domain data
Xf = Xf .* (mag_vec * ones(1,K));
% Recalculate the SHAPE vector from frequency scaled input
x = ifft(fftshift(Xf, 1), [], 1);
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Generated Code Interfacing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!