Applied Speech and Audio Processing: With matlab examples
Download 2.66 Mb. Pdf ko'rish
|
Applied Speech and Audio Processing With MATLAB Examples ( PDFDrive )
- Bu sahifa navigatsiya:
- Basic audio processing Infobox 2.4
2.7. Sound generation
31 2.7.3 Variable tone generation Occasionally it is necessary to generate a time-varying frequency. This is not quite as trivial as one may imagine, since when dealing with sinewaves, any discontinuity when changing frequency will be clearly audible. However the following Matlab function will smoothly transition frequencies when fed with an array specifying desired frequency, sample-by-sample, in Hz: function [snd]=freqgen(frc, Fs) th=0; fr=frc*2*pi/Fs; for si=1:length(fr) th=th+fr(si); snd(si)=sin(th); th=unwrap(th); end We can test this function by creating an array specifying a few musical note frequencies, then convert this into sound and listen to the result: freq=[440*(1+zeros(1,1000)), 415.2*(1+zeros(1,1000)), 392*(1+zeros(1,1000))]; music=freqgen(freq, 8000); soundsc(music, 8000); 2.7.4 Mixing sounds Given two audio arrays of equal length we may combine or mix them together. We will illustrate this and listen to the result using soundsc() (since the result of the addition may well cause individual sample amplitudes to exceed the +/− 1.0 limit which would cause the sound() function to clip). Here are notes of a chord generated and replayed in Matlab: C=tonegen(261.63, 8000, 2); E=tonegen(329.63, 8000, 2); G=tonegen(783.99, 8000, 2); B=tonegen(987.77, 8000, 2); soundsc(C+E+G+B, 8000); For those readers with a musical theory background, it should be relatively easy to create Matlab functions able to create specified chords, minors or majors and replay them on demand. 32 Basic audio processing Infobox 2.4 Visualisation of signals As an example of the difficulty in analysing a constantly changing signal, we will deliberately construct a ‘frequency agile’ signal (one which changes rapidly in frequency characteristics) and then plot it: y=chirp([0:0.001:5],0,5,500); %construct a frequency chirp z=[y,y[length(y):-1:1],y]; %make a zig-zag First let’s take one huge FFT and plot this as shown below: f=abs(fft(z, 8192)); plot(f(1:4096)); Absolute FFT plot of chirp spectrum. Does this spectrum really represent the characteristics of the signal we have constructed? Let us explore further by slicing the signal up into smaller pieces and plotting as a waterfall plot to see how the frequency changes over time. We could do the slicing manually, but in this case we can be lazy and use spectrogram which accomplishes the same thing for us: s=spectrogram(z, 1024); waterfall(abs(s)’); % may take some time to process Absolute FFT plot for audio spectrum. The waterfall plot above shows almost 30 slices in time, each one giving a 512-bin FFT plot, and clearly indicating that a different frequency component is present during each of the time periods. Evidently a totally different picture emerges of the signal in this plot compared to the spectrum plotted initially. If we had relied upon only an FFT to observe the signal characteristics we would have missed a significant amount of information. Now explore the spectrogram function; without assigning its output to a variable, it plots the spectrogram directly on screen. Try changing the 1024 to 256 and then 8192 and see the difference it makes to the visualisation, and to your understanding of what the signal really is. |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling