Write the output to a text file
5 views (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
ANKUR KUMAR
on 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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!