0
votes

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.

enter image description here

Thanks for help.

1

1 Answers

0
votes

In the plot, you are setting freq as your x-axis vector, and A as your y-axis vector.

If you want to know the slope of the orange line, you first need to know the index where 4000Hz and 8000Hz is:

f1 = find(freq==4000);
f2 = find(freq==8000);

Then you can check which is the phase in this two points:

p1 = A(f1);
p2 = A(f2);

Finally the slope will be deltaX / deltaY:

slope = (f2-f1)/(p2-p1);