1

I'm writing a code in Matlab with a simple windowing function in order to apply a simple overlap and add algorithm to my input signal.

So far this is what I have written:

[s_a,Fs] = audioread('a.wav');
frame_dur = 0.04; %length of my window in time
frame_stride = 0.01; %shift of every single window in time

frame_len = round(frame_dur * Fs); 
frame_step = round(frame_stride*Fs);

win = hamming(frame_len);

The window overlapping is given by shift in time instead of a percentage value of its length (so every 10ms I have a window that ends 40ms later.

How do i calculate the number of windows in my signal?

I found this solution but i do not have the overlap r. Can I find my number of windows starting from the data I have?

Mattia Surricchio
  • 1,362
  • 2
  • 21
  • 49

2 Answers2

3

Let us assume that n is the number of samples in your audio file:

n=numel(s_a);

When processing your data frame wise (with each window) you would do the follwoing

for frame=1:frame_step:(n-(frame_len-1))

    Tmp=s_a(frame:frame+frame_len-1).*win;
    %do something with tmp

end

So you can see that the amount of windows that fits into your data can be calculated in the following way:

num_win=numel(1:frame_step:(n-(frame_len-1)));

Assuming the worst case that n is not a multiple of frame_len you can calculate it like:

num_win=floor((n-(frame_len))/frame_step)+1;
Irreducible
  • 864
  • 11
  • 24
  • The number of windows changes based on the step size `frame_step`. Here is a slightly modified way to account for this: `num_win = floor((n-frame_len))/frame_step)+mod(n,frame_step);` – mhdadk Dec 19 '20 at 07:27
2

I think that you can consider r as:

frame_dur - frame_stride

and calculate the number of windows (depending on the length of the signal with respect to the stride) with the formula you posted:

m = (n-r)/(k-r)

enrico_ay
  • 76
  • 6