Octave/Matlab Applying a stft on wav file

时间:2016-10-20 18:58:09

标签: matlab fft octave wav

%Octave-Programming 
%Denny Jack Muttathil
% Apply STFT on a small Wav-File
% My audiofile is exactly 10,8525 seconds long.
% If you want to check the length of the wavfile, use the following code 
% in the command window:
% [y,fs]=wavread('Name of the wavfile');
% Total Time=lenght(y)/fs 
% Now the actual code: 
%------------------------------------------------------------------------
[y,fs]=wavread('Test');
% y defines the length of my vector
% fs defines the number of samples per second in the vector y
% wavread, just as the names say, reads my wavfile
% 'Test' is the name of my wavfile 
t=linspace(0,length(y)/fs,length(y));
% Generating a time vector with linspace
% 0 is my start time
% length(y)/fs is my end/stop time
% length(y) is the number of samples in y 
plot(t,y)
% Shows my signal in the time domain

% Now a little bit explanation
% Since my wavfile is about 11 seconds long, i want to take out
% small parts of my wav file, which are 50ms long. On these small
% segments, i want to apply the hanning function. These function uses 
% a window, which performs a stft on each segments. The window is half  
%the size of my segment.

fftlen = 4096; 

segl = 0.05; 
% Length of my segment on which my hanning function is applied
w=segl/2;
% Length of my window size
si=1; %Start index
ei=10.8526; %End index

for m= 1:0.025:(10.8526/w)-1
% Using a for loop to see, what exactly happens
y_a = y(si:ei); 
y_a= y_a.*hann(segl);
Ya=fft(y_a, fftlen);

si=si+w; % Updates my start index 
ei=ei+w; % Updates my end index 

f=0:1:fftlen-1;
f1=fs/(fftlen-1);

figure; plot(f1, 20*log10(abs(Ya)));

end

Hello community! Please take the time to read this. I would really appreciate your help, because it is for a project. Anyway, i want to perform a stft on a wav file. Of course it didnt worked out, like i wished. If you can provide me a simple explanation, what is wrong or even help me out, how to solve this problem, please do so. There are many comments which explains my code how it should work, like i intended.

0 个答案:

没有答案