To display positive frequencies, trim the second half of the Xmag array. --> N =
length(x). --> Xmag = Xmag(1:N/2);. Values for the horizontal frequency axis may
...
DSP Notes: Sound I/O and Spectrums Dr. Fred DePiero, CalPoly State University Sound File I/O and Spectral Analysis in SciLab To load one a WAV file such as ‘guitar.wav’ into SciLab, use --> [x,S,bits]=wavread(‘guitar.wav’); This will initialize the vector x with the WAV signal data, it will also store the sample rate (S, in Hz) that was used when the file was captured. The variable ‘bits’ above will receive the number of bits associated with each sample – which is typically either 8 or 16. The signal may be plotted, versus seconds, via: --> --> --> -->
t = 0:(N-1); t = t / S; plot2d(t,x); xtitle("x(t)","t (Sec)", " ") x(t)
1.0 0.8 0.6 0.4 0.2 0.0 -0.2 -0.4 -0.6 -0.8 t (Sec)
-1.0 0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
The above signal, x, was digitized from a guitar (sample rate 16 kHz). It is the open G string. The true analog frequency is 220 Hz (assuming correct tuning). To compute the magnitude of the spectrum of x, use: --> X = fft(x,-1); --> Xmag = abs(X) To display positive frequencies, trim the second half of the Xmag array --> N = length(x) --> Xmag = Xmag(1:N/2); Values for the horizontal frequency axis may be setup using: --> F = 0:((N/2)-1); --> F = F * S/N; Finally the plot of the spectrum, with title are generated with: --> plot2d(F,Xmag); --> xtitle("|X(f)|","f (Hz)", " ") |X(f)| 2800
2400
2000
1600
1200
800
400
f (Hz)
0 0
1000
2000
3000
4000
5000
6000
7000
8000
SciLab permits zooming within its graphics window, for example: |X(f)| 2800
2700
2600
2500
2400
2300
2200
2100
2000 -100
f (Hz) 0
100
200
300
400
500
600
700
800
900
This spectrum is consistent with the frequency of the original analog signal, 196 Hz. Additional harmonics are revealed in the previous plot.