0
$\begingroup$

I'm tring to code a STFT program in Matlab. I got results but I'm confused a bit. I have a audio signal of 900000 pts sampled at 1000Hz (15 min signal). I've taken fft with following parameters =>

  • hop size of H = 1400 pts
  • the window length M = H * 6

So, 5/6 of the window overlaps with the next one. The program runs for 637 iterations, as (637*1400 + M = 900200)

Now, I get a 637 pt vector with frequency in them. I should get a frequency vs time plot. But it only has 637 frequency bins, for a signal of 900000 time sample.

  1. How, can I find the change of frequency with Time (900000 sample) or 15 min?
  2. Moreover, how does changing the window length and overlap affect the outcome of STFT? The code is below.

%hop size
L = 1400;

%window length & Formation
D = 6;                        %User Defined Parameter in Cooper's paper 
M = L*D;                             
w = hanning(M, 'periodic');    %window formation

k = 1; % k =index
j = 1; % j =result vector index  
while k + M <= xlen

  %data chunk
  %x = x(k:1400);

  %window length & Window
  xw = x(k+1:k+M) .*w;                  %windowed signal

  %zero padding
  b = 5;                           %Zero Padding Factor 'b'
  xw = [xw; zeros(M*5,1)];
  [nft,c] = size(xw);

  %plot(abs(fft(xw)))
  X = abs(fft(xw));
  XF = X(1:length(X)/2);
  [q,ind] = max(XF);
  v(j) = ((fs/2)/(nft/2)) * (ind-1);  %convert Bin to frequency 
  k = k+L;
  j = j+1;
end

figure(1);
plot(v)
axis([0 1400 0 100])

figure(2);   %zoom version
plot(v)
$\endgroup$
3
  • $\begingroup$ Are you saying M = H * 6 = 1400 * 6 ? It's not clear from what you've written. If that's true, then your overlap is 5/6, not 1/6? Each FFT should return a vector of length M. So you should have a $637 \times M$ matrix at the end of it. $\endgroup$
    – Peter K.
    Nov 20, 2015 at 15:07
  • $\begingroup$ Oh, sorry about that. I fixed it in the question to 5/6. I'm fairly new. What I'm trying to do, is to mimick the built-in "spectrogram" function of Matlab without the color. The spectrogram function fails to detect slight change of frequency. I want to find out the change of frequency with respect to time. I don't have 637 x M matrix, because I converted each fft frame and took the frequency bin corresponding maximum amplitude, with formula v(j) = ( (fs/2) / (nft/2) ) * (index of freq correspond ot max amplitude) and save in a vector. I've attached the related code in the question now. $\endgroup$
    – Rio1210
    Nov 20, 2015 at 15:25
  • $\begingroup$ Let us continue this discussion in chat. $\endgroup$
    – Rio1210
    Nov 20, 2015 at 16:50

2 Answers 2

1
$\begingroup$

How, can I find the change of frequency with Time (900000 sample) or 15 min?

OK, so you need 900000 frequencies. Well, one way to do that is to take each element of your 637 length vector and expand it to (up to) $H$ samples.

Moreover, how does changing the window length and overlap affect the outcome of STFT?

The longer the window length, the better the frequency resolution is. The shorter the length, the worse the frequency resolution will be.

Before we can answer your question, we will need to know what form your signal takes.

If it's a single tone in noise, then you may be able to use one of these or one of these or this approach.

$\endgroup$
6
  • $\begingroup$ I have two types of signals. 1. Electrical Network signals with constant 60Hz (+/- 0.5Hz). And the other is audio recording with the power-line interference of that particular Electric network. The audio is recorded in a silent room. So, I'm passing the audio recording through a bandpass filter of 59.5 to 60.5 Hz and trying to do STFT of both the signals and match them. Fs=1000Hz $\endgroup$
    – Rio1210
    Nov 20, 2015 at 17:35
  • $\begingroup$ OK, then the FFT will not give you a very precise measurement of that mains frequency. $\endgroup$
    – Peter K.
    Nov 20, 2015 at 17:43
  • $\begingroup$ Thanks for your help so far. So, what should be my course of action. I have 9 different Mains signal, and 2 audio signals. I have to find out which mains signal is embedded in the audio recordings of the nine total. $\endgroup$
    – Rio1210
    Nov 20, 2015 at 18:28
  • $\begingroup$ If you are trying to match time domain signals, wouldn't cross correlation be a better way to test for degree of match? $\endgroup$
    – hotpaw2
    Nov 20, 2015 at 18:55
  • $\begingroup$ I'm not trying to match time domain signals. Every power-station has distinct frequency variation (ENF=electrical network frequency). This frequency variation can also be found in audio/video recordings, recorded in close proximity to any socket, appliances etc taking power from that grid. So, I'm trying to match this unique frequency fluctuation of a grid signal to a recorded signal to cerify if the data was recorded in that grid or not. thanks :) $\endgroup$
    – Rio1210
    Nov 20, 2015 at 19:08
0
$\begingroup$

You could interpolate your low sample rate of STFT results (1/1.4 Hz) to the higher sample rate (1 kHz).

$\endgroup$
2
  • $\begingroup$ I'm still a neophyte. Could you clarify it further. I'm following a research-paper and they also suggest doing a QIFFT; FFT and Quadratic Interpolation of the bins right after & before the frequency bin corresponding to the max-amplitude. thanks a lot. $\endgroup$
    – Rio1210
    Nov 20, 2015 at 19:12
  • $\begingroup$ See Peter K's answer for better interpolation methods than parabolic. But all these methods require a signal to be stationary across the FFT frame. $\endgroup$
    – hotpaw2
    Nov 20, 2015 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.