Instananeous frequency sampling
Instananeous frequency sampling
(OP)
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!
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!





RE: Instananeous frequency sampling
f=diff(unwrap(angle(hilbert(x))));
f is proportional to the instantaneous signal.
Alternatively, you could use specgram() to get a colormap of STFTs.
RE: Instananeous frequency sampling
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.
RE: Instananeous frequency sampling
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.
RE: Instananeous frequency sampling
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: Instananeous frequency sampling
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.
RE: Instananeous frequency sampling
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.
RE: Instananeous frequency sampling
RE: Instananeous frequency sampling
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
RE: Instananeous frequency sampling
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
RE: Instananeous frequency sampling
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.
RE: Instananeous frequency sampling
Also, other Joint time frequency analysis tools which can be accessed at dsp.rice.edu would help too.
RE: Instananeous frequency sampling
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!
RE: Instananeous frequency sampling
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
RE: Instananeous frequency sampling
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!
RE: Instananeous frequency sampling
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.
RE: Instananeous frequency sampling
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.
RE: Instananeous frequency sampling
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.
RE: Instananeous frequency sampling
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.
RE: Instananeous frequency sampling
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.