# Creating multiple sine wave data

**URL:** <https://discourse.julialang.org/t/creating-multiple-sine-wave-data/65130>\
**Category:** New to Julia\
**Created:** [July 22, 2021, 6:13pm UTC](https://discourse.julialang.org/t/creating-multiple-sine-wave-data/65130 "2021-07-22T18:13:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sekarsum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sekarsum/32/27202_2.png) [@sekarsum](https://discourse.julialang.org/u/sekarsum)\
**Post date:** [July 22, 2021, 6:13pm UTC](https://discourse.julialang.org/t/creating-multiple-sine-wave-data/65130/1 "2021-07-22T18:13:44Z")

</div>

Hi I need some help creating multiple sine wave profiles and storing them in arrays. I just need data to test another function and sine data is the most useful. It would be helpful if I could also randomize the sinewave signal a little bit by adding a random number to each element.

Pseudocode

begin  
Create sine waves(I don’t know how to do this yet)  
\*\*I tried a for loop and it didn’t exactly work

sinewave1 = [0, 0.2, 0.6, 1, 0.6 ,0.2, 0, - 0.2, -0.6, -1,- 0.6 ,-0.2,0]  
sinewave2 = [0, 0.2, 0.6, 1, 0.6 ,0.2, 0, - 0.2, -0.6, -1,- 0.6 ,-0.2,0]  
sinewave3 = [0, 0.2, 0.6, 1, 0.6 ,0.2, 0, - 0.2, -0.6, -1,- 0.6 ,-0.2,0]

Transpose the sine wave profiles above so instead of [13,1] it is [1,13].  
concatenate the 3 arrays  
add random number to each element

end

---

<div class="post-metadata">

**Author:** ![ess3sq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ess3sq/32/26834_2.png) [@ess3sq](https://discourse.julialang.org/u/ess3sq)\
**Post date:** [July 22, 2021, 6:53pm UTC](https://discourse.julialang.org/t/creating-multiple-sine-wave-data/65130/2 "2021-07-22T18:53:32Z")

</div>

Look into `cat()`, `transpose()` and `push!()`.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 23, 2021, 2:38am UTC](https://discourse.julialang.org/t/creating-multiple-sine-wave-data/65130/3 "2021-07-23T02:38:07Z")

</div>

> [@sekarsum](#):
>
> e sine wave profiles and storing them in arrays. I just need data to test another function and sine data is the most useful. It would be helpful if I could also randomize the sinewave signal a little bit by adding a random number to each element.

For example, here is one period of a sine wave + 1% noise:

```julia
x = range(0, 2π, length=100)
y = @. sin(x) + 0.01 * randn()

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 23, 2021, 11:09am UTC](https://discourse.julialang.org/t/creating-multiple-sine-wave-data/65130/4 "2021-07-23T11:09:28Z")

</div>

It might be useful to link here your other post explaining the (non-trivial) [broadcasting of `rand()`](https://discourse.julialang.org/t/rand-vs-rand/2079/11).
