%% m file to compute the 4 functions in the M-File lab
clear;y=zeros(4,256);
x=0:255;                     %% all have length 256
y(1,:)= x;        %% first is the 1 kHz sine function
y(2,:)= x;        %% second is the random noise function
y(3,:)= x;        %% impulse noise
y(4,:)= x;        %% 16 th harmonic, i.e., 16 kHz sine

%%%%%%%%%%%%%%% Plot the 4 functions %%%%%%%%%%%%%%%%%%%%%%%%%
for k=1:4
  subplot(2,2,k)
  stairs(x,y(k,:),'k-');
  switch k 
      case 1, title('lut0:1 KHz sine');
      case 2, title('lut1:Random noise');
      case 3, title('lut2:Impulse noise');
      otherwise title('lut3:16th harmonic, i.e., 16 kHz sine');          
  end
  axis([0 255 1.5*min(y(k,:)) 1.5*max(y(k,:))]);
  str=sprintf('lut%d.mif',k-1); fid=fopen(str,'w');
  fprintf(fid,'depth= 256;\r\nwidth = 16;\r\n');
  fprintf(fid,'address_radix = dec;\r\ndata_radix = dec;\r\n');
  fprintf(fid,'content \r\nbegin\r\n');
  xy=[x; y(k,:)];
  fprintf(fid,'%d : %d;\r\n',xy);
  fprintf(fid,'end;\r\n');
  fclose('all');
end;
print -djpeg90 fungen.jpg