How can I divide an audio signal into frames and write the frames into a matrix?

37 views (last 30 days)
Hi all!
I need to divide an audio signal into frames of length = 128 samples each, then multiply each frame by the Hamming window and write the windowed frames into a matrix where each row of this matrix contains a single frame.
This is what I did so far:(I'm stuck at the for loop!)
[input, fs] = wavread('.....'); % input= <15360x1 double> , fs= 22050
N=15350;
L = length(input)./fs; % time in seconds -> L=0.96
w_length = 128; % window length
w = hamming(w_length); % window type - hamming
% windowing and matrix creation
for 1:w_length:N
.
.
end
Thank you in advance!
  2 Comments
Shashank R
Shashank R on 5 Mar 2017
@Geoff Hayes, I tried the same thing and it kept showing me the error when I tried to apply the Hamming Window. Could you please help me out. I'm new to Matlab and also as David asked about recovering the signal through concatenation.
Thanks in Advance
Geoff Hayes
Geoff Hayes on 6 Mar 2017
Shashank - which error? Please copy and paste the full error message and describe what you are doing. You may want to post this as a new question if it is significantly different from this one.

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 3 Aug 2014
David - what is N? Is that the assumed length of the input?
Probably one of the first things that you want to do is to allocate memory to the matrix to store each frame/block of data. You know that the Hamming window size is 128 (which will be the number of columns in the matrix), and you need to determine the number of rows
% determine the number of rows/frames
m = length(input);
numFrames = floor((m-1)/w_length)+1;
% allocate memory to the frame matrix
frameData = zeros(numFrames,w_length);
Now, extract the frames from the input data
for k=1:numFrames
startAtIdx = (k-1)*w_length+1;
if k~=numFrames
frameData(k,:) = input(startAtIdx:startAtIdx+w_length-1);
else
% handle this case separately in case the number of input samples
% does not divide evenly by the window size
frameData(k,1:m-startAtIdx+1) = input(startAtIdx:end);
end
end
All that is missing is to apply the Hamming window...which I will leave for you. Try the above and see what happens!
  5 Comments
Sumayyah Hai
Sumayyah Hai on 30 Aug 2017
@Geoff Hi! I was wondering how you would implement the hamming window on the framed matrix. What will you use as input argument for the: w=hamming(L) command? The number of samples in one frame, 128, or the number of frames (rows)? And after getting the w vector how would you implement it on the frameData matrix?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!