Audio Procesing

Im new to Matlab. I need to split the time dimensions of an audio track into frames of 10mS and for every 10mS frame have to compute the FFT to generate the spectrograph. I need help on this.

 Accepted Answer

Wayne King
Wayne King on 17 Jan 2012
Hi Karthik, Why can't you just use spectrogram()? You can specify the window length (the number of samples corresponding to 10 msec) as an input.
If you cannot use spectrogram(), you can use reshape() as one option.
Suppose you have an audio signal sampled at 20 kHz.
Then 200 samples is 10 msec.
x = randn(2e4,1);
x = reshape(x,200,100);
You can then apply the Fourier transform to the columns of x.
Better than the above option is buffer(), which allows you to construct overlapping segments.
x = 1:16;
x = buffer(x,4,2)
Again, spectrogram provides a NOVERLAP input argument that handles this easily.

4 Comments

Karthik Raj
Karthik Raj on 17 Jan 2012
K thanks for your reply.
When is use spectrogram() directly it flags an error saying input must be vector.
My audio signal is of length 4 mins. When i stored that in an array it forms a matrix of size 11470464 x 2
frequency is 44100
so samples will be 441 for 10ms correct? how to proceed?
These thing may be silly but help me.
Thanks.
Wayne King
Wayne King on 17 Jan 2012
yes, you don't input an array into spectrogram(). Input a vector. If you have a two-channel audio signal, then just give spectrogram 1 column
input = x(:,1);
Yes, that is correct. 441 samples. You will definitely want to play with NOVERLAP.
You can try:
S = spectrogram(x,441,[],[],44100);
to start
Wayne King
Wayne King on 17 Jan 2012
[s,f,t,p] = spectrogram(x,441,[],[],44100);
surf(t,f,10*log10(abs(p)),'EdgeColor','none');
axis xy; axis tight; colormap(jet); view(0,90);
xlabel('Time');
ylabel('Frequency (Hz)');
Karthik Raj
Karthik Raj on 17 Jan 2012
thanks i got it. Then how to input the window and fft of the signal to spectrogram?
my script looks like this...
[y,fs]=wavread('aud1.wav');
t=fs/100;
nfft=fft(y,t);
nwindow=hann(t);
[s,f,t,p]=spectrogram(y(:,1),t,nwindow,nfft,fs);

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!