Euler can handle sound and graphics. Sound can be created with the Euler matrix language, and analyzed with the Fast Fourier Transform (FFT). Euler can save sound in the wav file format, and play sounds in files. Let us generate 5 seconds of sound. The default sampling rate is 22050 per second. First we need the time variable.
>t=soundsec(3);
Now generate a 440 Hz sound.
>s=sin(t*440)+sin(t*880)/2;
We can analyze it using FFT.
>analyzesound(s):
To play the sound, Euler saves the file in the user home directory. After playing the file, it is deleted.
>playwave(s);
We add some noise.
>s=s+normal(size(s))*0.1; >analyzesound(s):
>playwave(s);
To fix this noise, we FFT the signal, and remove anything smaller than 0.1 times the maximal FFT result.
>f=fft(s); m=max(abs(f)); f=f*(abs(f)>0.1*m); s=re(ifft(f)); >analyzesound(s):
This clears the sound effectively.
>playwave(s);
We can also remove the sound with a filter.
>s=sin(440*t)+sin(880*t)/2+normal(size(f))*0.2;
First the sound with noise.
>playwave(s);
Now we use a simple filter, averaging over the 10 neighbors of each element.
>h=zeros(size(s)); h[1:10]=1/10*ones(1,10);
FFT can be used to fold a sound with the filter.
>s=fftfold(s,h);
The result is not perfect.
>playwave(re(s));
Let us try a sound with changing frequencies.
>f=880*(1-0.5*exp(-t/max(t)*5)); s=sin(f*t);
This defines the factor f, which controls the frequencies.
>plot2d(t,f):
We can make a windowed FFT for this with the following function.
>mapsound(s):
Hear the sound.
>playwave(s);
For more examples on sound in Euler see the following notebooks. See: Examples/Temperament in Musical Pitch See: Examples/Sample Rates of Sound
Graphics can be stored in Euler in compact form, using one real number for each pixel, or in matrices of red-, green-, or blue-channel. Let us create a colorful matrix.
>r=0:0.005:1; g=(0:0.005:1)'; M=rgb(r,g,0);
The matrix is plotted with the (0,0) corner in the lower left. The plot with "plotrgb" fills the current plot window.
>plotrgb(M);
The command "insrgb" inserts a rgb matrix into the notebook window. Note that the graphics is only 200x200.
>insrgb(M);
To save the file, we choose a location in the user home directory.
>file=userhome()|"test.png"
C:\Users\Rene\test.png
Save the file.
>savergb(M,file);
Load it back, and remove the file.
>M=loadrgb(file); remove(file);
Let us add some blue noise. To do this, we extract the red and green channels and set the blue channel to a random value, and reassemble this to a rgb image with the "rgb" function.
>insrgb(rgb(getred(M),getgreen(M),random(size(M))));