Write the output to a text file

Hello there, I would like to generate a lookup table, which is going to hold values to generate a COS wave of 6khz with a sampling freq of 8Khz using Matlab. The values of the LUT needs to be exported as a xxx.h header file in order to "include" this in my main.c, that programs my DSP kit ( C6713 ). Below, I've given my script. Kindly let me know what changes do I need to make in order to solve this.
P.S.: What i tried was to export the table as a text file, which I can open in Notepad and label it as header file.
% code
F_sin = 666.66; %Desired frequency
F_sample=8000; %Sampling frequency
N=F_sample/F_sin; %Number of samples
T=1/F_sample;
for t=0:T:(N-1)*T %Incremental distance
%disp(t);
sin_table=cos(2*pi*t*F_sin)
for k=0:N-1
y(:,k) = sin_table;
%disp(sin_table);
end
end
headerfile = fopen('Hw1.txt', 'w');
fprintf(headerfile,'%f\n',y);
fclose(headerfile);

Réponses (1)

ANKUR KUMAR
ANKUR KUMAR le 30 Oct 2017
fileID=fopen('my_text.txt','w');
fprintf(fileID,'%6.0f\n',y');
fclose(fileID)
On the second line, based on the number of columns in y, you can change the second line. If you have 5 columns in y, then you can write
fileID=fopen('my_text.txt','w');
fprintf(fileID,'%6.0f %6.0f %6.0f %6.0f %6.0f\n',y');
fclose(fileID)
P.S. There is y' at the last in the second line.

2 commentaires

Karthik Shanmugam
Karthik Shanmugam le 30 Oct 2017
I tried to do what you said. But, the text file contains only one value i.e. 1 and not all the values.
Karthik Shanmugam
Karthik Shanmugam le 30 Oct 2017
Is there any other way to do this? As told earlier, am trying to export the LUT as a header file for main.c . Will Matlab coder be easy way?

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Coder dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by