random signal delay

clc
clear all
close all
fs=10000; % sampling frequency in Hz
f1=500; % frequency of signal in Hz
f2=200;
f3=700;
t_duration=1; %duration of LONG signal in seconds
t = 0:1/fs:t_duration-1/fs; %sampling points
x = sin(2*pi*f1*t)+cos(2*pi*f2*t)+sin(2*pi*f3*t);
d=0.000079734452; % time delay in seconds
I can delay it mathematically as follows:
s1=sin(2*pi*f1*(t-d))+cos(2*pi*f2*(t-d))+sin(2*pi*f3*(t-d));
How can I do the same (mathematically) if:
x=randn(size(t));
I need to produce the same set of random values each time. I have gone through doc rng; but Iam unable to do it.
Please illustrate with an example.
thank you.

Respuestas (2)

Honglei Chen
Honglei Chen el 27 de Feb. de 2012

0 votos

There are two questions in your post so I'm not sure if I understand exactly what you look for. I'll include my thoughts below:
1. To get the same random value each time, set a seed using rng, for example
rng(1);
randn(10,1);
rng(1);
randn(10,1);
You should get the same random values for two trials.
2. Now if you want to delay the random signal, you can always append zero in front. The number of zeros you insert depends on your sampling frequency and required delay.
x = randn(10,1);
x_delay = [0;x]; % delayed by 1 sample

4 comentarios

zozo
zozo el 27 de Feb. de 2012
Sir, my problem is delay being a non-integer multiple of sampling frequency.
As mentioned in my code,
d=0.000079734452; % time delay in seconds
how can I implement this mathematically into 'randn' like I did with 's1' above?
(Note: Iam doing this to cross check if my frequency domain delaying technique works perfectly for any random signal and any random delay 'd').
Honglei Chen
Honglei Chen el 27 de Feb. de 2012
I suspected a little for this but I wasn't sure. Given this is what you want to do, I have a question for you. What do you think the delayed signal should be? Now this is a signal you created out of randn, which is a white noise. By definition, the value at the next moment has nothing to do with the value at the current moment, so I would argue that the delayed version is a complete different randn vector. Therefore, IMHO, I don't think this is a good test signal.
zozo
zozo el 27 de Feb. de 2012
Ok..Can you suggest an alternative test, apart from the one I used above in my code?
Honglei Chen
Honglei Chen el 27 de Feb. de 2012
Personally I think your test case is fine, if you really want, you can try a triangle signal or even a rectangular signal. Just be prepared that there will be distortion in the result.

Iniciar sesión para comentar.

vijay
vijay el 31 de Oct. de 2013

0 votos

do u have modified code for this

Etiquetas

Preguntada:

el 27 de Feb. de 2012

Respondida:

el 31 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by