Sinusoidal Random Vector question

I want to create a vector of the same length as another vector called variable t. Typically, I would just use linspac; however, I do not want a linear regression. preferably, I'd like to make a sinusoidal regression if at all possible... if not any non-linear regression will do. What's the best way to go about this?

4 Commenti

This question raises to many questions.
  • Do the values of the vector depend on t?
  • What is your link between using linspace and linear regression?
  • What do you mean by random?
  • Can you give a small example?
John D'Errico
John D'Errico il 31 Mag 2016
Modificato: John D'Errico il 31 Mag 2016
Usually when someone posts a question like this that is so totally confusing, it is a reflection that THEY are totally, utterly confused. For example, linspace has nothing to do with linear regression. It also has nothing to do with random-ness, or anything sinusoidal for that matter.
So SLOW DOWN. Don't try to use jargon that you don't really understand. Explain your problem clearly. More words are better than fewer words. A picture would help, or an example.
So I have a time variable, called t that is 20 seconds long (length of 20). I want to essentially create a new vector in a way that you would by using linspace (where you have a start value, end value, and a step value) or using a colon operator. The problem that I have now is that these operations will increase linearly.
For example: t = [1 2 3 4 5... 20] f1 = 4500 f = linspace(f1,4700,length(t))
f = [4500 4510.52631578947 4521.05263157895 4531.57894736842 4542.10526315790 4552.63157894737 4563.15789473684 4573.68421052632 4584.21052631579 4594.73684210526 4605.26315789474 4615.78947368421 4626.31578947368 4636.84210526316 4647.36842105263 4657.89473684211 4668.42105263158 4678.94736842105 4689.47368421053 4700]
What I'm asking is if there is a function to use that would give me 20 different values (or whatever length t is) across a sinusoidal wave function or if there's a good way to go about it.
An easier example would be f1 = 1 t = [1 2 3 4 5... 20] f = linspace(f1, 20, length(t))
f = [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]

Accedi per commentare.

 Risposta accettata

John D'Errico
John D'Errico il 31 Mag 2016
Modificato: John D'Errico il 31 Mag 2016
This is just a guess.
f1 = 4500;
f2 = 4700;
x = (sin(linspace(-pi/2,pi/2,20))+1)/2*(f2-f1) + f1;
plot(x)
But it is not random. Do you also want something that is random? You did say random in the original question, but in the comment, you said nothing about randomness.

3 Commenti

Macon Pharr
Macon Pharr il 31 Mag 2016
Modificato: Macon Pharr il 31 Mag 2016
Sorry about that. I would prefer random as that's how I've visualized the data points for the test that I'm running. This might work too though as it's along the lines of what I want.
You can add noise to the values, using functions like rand, randn etc.
Xnoise = x + randn(size(x))
John D'Errico
John D'Errico il 31 Mag 2016
Modificato: John D'Errico il 31 Mag 2016
Here is a sample with many points, so you can see they come from the desired distribution.
x = (sin(sort((rand(1,2000)-.5)*pi))+1)/2*(f2-f1) + f1;
plot(x)
I had a funny feeling randomness was part of it, but I was too lazy to add it too. Note that only 20 points might not seem that sinusoidal.

Accedi per commentare.

Più risposte (0)

Prodotti

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by