0
%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.

  • What do you mean by `it didnt worked out, like i wished.`? What is your expected output? – NKN Oct 20 '16 at 19:20
  • I wanted to see the frequency spectrum of my audio file by using the fft –  Oct 20 '16 at 20:18
  • Here I show how a STFT is supposed to work: http://stackoverflow.com/a/38386589/500207 please try to do some debugging on your own to establish where exactly your code is failing. – Ahmed Fasih Oct 20 '16 at 23:28
  • @AhmedFasih Regarding the package how to download it. Do i have to open the link and copy it in a m-file? And then save it in the directory +arf? Not exactly sure how to pull this off. Does it also work on Octave? Due to various circumstances i had to use octave instead matlab. –  Oct 21 '16 at 09:32
  • Like I said in [the answer](http://stackoverflow.com/a/38386589/500207): create a directory, `+arf` in your path, and download the two files `stft.m` and `partition.m` inside them. Then, the code snippet there will work. You can adapt it to your wave file. Let me see confirm that it works in Octave—`partition.m` uses a lot of cell arrays, which should work in Octave just fine, but I’m not sure if namespaces work, so I’ll try to install Octave (Brew install of Octave needs gcc ) and double-check. Stand by. – Ahmed Fasih Oct 21 '16 at 15:05
  • 1
    specgram is part of the octave-forge signal package which does what you want – Andy Oct 21 '16 at 16:31
  • Oh right, what @Andy said. My Matlab spectrogram is breaking currently in Octave 4.2.0-rc2 because of differences in Matlab’s and Octave’s `parse` (to parse input arguments) so `signal.specgram` in octave-forge may be your best bet… (Though note, Python has a nice [`scipy.signal.spectrogram`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html) that I’ve used as well.) – Ahmed Fasih Oct 21 '16 at 16:41

0 Answers0