function [z] = soundfile(y,varargin) %"Song of convergence" Copyright Andrew Knyazev 1998 %Z=soundfile(Y) takes the colunm-vector Y %with components describing history of convergence %of an iterative method and returns a file Z that %can be played with sound(Z) command. %Convergence is assumed to be close to linear. %The program will take first two columns %of Y, if Y has more then one column. %That will produce a stereo sound, is supported %by user's hardware. %The default playing time is about a second %on my computer. It can be changed by using an %optional scalar input argument, %Z=soundfile(Y,length). Reasonable range of length %is between 0.1 and 3. %Example: %q(1,1)=1;q(1,2)=1; %for i=2:100 %q(i,1)=0.99*q(i-1,1); %q(i,2)=0.89*q(i-1,2); %end %s=soundfile(q,2); %sound(s); %will play a stereo sound for ~2 seconds. nin = max(nargin,1)-1; if nin>0 length=cat(nin,varargin{:}); else length=1; end if length > 3 disp('The value of the optional argument is too big') disp('The program soundfile may take forever to execute') disp('Enter the number again,') an=input('or just press "Enter" to use the default "1":'); if isempty(an) length=1 else length=an end end [n,nchannel]=size(y); nchannel=max(2,nchannel); y=log(y); maxy=max(max(y)); miny=min(min(y)); y=(y-miny)/(maxy-miny); x=(1:n)'/n; size=round(length*10000); xi=(1:size)'/size; yi=interp1(x,y,xi,'*linear'); for i=1:size for j=1:nchannel z(i,j)=sin(size*xi(i)*(1.2+yi(i,j))); end end