1

I have a project where I have to recognize the frequency from an audio file. For this I use a single tone of 10 kHz to see if I can get it working. Since I am pretty new to Octave, I tried this example with my own audio file. I tried to understand what happens by doing some research to all functions.

My question here is; if I let specgram plot the figure when I do not specify it's output:

specgram(y,fftn,Fs,hanning(window),step);

it gives a line at 10kHz which is what I want.

But if I specify the output for the specgram function

[S,f,t]= specgram(y,fftn,Fs,hanning(window),step);

and let it plot, it plots the line at 18 kHz.

I figured it have to be in the inputs for the figure and I tried modifying these a bit, but every time I do that Octave gives an error. I need the frequency as an given output, since I have to do some calculations with it, I figured I need to specify the frequency output.

This is the part of the code that specify the plot for the spectrogram:

step= fix(5*Fs/1000);           % stepsize of the window
window= fix(90*Fs/1000);        % window size 
fftn =2^nextpow2(window);       % Size of the FFT block

[S,f,t]= specgram(y,fftn,Fs,hanning(window),step); 

S= abs(S(2:fftn*12000/Fs,:));   % Normalize the phase
S= S/max(S(:));                 % Normalize the Energy
S= max(S, 10^(-40/10));         % Throw out values below -40 dB and above -3dB
S= min(S, 10^(-3/10));      
figure
imagesc(t,f,(log(S)));

Can anyone help me here how to gain the frequency data from the audio file so I can use it in some calculations?

I have searched for answers already in the Octave manual for help and I tried it with various matlab sites. Also checked already many posts here such as:

How does Octave spectrogram 'specgram' from signal work?

Methodology of FFT for Matlab spectrogram / short time Fourier transform functions

P.S. Sorry for my bad English, it's not my native language

Community
  • 1
  • 1
Lord Me
  • 11
  • 2
  • You should provide a minimum complete working example. The 'demonstration 1' in the documentation does not work for you ? You mention an error. Which one ? – ederag Mar 01 '15 at 11:22
  • I tried the 'demonstration 1', and that one works. But I need the value for the frequency, not the plot. – Lord Me Mar 02 '15 at 09:02
  • I tried modifying the terms for the normalisation of the phase, I deleted the abs function, which gives the error: wrong type argument 'complex matrix'. If I delete either the fftn of Fs terms it gives: nonconformant arguments (op1 is 0x352, op2 is 0x1). I think the fault is in that line, maybe you could tell me what that line exactly does? – Lord Me Mar 02 '15 at 09:10

1 Answers1

0

I found the answer myself, it turns out it is in this line of code:

S= abs(S(2:fftn*12000/Fs,:));

if I delete this line, the lines are placed on the right frequency in the figure. To me it looks like this line just takes a small space of the fft and replaces it with other frequencies but I'm not shure about that.

Lord Me
  • 11
  • 2