How to create a delayed version of a cosine signal?

조회 수: 25 (최근 30일)
Varun
Varun 2014년 7월 24일
댓글: Varun 2014년 7월 25일
I have defined a cosine signal with 100 Hz frequency using the code:
st=1/1000; % sampling frequency Fs=1000;
t=[0:999]*st;
cos(2*pi*100*t);
I want to create a second cosine signal of the same frequency and length but with a time delay of 0.0050 seconds. I tried creating a separate vector and using that time vector to define the signal.
t1=[50:1049]*st;
cos(2*pi*100*t1)
But when I use the cross correlation function to verify the delay between the signals it shows that the delay is zero.
Please help me out here. Thank you

답변 (2개)

Andrew Reibold
Andrew Reibold 2014년 7월 24일
Your second cosine function definitely IS shifting. Its just that you are shifting it over exactly 5 periods, so it lies on top of itself again.
I'm not sure which cross correlation function you are talking about, but perhaps it only only looks at delay between overlapping periods, in your case which may be 0. Does that make sense?
  댓글 수: 2
Andrew Reibold
Andrew Reibold 2014년 7월 24일
PS. You can verify it is shifting visually with a simple plot :)
figure;
plot(t,cos(2*pi*100*t),t1,cos(2*pi*100*t));
Varun
Varun 2014년 7월 25일
if s1 is the first signal and the s2 is the delayed signal then:
[c,lag]=xcorr(s1,s2);
[~,I] = max(abs(c));
T = lag(I)
plot(lag,c/max(c))
This is the piece of code im using to verify the delay. When I was using two different time vectors t and t1 the peak of the cross correlation plot which indicates the sample delay was zero. When I tried it using Azzis method the plot shows that the sample delay is 5 which should be correct. However the T value displayed by matlab obtained by T=lag(I) is still zero. When I plotted the two signals using the same time vector t I can see that at t=0, the first signal has a value of 1 while the second has a value of -1 indicating a 180 degree phase shift which should happen for a 0.05 second delay. This is also confirmed when I take the FFT of the two signals and plot the phase spectrum. So despite the T value being zero, Can I now accept that my second signal is in fact delayed by 0.05 seconds as required?

댓글을 달려면 로그인하십시오.


Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 24일
delay=5*st
y1=cos(2*pi*100*(t-delay)) % delayed signal

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by