diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Functions/createMat.m	Mon Jun 11 17:42:13 2012 +0100
@@ -0,0 +1,69 @@
+function [matOut,numFrames]=createMat(x,frameSize,hopSize)
+
+% create a matrix of frames of input x
+%
+% Input:
+%   - x: 1 or 2 column vector (audio data)
+%   - frameSize: size of frames
+%   - hopSize: number of samples overlap
+%
+% Output:
+%   - matOut: matrix of frames, either (frameSize x numFrames) for 1
+%   channel or (framSize x 2 x numFrames) for stereo
+%   - numFrames: number of frames in matOut
+%
+% Developer:  - Alice Clifford (alice.clifford@eecs.qmul.ac.uk)
+
+sizeX=size(x);
+
+if sizeX(1)==1 || sizeX(1)==2
+    x=x'; %make columns
+end
+
+sizeX=size(x);
+
+if sizeX(2)==1
+    fileType='mono';
+elseif sizeX(2)==2
+    fileType='stereo';
+else
+    error('Input is neither mono or stereo')
+end
+
+
+numFrames=(floor(length(x)/hopSize));
+
+for n=1:numFrames
+    
+    xStart=(n-1)*(hopSize)+1;
+    xEnd=(n-1)*(hopSize)+frameSize;
+    
+    %Break if frame index goes over length of x
+    if(xEnd>length(x))
+        break
+    end
+    
+    
+    if strcmp(fileType,'stereo')
+        xframe=x(xStart:xEnd,:);
+        matOut(:,:,n)=xframe;
+        
+    elseif strcmp(fileType,'mono')
+        xframe=x(xStart:xEnd);
+        matOut(:,n)=xframe;
+    else
+        error('File type unknown')
+    end
+ 
+end
+
+sMat=size(matOut);
+
+if strcmp(fileType,'stereo')
+    
+    numFrames=sMat(3);
+    
+elseif strcmp(fileType,'mono')
+    
+    numFrames=sMat(2);
+end
\ No newline at end of file