[Scilab-users] How to convert .wav to formula?

Rafael Guerra jrafaelbguerra at hotmail.com
Wed Feb 7 22:40:45 CET 2018


Hi,

Q: "I only got graphic? What to do?"
A: look at Fourier synthesis of periodic waveforms.

For the toy example provided of a monochromatic wave, the simple code here below finds the approximate solution.
More general waveform case, needs much more programming effort.

// START OF CODE
clear; clf;
fs = 22050; // default sampling rate (Hz)
t=soundsec(0.5,fs);
s=[sin(2*%pi*440*t)];
savewave('foo.wav', s);

y = loadwave('foo.wav');
y = [y zeros(y)];  // make #samples even & increase spectral resolution
Yf = abs(fftshift(fft(y)));
N = length(Yf);
Yf = Yf(N/2+1:$);
f = linspace(0,fs/2-fs/N,N/2);
[y0 k] = max(Yf);
plot(f,Yf,'blue',f(k),Yf(k),'*red')
xlabel("Frequency [Hz]")
printf("sinusoid frequency = %.1f Hz",f(k))
// END OF CODE

Regards,
Rafael



More information about the users mailing list