Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instananeous frequency sampling

Status
Not open for further replies.

JonnyMcK

Electrical
Jul 11, 2005
12
Hi,

I'm trying to sample the variation in frequency of an audio file using Matlab. Is it possible to break the audio file into a set number samples and construct an array containing the instantaneous frequency at each sample?

Thanks!
 
Replies continue below

Recommended for you

If you are trying to demodulate a signal, take a look at the hilbert() function. For example:

f=diff(unwrap(angle(hilbert(x))));

f is proportional to the instantaneous signal.


Alternatively, you could use specgram() to get a colormap of STFTs.
 
Yes. You may want to consider overlapped sample sets. I assume you already have your MATLAB frequency estimation algorithm that operates on a block of samples. You mentioned the instantaneous frequency "at each sample". That has the Hiesenberg uncertainty between frequency and time. But, if you extend the overlapped sample blocks all the way to only adding one new sample and removing one old sample, you would get a new frequency estimate for each sample point, but you would need a time aperture around that point to determine frequency.
i.e.
dataIn = rand( 128, 1 );

for iBlock = 1 : 127
fftDataSubBlock( :, iBlock ) = fft( dataIn( [ 0 : 7 ] + iBlock ) );
end

This would do a sliding block one sample at a time. If you can live with half overlapped blocks, you could step by 4, but you would not have a "new" frequency estimate for each sample, but only one for every 4 samples. You might want to look at the MATLAB Welch PSD method.
 
Just re-read my post and spotted an important missing word. It should have read:

If you are trying to demodulate a signal, take a look at the hilbert() function. For example:

f=diff(unwrap(angle(hilbert(x))));

f is proportional to the instantaneous frequency.
 
Define instantaneous?



Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Define instantaneous?

For a frequency modulated signal, the instantaneous frequency minus the carrier frequency stores the information. Doesn't work for broadband signals, but for signals with a dominant carrier (e.g. FM radio), it works well.

As an aside (and my primary interest), an inductive probe targetted at gear teeth has a carrier frequency (mean rotational speed multiplied by number of teeth) which is modulated by instantaneous rotational speed variations. Take the diff(unwrap(angle(hilbert()))) of it, filter out tooth-passing frequencies and you end up with a signal representing through-cycle speed variations. Pretty useful for gear rattle studies.

 
Sorry, I was getting at the Heisenberg limit. Instantaneous implies a very short sample time implies a very poor frequency resolution.

To give an example, suppose I use 4 samples,1,2,3,4 and get a peak frequency F14

Then I calculate the peak frequency for sample 2,3,4,5 and get peak frequency F25

and then calculate F36

What are the odds on F25 falling between F14 and F36?

If it doesn't, what on earth do you mean by an instantaneous frequency?


Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
I would define "instantaneous frequency" as the instantaneous rate of change of the phase of the analytic signal. And as I said previously, it only really makes sense if your signal is FM with a single carrier.
 
Hi again,

I've been using the Hilbert function as suggested by Sompting guy. There's something that I'm not sure about though, and I wonder if any of you can explain it.

If the instantaneous frequency is the time rate of change of the instantaneous phase angle of the Hilbert function, does this mean if the result is -ve that the instantaneous frequency is negative?

What exactly does it mean if a signal has an -ve instantaneous frequency?

Cheers,
Jonny
 
I think you may have been led up the garden path somewhat by some of the replies you have received. The term "instantaneous frequency" doesn't really have any meaning except in the specialised sense of a frequency modulated signal. The slope of the phase of the analytic signal is one way of estimating that parameter.

You, on the other hand, have a baseband audio signal (I assume) and for such a signal the concept of instantaneous frequency is meaningless which is why you are getting odd answers using the Hilbert transform approach.

M

--
Dr Michael F Platten
 
Have you tried an overlapped FFT method? This would give you a larger time aperture and thus a higher frequency resolution, and at the sam time give you freqeucny estimates more often.
To improve the resolution (not the accuracy) of the frequency estimate from the short term Fourier transform you could take the highest picket and the neighbor that is the second highest. Then using the voltage (NOT the power) you could linearly interpolate. This method is a zero bias estimator (which is good). This may do just what you need.
If it does not you could switch to a high resolution method. But those have problems and take more MIPS.
 
Spectrogram will solve your problem(dont remember the function name in matlab), I have some files in case u r interested.

Also, other Joint time frequency analysis tools which can be accessed at dsp.rice.edu would help too.
 
