So I have wrote some code which takes an audio file and splits into frames of 320 samples for the 16000hz.
I have took the hamming window of each frame as shown by the code:
fs=16000;
[x,fs] = audioread('01.wav');
%Pre-emphasis filter (Y[n]=X [n]-0.95x[n - 1])
b = [1 -0.95];
y = filter(b,1,x);
%windowing
numSamples = length(y);
frameLength = 320;
numFrames = floor(numSamples/frameLength);
for frame = 1:numFrames,
firstSample = (frame * frameLength) - (frameLength - 1);
lastSample = (frame * frameLength);
shortTimeFrame = y(firstSample:lastSample);
h = hamming(320);
hs = h.*shortTimeFrame;
plot(hs, 'r');
end
How would I then overlap the hamming windows by 50%? I have seen other questions on SO and seen answers such as this:
y = buffer(h, 1, floor(64 * 0.5));
But have had no luck with it
Have a look at the documentation for the
buffer
function.The first argument is your signal (i.e. not the hamming window). If you do:
you will get out a matrix
Y
where your signal has been split into overlapping frames; that is, every column ofY
is of size 320 (i.e. a frame), and the last 160 elements of one column are identical to the first 160 elements of the next column.Applying the hamming window of your choice to each 'frame' is then a simple case of multiplying each column with the hamming window, e.g.
inb4pedants:
repmat
isn't the most efficient way to do this, but it's the clearest to demonstrate the concept. Preferbsxfun
if possible, (or broadcasting in octave).