How can I find phase angle for chosen frequency?
10 views (last 30 days)
Show older comments
Jakub Panuska
on 18 Feb 2016
Commented: Star Strider
on 22 Feb 2016
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.
0 Comments
Accepted Answer
Star Strider
on 18 Feb 2016
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 Comments
More Answers (0)
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!