Frequency Transform : Fundametal Concept - signal-processing

I was going thru this book to understand wavelets. Its a beautifully written not much technical document.
web.iitd.ac.in/~sumeet/WaveletTutorial.pdf
But in its very first chapter it describes below figure with explanation:
The frequency is measured in cycles/second, or with a more common
name, in "Hertz". For example the electric power we use in our daily
life in the US is 60 Hz (50 Hz elsewhere in the world). This means
that if you try to plot the electric current, it will be a sine wave
passing through the same point 50 times in 1 second. Now, look at the
following figures. The first one is a sine wave at 3 Hz, the second
one at 10 Hz, and the third one at 50 Hz. Compare them
But I am unable to understand what X and Y axis values represents. The X values range is in between [1,-1] so I am assuming it is value of the signal while Y axis is representing the time in milliseconds (1000ms = 1 sec). But then the document goes on further to state the representation of same signal in frequency-amplitude domain:
So how do we measure frequency, or how do we find the frequency
content of a signal? The answer is FOURIER TRANSFORM (FT). If the FT
of a signal in time domain is taken, the frequency-amplitude
representation of that signal is obtained. In other words, we now have
a plot with one axis being the frequency and the other being the
amplitude. This plot tells us how much of each frequency exists in our
signal.
But I am not able to understand what does in the upper graph X and Y axis values represents - shouldn't is be Frequency (X Axis) and Amplitude (Y axis) - if I am correct then why does Y axis has values ranked as 0,200 and 400 - shouldn't it be between range [1,-1] or rather [0,1]?

For the time domain signals the X axis is time and the Y axis is amplitude.
For the frequency domain equivalents the X axis is frequency and the Y axis is magnitude.
Note that when using most FFTs there is a scaling factor of N, where N is the number of points, so the magnitude values in the frequency domain plots are much greater than amplitude of the original time domain signal.

As Paul R wrote above, in the first image the horizontal X-axis represents time with the units ms.
The time interval has the length 1000ms.
The vertical Y-axis represents the amplitude of the signal. However, in the diagram the unit is not Volt, but it is normalized to amplitude 1.
If you perform a Fourier Transformation on that time signal, you will get a frequency spectrum.
If you use a DFT (Discrete Fourier Transformation) or a FFT (Fast Fourier Transformation),
the result depends on the implementation of the algorithm.
a) If the algorithm delivers a normalized result, the amplitude of your frequency line is 0.5 (if the amplitude of your input signal is 1).
b) If the algorithm delivers a non normalized result, the amplitude of your frequency line is half the value of the number of DFT/FFT input values.
Your frequency line has the value of 500, which means the algorithm does not use normalization and the number of input samples was 1000.
Now, what is represented by the horizontal X-axes in the frequency domain?
In the time domain, the length of your time input interval is T = 1000ms = 1s.
Therefore the distance between the frequency lines in the frequency domain is df = 1/s = 1Hz.
As we know from the amplitude in the frequency domain, the input signal in time domain had 1000 samples. This means the sampling time was dt = T/1000 = 1s/1000 = 1ms.
Therefore the total frequency interval F = (fmin, ..., fmax) in frequency domain is 1/dt = 1/1ms = 1kHz.
However, the range does NOT start at fmin = 0 Hz and ends at 1kHz, as one could assume inspecting the upper diagram in the second image. The spectrum calculated by a DFT/FFT contains a positive and a negative frequency range. This means you get a frequency range: (-500Hz, -499Hz, -498Hz, ... -1Hz, 0Hz, 1Hz, 2Hz, ..., 498Hz, 499Hz). The value 500Hz does not exist!
However, for the user's convenience the spectrum is not output in this order, but it is shifted by 500Hz (F/2). This means the spectrum starts with the DC value:
0Hz, 1Hz, 2Hz, ..., 498Hz, 499Hz, -500Hz, -499Hz, -498Hz, ..., -2Hz, -1HZ.
Because the spectrum of a real input function is hermitian Y(f) == Y(-f)*, the positive band carries the complete information. So, you can cut off the negative side band.
The upper diagram in the second image shows two peaks. The first peak appears at f = 50Hz and the second peak is shown at f=950Hz. However, this is not correct. The labels of the horizontal axes are wrong. The second peak appears at f = -50Hz.
In the lower diagram the frequency range ends at 500Hz (499Hz would be correct)a). The range of the negative frequencies is cut off.

Related

How to convert time bins in spectrogram to real time?

