Dividing an audio signal into frames

12 views (last 30 days)
Biju
Biju on 3 Dec 2012
Answered: Walter Roberson on 10 Oct 2019
I have this speech signal(in au format), that I need to divide into 30ms frames, and I have no idea on how to do that. The following is the code I have so far into to plot and show the signal:
%% Speech Signal
clear; close all; clc;
set(0,'defaultaxesfontsize',11);
%% Reading Audio File
[x, Fs, bits] = auread('phrase.au');
Fs
bits
%% Display Speech Waveform
t = 0:1/8000:2.5;
x = x(1:20001);
figure(1)
plot(t, x)
xlabel('Time (sec)');
ylabel('Amplitude');
title('Speech Waveform "Phrase"');
%% Speech sound
soundsc(x,Fs);
Any information regarding this issues will be greatly appreciated.

Answers (1)

Walter Roberson
Walter Roberson on 10 Oct 2019
You can use buffer() from the signal processing toolbox. However, you need to process one channel at a time to use buffer() .
30 ms at 8000 Hz is 240 samples.
Your code assumes that what you read is a single channel at least 20001 samples long (2.5 seconds plus one sample). If it is not then your code will accidentally put data from the second channel after the end of the first channel.
Because 20001 samples is not evenly divisible by 240, you will end up with a partial frame. buffer() handles that by padding the last frame with 0.
If you do not have the signal processing toolbox, you can divide into cell array entries:
x_frames = mat2cell(x(:), [240*ones(1,floor(numel(x)/240)), mod(numel(x),240)], 1);
x_frame{end} will end up with only 81 entries, which could be a problem for your code. You need to make a decision as to what you want to do with those 81 samples.

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!