How can I find phase angle for chosen frequency?

6 ビュー (過去 30 日間)
Jakub Panuska
Jakub Panuska 2016 年 2 月 18 日
コメント済み: Star Strider 2016 年 2 月 22 日
Hi everyone.
I am new in matlab so maybe my question is stupid. I have a two signals rec(t) and sent(t) for which I want to find time delay through phase vs. frequency realtionship obtained from cross spectrum. I obtained cross spectrum through the FFT of the cross corelation between rec(t) and sent(t). Here it is:
time=data(15:length(data),1); %time of measurement - s
sent=data(15:length(data),2); %sent signal - mV
rec=data(15:length(data),3); %recorded signal - mV
samples=length(time); %number of samples
Fs=samples/max(time); %sampling frequency - Hz
dt=max(time)/samples; %time interval - s
freq=(0:samples/2)/samples/dt; %frequency scale for FFT
FFTrec=fft(rec); %FFT of recorded signal
FFTsent=fft(sent); %FFT of sent signal
CorrRecSent=(ifft(FFTrec.*conj(FFTsent))); %cross correlation definition
CS=fft(CorrRecSent); %cross spectrum (CS)
amp=abs(CS); %amplitude of CS
amp1=amp(1:samples/2+1); %amplitude of CS for half of the frequency spectrum
A2=angle(CS);
A1=A2(1:samples/2+1); %phase angle of (CS)
A=unwrap(A1); %unwrapped phase
plot(freq,(A));
xlabel('frequency (Hz)')
ylabel('phase (rad)')
And here is the plot. Is there any command or procedure how can I obtain exact phase angles for given frequencies (marked with black line)? Or how can I find the slope of the drawn orange line? I chose this range of frequencies because my sent signal was 5 kHz, so something around was chosen.
Thanks for help.

採用された回答

Star Strider
Star Strider 2016 年 2 月 18 日
I don’t have your data, but I would do something like this:
idxrng = find( (freq >= 2000) & (freq <= 10000));
b = polyfit(freq(idxrng), A(idxrng), 1);
A_4_8 = polyval(b, [4000 8000]);
That should return the estimated phase angles for 4000 and 8000 Hz in ‘A_4_8’.
Note: This is UNTESTED CODE but it should work.
  4 件のコメント
Jakub Panuska
Jakub Panuska 2016 年 2 月 22 日
yes a i checked it...big thanks to you!!! you learn me new things in matlab:)
Star Strider
Star Strider 2016 年 2 月 22 日
As always, my pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by