Incorrect phase from fourier transform
Afficher commentaires plus anciens
Hi,
- I make a few sinusoids of different frequencies with different phase offsets.
- Add them to make a waveform
- Fast Fourier Transform.
- Then get the phase from the complex number given by the FFT - but it doesn't always match the phase that it originally had...why?
- Code below with a plot - Its annotated well and outputs the phases
clear all
freq_range = (3:5)
Fs =10*max(freq_range);
Ts = 1/Fs;
end_time = 5;
n = 0 : Ts : end_time-Ts;
%Make the number of waves in the frequency range
for a = 1:length(freq_range)
random_phase(a) = 2*pi*rand(1,1);
y(a,:) = cos(2*pi .* freq_range(a) .* n + random_phase(a)) ; %Polar form
end
%Sum all the waves together to make a waveform
waveform = sum(y);
%Setup Fast Fourier Transform
N=length(n);
freq_domain = (0:N/2); %Show positive frequency only
freq_domain = freq_domain * Fs / N;
%Fast Fourier Transform
ft = fft(waveform)/N;
ft_spectrum = 2*abs(ft); %2* to compensate for negative frequency
ft_spectrum = ft_spectrum(1:N/2+1); %Show positive Frequency Only
ft_phase = angle(ft(1:N/2+1));
%Get Phase
Bins_per_freq= (N/Fs);
freq_bins = Bins_per_freq * (freq_range) +1; %Domain starts at 0, so add 1
random_phase %The phase offset the cosine waves orignally had
phase = angle(ft(freq_bins)) %The Phase from the fft
%They do not match... but sometimes they do... why?
figure(1);
subplot(3,1,1);plot(n,waveform);title('Time Domain Signal');
subplot(3,1,2);plot(freq_domain,ft_spectrum);title('Frequency Domain');
subplot(3,1,3);plot(freq_domain,ft_phase);title('Phase on Frequency Domain');
Réponse acceptée
Plus de réponses (1)
Nathan Kennedy
le 18 Avr 2018
Modifié(e) : Nathan Kennedy
le 18 Avr 2018
0 votes
Catégories
En savoir plus sur Matched Filter and Ambiguity Function dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!