DSPRelated.com
Forums

Amplitude & Phase Determination

Started by Parlous July 8, 2010
Suppose one generates a sine or cosine wave in discrete domain.
Suppose we are using floating-point numbers for the amplitude values
between -1 and 1. Suppose we generate 2048 consecutive samples at
44100Hz sampling rate. Now compute a FFT on those 2048 samples with
rectangular window (ie - do nothing else to the samples but put them
in DFT). Here is some MATLAB code:

x = 0:2047;    % time-domain
F = 82.407;    % hertz
p = pi/4;        % phase
y = sin(2*pi*F .* x/44100 + p);
f = fft(y);

Now in this example, the amplitude is 1. Since the chosen frequency
(82.407) is not one of the exact frequency bins, how does one
ascertain what p is if one knows the frequency and has the FFT data
only? Utilizing atan(imag(f1) ./ real(f1)) doesn't seem to help
much...

Now assume y is as follows:

a = rand(1,1);
y = a * sin(2*pi*F .* x/44100 + p);
f = fft(y);

Given only the frequency (F) and FFT data (f), how would one determine
both the phase (p) and amplitude (a)?

Thanks
On Jul 8, 2:46&#4294967295;pm, Parlous <parlous2...@gmail.com> wrote:
> Suppose one generates a sine or cosine wave in discrete domain. > Suppose we are using floating-point numbers for the amplitude values > between -1 and 1. Suppose we generate 2048 consecutive samples at > 44100Hz sampling rate. Now compute a FFT on those 2048 samples with > rectangular window (ie - do nothing else to the samples but put them > in DFT). Here is some MATLAB code: > > x = 0:2047; &#4294967295; &#4294967295;% time-domain > F = 82.407; &#4294967295; &#4294967295;% hertz > p = pi/4; &#4294967295; &#4294967295; &#4294967295; &#4294967295;% phase > y = sin(2*pi*F .* x/44100 + p); > f = fft(y); > > Now in this example, the amplitude is 1. Since the chosen frequency > (82.407) is not one of the exact frequency bins, how does one > ascertain what p is if one knows the frequency and has the FFT data > only? Utilizing atan(imag(f1) ./ real(f1)) doesn't seem to help > much... > > Now assume y is as follows: > > a = rand(1,1); > y = a * sin(2*pi*F .* x/44100 + p); > f = fft(y); > > Given only the frequency (F) and FFT data (f), how would one determine > both the phase (p) and amplitude (a)?
well, since you are given the exact frequency, you *could* inverse FFT to retreive y and cross-correlate that with u = exp(-j*2*pi*F .* x/44100); what do you think that z = mean(u .* y) is equal to? specifically, what is abs(z) and angle(z)? if you want to do this in the frequency domain, consider first windowing effects and then we'll talk about it. r b-j
On Jul 8, 2:46&#4294967295;pm, Parlous <parlous2...@gmail.com> wrote:
> Suppose one generates a sine or cosine wave in discrete domain. > Suppose we are using floating-point numbers for the amplitude values > between -1 and 1. Suppose we generate 2048 consecutive samples at > 44100Hz sampling rate. Now compute a FFT on those 2048 samples with > rectangular window (ie - do nothing else to the samples but put them > in DFT). Here is some MATLAB code: > > x = 0:2047; &#4294967295; &#4294967295;% time-domain > F = 82.407; &#4294967295; &#4294967295;% hertz > p = pi/4; &#4294967295; &#4294967295; &#4294967295; &#4294967295;% phase > y = sin(2*pi*F .* x/44100 + p); > f = fft(y); > > Now in this example, the amplitude is 1. Since the chosen frequency > (82.407) is not one of the exact frequency bins, how does one > ascertain what p is if one knows the frequency and has the FFT data > only? Utilizing atan(imag(f1) ./ real(f1)) doesn't seem to help > much... > > Now assume y is as follows: > > a = rand(1,1); > y = a * sin(2*pi*F .* x/44100 + p); > f = fft(y); > > Given only the frequency (F) and FFT data (f), how would one determine > both the phase (p) and amplitude (a)? > > Thanks
I'm glad you understand the "leakage" problem as that really screws up the phase estimate when your frequency is not exactly in a bin. If you know the freq. apriori, then simply take your time domain version of the signal and project it (in a vector sense via an inner product) onto both a sine and a cosine of the apriori freq. Then your simple 4 quadrant atan will give you the phase. And if your bases are normalized, then your amplitude is a sqrt of the sums of the squares of the two projection coefs. I will note that these results are not exact but are much better than what you got from the FFT data. At least we are now projecting the data onto vectors of the correct frequency. As your data's length increases the errors caused by the partial cycle portion of the data become less and less. If you want exact formulations, they are possible, but take a little more work. IHTH, Clay
Thanks for the suggestions. Would it be possible to figure out the
phase and amplitude without having to use each of the time-domain or
FFT values? I know this is impossible with just one complex bin (both
real and imaginary values at a bin). I tried to see what would happen
if you watched one bin as one went through each amplitude and phase
combination and it is a wave with increasing amplitude - not a 1 to 1
relationship for amplitude/phase combination. It would be ideal if I
could figure this out with only a subset of the FFT values. It sounds
strange, but I won't have access to any time-domain data - only FFT.
Anymore ideas? Thanks again...
I think I should clarify my last post and overall problem. I actually
only have access to a few random bins, I don't even have the complete
FFT. I do have both the real and imaginary components to these random
bins. If the bins are non-zero, I will know the frequency that
generates them. I'd like to reconstruct the rest of the FFT. I'm
considering just extrapolation. However, if I could ascertain the
amplitude and phase of this known frequency, I could generate the rest
of the FFT bins. Its not possible to do so with one bin but what about
others? Would you need the entire FFT?
On Jul 8, 3:11&#4294967295;pm, Parlous <parlous2...@gmail.com> wrote:
> Thanks for the suggestions. Would it be possible to figure out the > phase and amplitude without having to use each of the time-domain or > FFT values? I know this is impossible with just one complex bin (both > real and imaginary values at a bin). I tried to see what would happen > if you watched one bin as one went through each amplitude and phase > combination and it is a wave with increasing amplitude - not a 1 to 1 > relationship for amplitude/phase combination. It would be ideal if I > could figure this out with only a subset of the FFT values. It sounds > strange, but I won't have access to any time-domain data - only FFT. > Anymore ideas? Thanks again...
i am changing your "x" to "t" (as a better choice of symbol). and your "F" to "f0", which is a known number. and i am assigning 44100 to "Fs". correlating with exp((-j*2*pi*f0/Fs)*t) is the same as convolving with exp((+j*2*pi*f0/Fs)*t) since the convolving by exp((+j*2*pi*f0/Fs)*t) in the time-domain is the same as multiplying by delta(f-f0/Fs) in the frequency domain, then you *can* do this in the frequency domain by simply sampling the *proper* spectrum at f0/Fs. if that lies between FFT bins, you might have to do some interpolation in the frequency domain. but the first thing you need to worry about is the spectral leakage caused by your nasty rectangular window. you need to window this better before you FFT. r b-j
On Jul 8, 3:18=A0pm, Parlous <parlous2...@gmail.com> wrote:
> I think I should clarify my last post and overall problem. I actually > only have access to a few random bins, I don't even have the complete > FFT. I do have both the real and imaginary components to these random > bins. If the bins are non-zero, I will know the frequency that > generates them. I'd like to reconstruct the rest of the FFT. I'm > considering just extrapolation. However, if I could ascertain the > amplitude and phase of this known frequency, I could generate the rest > of the FFT bins. Its not possible to do so with one bin but what about > others? Would you need the entire FFT?
Few random bins? I would at least hope you have the ones nearest your frequency of interest. Can you change your FFT length so as to make your frequency of interest fall on or very close to a bin? Sounds like you have an ill defined problem. Clay
I think I have an answer, at least a preliminary one. Lets iterate
through the combinations of amplitude and phase, within numerical
abilities. Lets number each combination 1, 2, 3, ... such that 1 might
be (0.00001, -pi), 2 be (0.00002, -pi + pi/100000), and etc,
proceeding in a linearly increasing fashion. For each combination, we
generate a time-domain wave at some known frequency and run the FFT on
it (rectangular window). Now suppose we only record the values of one
bin. For my previous examples of 82.407, bins 4, 5 or 6 would be fine
as they have a lot of "energy". Any one of them will be fine. Now,
what would you see? If you looked at just the real or just the
imaginary, you would see another wave that grows linearly, as the
combinations do. If you had to use just that one wave to determine
what combination generated it you couldn't do it. This is because it
would fail the horizontal line test (not injective). However, if you
look at both domains (real & imag) for each combination, you would see
the same kind of wave pattern, just "out of phase" (as you typically
see) but there is an added advantage. If you consider both domains'
values as a "key" to the combination that generated them, I **think**
they're one-to-one. Think about it - if they're both the same
frequency (NOT the frequency I choose btw) and increasing by the same
amount linear amount, but one is "lagging" behind the other, than
they're constantly going to be different values when one considers
BOTH their values simultaneously as a "key" (like a key in a
database).

