How to add the exact axis ?!

2 visualizaciones (últimos 30 días)
Susan
Susan el 27 de Ag. de 2011
Dear all, I have my code for two signals and I am delaying one of them but the axis starts from 0 to 6 and I want to be able to see in the axis the time it was delayed in roughly if not exactly.. If I delay one signal by 50 it moves a bit towards 1 ? I know t=(0:N)/FS which basically 5.12 so t is up to 6 but how can I make it up to whatever the length of the signal is ?
function signal(a)
N=1024;
f1=1;
FS=200;
t=(0:N)/FS;
x=cos(2*pi*f1*t);
subplot(3,1,1);plot(t,x);
y=[repmat(0,1,input),x(1:end-input)];
subplot(3,1,2);plot(t,y);
[Rxx,lags] = xcorr(x,y);
[Y,I] = max(Rxx);
lags(I) ;
disp(lags(I));
end
Cheers, Susan

Respuestas (1)

Walter Roberson
Walter Roberson el 27 de Ag. de 2011
I find your question to be confusingly phrased.
I am not sure why your function takes a parameter "a" but does not use it?
I do not understand why you talk about ranges like 0:6 but also talk about delaying a signal by 50. 50 what? 50 points or 50 ms or 50 seconds?
Your line
y=[repmat(0,1,input),x(1:end-input)];
is likely to confuse both readers and the user. You do not define "input" in your function and it is not a parameter, so in this context "input" is going to mean a call to MATLAB's input() function with no arguments, meaning to prompt the user for input but not to give a message about which input is expected. And you call it twice in the same line so there are going to be two of these "Read Programmer's Mind" input in a row. And the program is going to malfunction if the two entered values are not scalars and are not the same value. Could you not at the very least use something like,
sdelay = input('Signal delay');
y=[repmat(0,1,sdelay),x(1:end-sdelay)];
It would, by the way, be more common to use zeros(1,sdelay) than repmat(0,1,sdelay)
Anyhow, to answer the question you actually posed, which I suspect is not at all what you meant to ask: to get the axis up to the length of the signal, use
xlim([0,length(t)])
I think you will be less than happy with the result, but this is how to do as you asked.

Community Treasure Hunt

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

Start Hunting!

Translated by