0
votes

I'm having trouble with the syntax in Matlab.

I'm trying to split an audio signal up into different segments (frames).

I would like to return the y-axis values to a matrix (each segment having its own column), and the corresponding time values with each segment having its own row.

I can't even get it to return just one single column and row pair (ie one frame). I just get returned two empty matrices. Here's my code.

function [mFrames, vTimeFrame] = Framing(vSignal,samplingRate,frameLPerc,frameshPerc)


totalTime=size(vSignal,1)/samplingRate

frameLength = totalTime*frameLPerc;
frameShift = totalTime*frameshPerc;

frameNumber =0;
check=frameLPerc;

while check<1
    check = check+frameshPerc;
    frameNumber=frameNumber+1;
end

start = 1;
% problem part
    mFrames = vSignal(round((start:1/samplingRate:frameLength)*samplingRate));
    vTimeFrame = round((start:1/samplingRate:frameLength)*samplingRate);

end

In the end I would like to be able to segment my entire signal into mFrames(i) and vTimeFrame(i) with a for-loop, but never mind that I cannot even get my function to return the first one (like I said empty matrix).

I know my segment code should be correct because I've got another script working with the same vSignal (it's a column vector by the way) that works just fine (y==vSignal):

voiced = y(round((1.245:1/Fs:1.608)*Fs));
plot(1.245:1/Fs:1.608,voiced)

I titled this with syntax problems because I'm very new to matlab and am used to Java. It feels very weird not initializing anything, and so I'm unsure whether my code is actually making any sense.

When testing I enter [m1,m2]=Framing(y,16000,0.1,0.05).

1
It seems to me that you have few unwanted things in your method like frame shift and frameNumber. What is purpose of while loop? use vTimeFrames to index vSignal. - User1551892
Like I said at some point I would use a for-loop to look at the whole signal. To know how many times I have to shift I have frameNumber which gets figured out with the while-loop. And of course as I look at different segments I will have to shift my starting point, that's why frameShift: so a for loop would be for i=1:frameNumber (start=start+frameShift) - Nimitz14

1 Answers

0
votes

I got it.

start was not in the right domain. This is correct:

round((start/samplingRate:1/samplingRate:frameLength)*samplingRate)

When I plot(m2,m1) I now get the correct answer.

I do still have another question though, how can I assign these segments to my matrices?

for i=1:frameNumber
    mFrames(:,i) = vSignal(round((start/samplingRate:1/samplingRate:frameLength)*samplingRate));
    vTimeFrame(i) = round((start/samplingRate:1/samplingRate:frameLength)*samplingRate);

    start=start+frameShift; 
    frameLength=frameLength+frameShift;

end

I get this error

In an assignment  A(I) = B, the number of elements in B and I must be the same.

Like I said I'm trying to get the y-axis numbers in columns next to each other and the x-axis in rows.