<quote>Then using the voltage (NOT the power) you could linearly interpolate.</quote>

I'm not sure exactly what exactly you mean by the voltage.
I know how to measure the amplitudes of the frequency components of a signal, but not as a function of time.

Would I be right in saying that by taking the STFT of a window of the sample you obtain the spectrum for that window. Then you use this spectrum to get an estimate of the frequency....if so, how?

Arrggh...! I think I've almost grasped this, but not quite well enough!
 
The STFT gives you an estimate of the frequency content of the signal over the length of the STFT window. If the frequency spacing of the spectral lines is df then it will tell you the how much of frequency 0 Hz, df Hz, 2*df Hz, 3*df Hz ... n*df Hz is present. The spectral line with the highest magnitude will be the dominant frequency in the STFT window.

There is no method which will give you (in your words) "an estimate of the frequency" because there will be many frequencies. As I said before, there is no such thing as "instantaneous frequency" except in the specialist sense of a Frequency Modulated signal.

M

--
Dr Michael F Platten
 
Thanks!

I've just about cracked it. I'm not sure I explained myself as clearly as possible, perhaps because I was a bit confused about it myself, but you guys have been a big help.

Thanks again!
 
Sorry, I am used to working in Volts as the units of amplitude.
You can increase the resolution of your estimated frequency by linearly interpolating between the highest amplitude picket and it's nearest amplitude neighbor.

To create an unbiased estimator do not use a window. Also, do not square the amplitudes out of the FFT.
The window can give you a visually pleasing plot, but will bias your estimate and can reduce the variance of your frequency estimate.

If you run your STFT on a sample by sample basis, that is highly overlapped, you will get what appears to be a high resolution in time and a high resolution in frequency estimate of the dominant frequency of your signal.

To test the bias of your estimator, and even the variance you could create a signal and add a small amount of noise. Choose a frequency that is exactly on a picket, then step your frequency for each run so that you get maybe 32 different frequencies between pickets. By subtracting the correct answer from your frequency estimate, you can draw a plot of error vs frequency. If this error curve is zero on average, you have an unbiased estimator. By making several runs using noise, you can determine a variance. You now have a method of comparing different estimator methods. I think you will find the method described above as having the lowest variance and unbiased of all linear methods you can try.
 
"You can increase the resolution of your estimated frequency by linearly interpolating between the highest amplitude picket and it's nearest amplitude neighbor. "

Well, that's a novel proposal.

So, if I take 1 second of data, normally I could hope for 1 Hz resolution, and depending on the hanning or whatever window, a slightly worse resolution (statistically) than that.

Are you saying I can get 0.5 Hz resolution meaningfully?


Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
You cannot break the Rayleigh resolution limit if there are two tones within your picket distance. However, you can reduce your error (as measured by variance) by using the interpolation method described.

A window will produce a bias in the estimate. That means that if you put in a tone at lets say 20.2 Hz in your 1 Hz picket spaced system you mentioned, you would measure 20.2 Hz on average in a non biased system. However, if you window the data (like with a von Hann window or anything other than a boxcar) the average estimate might be 20.25 Hz. The amount of "biased" error will be a function of the window you chose and of the distance, you are from a picket.
For instance, in a non windowed system and if you chose a privileged frequency right on a picket of let's say 20 Hz, you would have the nulls at all the other pickets and the linear interpolator would just estimate exactly 20 Hz. However, with a window, you could get non-zero amplitudes on your other pickets. Your bias error will be maximum on picket and minimum (zero) exactly between pickets (assuming your window is symmetric).

By the way, Mr. Hamming dislikes calling the Von Hann window the Hanning window. It may have to do with his Hamming window sounding like a verb or something.

Good luck. If your SNR is high you should be impressed by your improvement.
 
Ah, you are talking about single pure tone frequency identification, I think.

That may be an acceptable assumption to make in some circumstances, but if you can make that assumption you would probably be better off working in the time domain and counting how many cycles, and fractions thereof, you get.

At a practical level I would never be allowed to make that assumption. For instance any heterodyning effect (two very close tones) will throw you right off.


Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
You are correct. The system I explained only works well when modulations or other signals are 10 dB or more down depending on distance. If your second signal is more than one pciket away, you can still use this method. If you have the freedom, you would determine how close your second tone might be, then choose your number of data points to make tht second tone be more than a picket away. If you are within a picket, a window would blur your ability to sepeate them even more.

If you have the possibility of two tones within the Rayleigh limit, then you would want to look at the high resolution methods like MUSIC and such.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor