Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Efficiently Populating .mif File

Hi, this is my first post so I hope it is in the right section. I want to populate a .mif file with samples corresponding to one complete cycle of a sine wave. I generate the samples in matlab. At the moment I have 256 samples and I initially just wrote them into the .mif manually. Clearly this is rather tedious and will become more so since I want to include many more samples. Does anyone know of a more efficient means of achieving this?

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Use Matlab to wite mif:

    fid = fopen('filename.mif','w');

    fprintf(fid,'--MIF data generated by MATLAB\n');

    fprintf(fid,'--Date: %s \n\n', date);

    fprintf(fid,'WIDTH=16;\n');

    fprintf(fid,'DEPTH=256;\n');

    fprintf(fid,'ADDRESS_RADIX=UNS;\n');

    fprintf(fid,'DATA_RADIX=DEC;\n');

    fprintf(fid,'CONTENT BEGIN\n');

    for k = 1:256

    fprintf(fid,'%i : %i;\n',k-1,data(k));

    end

    fprintf(fid,'END;');

    fclose(fid);

    *****************

    you can also copy a column and paste to MIF in Quartus
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    That is fantastic kaz, I just tried it and it worked perfectly. Thank you so much for your help. :D