From: Parlous on
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
From: robert bristow-johnson on
On Jul 8, 2:46 pm, Parlous <parlous2...(a)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;    % 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)?

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

From: Clay on
On Jul 8, 2:46 pm, Parlous <parlous2...(a)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;    % 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

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
From: Parlous on
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...
From: Parlous on
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?