Does this make sense? I can provide some source code if need be. If
this is true, then I should be able to come up with some formulas to
describe this, or at least model it, for my application :). Thank you
again for your wonderful suggestions...
oops, I incremented the combinations wrong in my example. It should be
something like this:

Combination    (Amp, Phase)
1                    (0.01, -pi)
2                    (0.01, -pi + phaseIncrement)
3                    (0.01, -pi + 2*phaseIncrement)
4                    (0.01, -pi + 3*phaseIncrement)
....
N                    (0.01, -pi + K*phaseIncrement)  << here -pi +
K*phaseIncrement = pi
N + 1              (0.02, -pi)
N + 2              (0.02, -pi + phaseIncrement)
....
ad infinitum...
This posses another unusual problem - how does one choose the
appropriate increment for the amplitude and phase? One can think of
each like a "counter", just like digits in a counting system.
Theoretically, considering these particular "counters" are derived
from a continuous domain, one has to wonder how can to seemingly
infinitely dense segments [0, 1] and [-pi, pi] could be counters? Its
like infinity times infinity number of combinations!! Well, the
computer is obviously limited but I don't think that I need to even go
that far, to push the limits of floating-point numbers. From my MATLAB
experiments an amplitude increment of 0.0001 and phase increment of
2*pi/100 are just fine. Its an interesting theoretical question though
- would the real and imaginary values considered as one "value" or
"key" together be unique for the possible amplitude and phase
combinations, if one made an "ordered set" of such combinations?
Again, this is all assume ONE generated, known frequency into the FFT.