I have an output of a spectrogram with the shape of (8193, 2110). This means that I have 2110 time frames and 8193 frequency bins. I want to convert time bins to real time. This spectrogram is related to a one day long file, so instead on time frame I need the exact real time like : 12:32:45.
A single FFT in your spectrogram represents a time window of duration T = N / Fs, where N = FFT size and Fs = sample rate. If you have no overlap between successive FFTs then the i’th FFT represents a time window of duration T, starting at time i*T.
If you have overlap between successive FFTs, e.g. k = 0.5 (50% overlap), then i*T obviously becomes (1-k)*i*T.

Strange FFT spectrum from a near perfect sinusoid

I have retrieved some signal in my Abaqus simulation for verification purpose. The true signal shall be a perfect sinusoid at 300kHz and I performed fft on the sampled signal using scipy.fftpack.fft.
But I got a strange spectrum as shown below (sorry that I am too lazy to scale the x-axis of the spectrum to the correct frequency). In the same figure, I sliced the signal into pieces and plotted in the time domain. I also repeated the same process for a pure sine wave.
This totally surprises me. As indicated below in the code, sampling frequency is 16.66x of the frequency of the signal. At the moment, I think it is due to the very little error in the sampling period. In theory, Abaqus shall sample it in a regular time interval. As you can see, there is some little error so that the dots in my signal appear to be thicker than the perfect signal. But does such a small error give a striking difference in the frequency spectrum? Otherwise, why is the frequency spectrum like that?
FYI1: This is the magnified fft spectrum of my signal:
FYI2: This is the python code that was used to produce the above figures
def myfft(x, k, label):
plt.plot(np.abs(fft(x))[0:k], label = label)
plt.legend()
plt.subplot(4,1,1)
for i in range(149800//200):
plt.plot(mysignal[200*i:200*(i+1)], 'bo')
plt.subplot(4,1,2)
myfft(mysignal,150000//2, 'fft of my signal')
plt.subplot(4,1,3)
[Fs,f, sample] = [5e6,300000, 150000]
x = np.arange(sample)
y = np.sin(2 * np.pi * f * x / Fs)
for i in range(149800//200):
plt.plot(y[200*i:200*(i+1)], 'bo')
plt.subplot(4,1,4)
myfft(y,150000//2, 'fft of a perfect signal')
plt.subplots_adjust(top = 2, right = 2)
FYI3: Here is my signal in .npy and .txt format. The signal is pretty long. It has 150001 points. The .txt one is the raw file from Abaqus. The .npy format is what I used to produce the above plot - (1) the time vector is removed and (2) the data is in half precision and normalized.
Any standard FFT algorithm you use operates on the assumption that the signal you provide is uniformly sampled. Uniform in this context means equally spaced in time. Your signal is clearly not uniformly sampled, therefore the FFT does not "see" a perfect sine but a distorted version. As a consequence you see all these additional spectral components the FFT computes to map your distorted signal to the frequency domain. You have two options now. Resample your signal i.e. it is uniformly sampled and use your off the shelf FFT or take a non-uniform FFT to get your spectrum. Here is one library you could use to calculate your non-uniform FFT.

Cepstrum analysis: how to find quefrency step?

I'm newbie in cepstrum analysis. So that's the question.
I have signal with the length 4096 and sample rate 8000 Hz. I make FFT and get the array with the length 4096*2 (2*i position is for cosinus coeff, 2*i+1 position is for sinus coeff). Frequency step is (sampleRate/signalLength == 8000/4096). So, I can calculate frequency at i position this way: i*sampleRate/signalLength.
Then, I make the cepstrum transformation. I can't understand how to find quefrency step and how to find frequency for given quefrency.
The bin number of an FFT result is inversely proportional to the length of the period of a sinusoidal component in the time domain. The bin number of a quefrency result is also inversely proportional to the distance between partials in a series of overtones in the frequency domain (this distance often the same as a root or fundamental pitch). Thus quefrency bin number would be proportional to period or repeat lag (autocorrelation peak) of a harmonically rich periodic signal in the time domain.

what is the PSD unit by using FFT method

I'm just doing a power spectral density analysis of a signal in time domain. I'm following the fft method described in :
http://www.mathworks.com/support/tech-notes/1700/1702.html
It gives the real physical unit for the PSD. However, the unit is "power", is that mean "V^2/Hz"?
If I take 10*log10(power) or 10*log10(V^2/Hz), do I get the unit of "dB/Hz"?
Then how can I convert it to dBm/MHz?
It depends on the unit of your timeseries. Often we think of this as just "amplitude", but if your timeseries is a series of voltage amplitude vs. time, then your PSD estimate will be Volts^2/Hz. This is because the PSD is the Fourier Transform of the autocorrelation of your original signal: The autocorrelation has units of Volts^2, and running it through the Fourier Transform decomposes these units over frequency, instead of time, resulting in units of Volts^2/Hz. This is commonly referred to as Watts/Hz, but the conversion from Volts^2 to Watts is not very physically meaningful, as W = V^2/R.
10*log10(power) will result in a unit of dB/Hz, but remember that decibels are always a comparison between two power levels; you are quantifying a ratio of powers. A better definition of decibels is 10*log10(P1/P0), as explained here. If you simply plug a PSD bin estimate into this equation, you are setting your PSD bin to P1 and implicitly comparing it to a P0 value of 1. This may be what you want, and it may not be. For visualization purposes, this is fairly typical, but if you have a standard reference power you should be comparing to, you should use that for P0 instead.
Assuming that you are attempting to plot a dB Power Spectral Density estimate, to convert from Hz to MHz, you simple rescale the x-axis of your frequency graph. Remember that a MHz is just 1 million Hz, so the only difference is that 240000Hz = 0.24MHz
EDIT
The point brought up by mtrw is a very valid one; if you are dealing with large amounts of data and are averaging FFT vectors, I highly suggest the Multitaper method; it's a much more statistically sound method of sacrificing frequency resolution for greater confidence on your PSD estimate.
If you have a PSD in W/Hz i.e. 100 W/Hz then you have 50 dBm/Hz. dB/Hz or is often vaguely and generically used instead of dBm/Hz. Audacity uses dB as shorthand for dBFS (not dBFS/Hz, because it is computing a DFT, and discrete frequencies use a power spectrum and not a density) . A digital signal that reaches 50% of the maximum level has an amplitude of −6 dBFS, which is 6 dB below full scale – the removal of the MSB, hence the 6dB/bit figure (because 50% of maximum level is 25% of maximum power; 1/4 = - 6dB)
dBm is the logarithmic ratio of the power with respect to 1mW, you divide the power by 1mW to get a unitless ratio, and then take the logarithm to get dB units, which in this case makes more sense to be clarified as dBm.
dBc/Hz is the ratio with respect to the carrier power, which is a ratio of two dBm/Hz values, meaning you subtract them and you get dBc/Hz; you get the same result if you divide the two linear power levels in W and then convert the ratio to dB (or more appropriately dBc).
dB-Hz is a logarithmic measure of bandwidth with respect to 1Hz and
dBJ is a measure of spectral density as a logarithmic ratio to 1 joule, seeing as W/Hz is indeed J.
Power spectral density is a density function, so you need to integrate it to get the actual quantity, like a line Integral of a V/m electric field, or a probability density of probability per x. This does not make sense for discrete quantities and instead the power spectrum is used akin to a probability mass function. If you see dB (which should be used for the discrete frequency domain) instead of dBm/Hz then it's wrong, but if you see it instead of dBm then it's right, as long as it's made clear what the reference is.

DFT frequency subtraction

If the maximum magnitude M = A^2 + B^2 of DFT transform corresponds to the frequency F,
(A - real, B - imaginary output of DFT, at frequency F)
then is it correct to do the following:
for (j = 0; j < size; ++j) {
data[j] -= (A*cos(2*PI*F*j/dfts) -
B*sin(2*PI*F*j/dfts)) / dfts;
}
In order to cancel (subtract) that frequency influence from original wave data?
The data is assumed to be a sum of several sines and cosines with different frequencies and multiplied by different coeffitients.
EDIT1:
I could achieve the cancelation by subtracting, and the result is correct. There was a mistake in above, but it is possible to do it. If interested I can post the way of doing it.
EDIT2:
And if you do the next DFT transform, you will get a very small, near zero value at the A and B values.
But you need to remember, that the original data can be the sum of 4 frequencies (sines and cosines) but the DFT transform will give you as much as the size of DFT is divided by 2.
No - that won't work. It could only work if the time domain component matched the FFT bin frequency exactly and the phase of the component is constant throughout the sample window, and even if this were the case you'd still need to take care of phase in your subtraction.
Ideally you need to remove (i.e. zero) the component in the frequency domain and then do an inverse FFT. Note that you probably don't want to just zero the bin of interest in the frequency domain, as this will produce artefacts in the time domain after you inverse FFT - you'll need to apply a window function to the bin of interest and adjacent bins.

Resources