comparison Functions/createMat.m @ 0:ab043bd3b162 tip

First commit
author Alice Clifford <alice.clifford@eecs.qmul.ac.uk>
date Mon, 11 Jun 2012 17:42:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ab043bd3b162
1 function [matOut,numFrames]=createMat(x,frameSize,hopSize)
2
3 % create a matrix of frames of input x
4 %
5 % Input:
6 % - x: 1 or 2 column vector (audio data)
7 % - frameSize: size of frames
8 % - hopSize: number of samples overlap
9 %
10 % Output:
11 % - matOut: matrix of frames, either (frameSize x numFrames) for 1
12 % channel or (framSize x 2 x numFrames) for stereo
13 % - numFrames: number of frames in matOut
14 %
15 % Developer: - Alice Clifford (alice.clifford@eecs.qmul.ac.uk)
16
17 sizeX=size(x);
18
19 if sizeX(1)==1 || sizeX(1)==2
20 x=x'; %make columns
21 end
22
23 sizeX=size(x);
24
25 if sizeX(2)==1
26 fileType='mono';
27 elseif sizeX(2)==2
28 fileType='stereo';
29 else
30 error('Input is neither mono or stereo')
31 end
32
33
34 numFrames=(floor(length(x)/hopSize));
35
36 for n=1:numFrames
37
38 xStart=(n-1)*(hopSize)+1;
39 xEnd=(n-1)*(hopSize)+frameSize;
40
41 %Break if frame index goes over length of x
42 if(xEnd>length(x))
43 break
44 end
45
46
47 if strcmp(fileType,'stereo')
48 xframe=x(xStart:xEnd,:);
49 matOut(:,:,n)=xframe;
50
51 elseif strcmp(fileType,'mono')
52 xframe=x(xStart:xEnd);
53 matOut(:,n)=xframe;
54 else
55 error('File type unknown')
56 end
57
58 end
59
60 sMat=size(matOut);
61
62 if strcmp(fileType,'stereo')
63
64 numFrames=sMat(3);
65
66 elseif strcmp(fileType,'mono')
67
68 numFrames=sMat(2);
69 end