How to move a Signal..

3 vues (au cours des 30 derniers jours)
Susan
Susan le 12 Août 2011
Dear all,
I am trying to learn some concepts of Signal processing to be able to work on my project. For the sample code below (Not my code but the idea is the same, mine is using random number generator), I have two signals and one is a delayed version of first one.. I want to know how can I move the Signal by the delay time I got so I will show that the two signals are the same indeed but one is delayed?
n = 0:299;
x = cos(pi/4*n);
xdft = fft(x);
k = 0:299;
D = 2;
phaseshift = exp(-1j*(2*pi*k*D)/length(x));
xdft = phaseshift.*xdft
% y is x delayed by two samples
y = ifft(xdft,'symmetric');
[Pxy,W] = cpsd(x,y,100,80,128);
[~,I] = max(abs(Pxy));
phase = atan2(-imag(Pxy(I)),real(Pxy(I)));
% the delay in samples prints out. The negative indicates delay.
round(phase*(1/(pi/4)))
plot(x(1:100),'k');
hold on;
plot(y(1:100),'b');
grid on; legend('Original','Delayed');
Thanks,
  1 commentaire
Aboubakar Tchendjou
Aboubakar Tchendjou le 16 Fév 2022
Hallo zusammen
wie kann ich bitte ein Signal x[n]=2delta[n]+delta[n-2]+4delta[n-5]
3 Mal nach recht mit Matlab verschien also X[n-3] Mit Matlab erzeugen?
Danke im Voraus

Connectez-vous pour commenter.

Réponse acceptée

Daniel Shub
Daniel Shub le 12 Août 2011
For delays that are an integer number of samples you can add a delay (zeros) in the plot:
plot([zeros(1, D), x(1:100)],'k');
plot([y(1:100), zeros(1, D)],'b');
For delays that are not an integer number of samples, where using your approach with "phaseshift" really shines, you really have to just rerun your code backwards to compensate for the delay.

Plus de réponses (1)

Nitin
Nitin le 12 Août 2011
It may be that I didn't understand your problem but isn't plot((1-delay:100-delay),x(1:100)) plot a delayed version of x on the same scale; here I've used 1-delay, as I saw you're plotting x and y with an initial time of 1. The delay you've calculate in your code is -2. The values for time periods before the delay time are not defined, but you could define them with some initial value.

Community Treasure Hunt

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

Start Hunting!

Translated by