This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Triangular Wave

 
Jody Monahan
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am having a problem creating a triangular wave. Essentially I would like a wave that oscillates from -0.5 to 0.5 with increments of 0.005. I have been able to do this for 1 iteration i.e it oscillates from -0.5 to 0.5 and back down to -0.5, however I would like this to be periodic, and repeat itself so that there is a certain number of samples left in the array (832267 samples to be exact). The following is the code I have currently come up with:



Thanks in advance.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you basically want to repeat what you already have for as many times as you want samples (with the caveat that what you have there already fills a certain number of those samples), yes?

What might that look like?
 
Jody Monahan
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes thats exactly what I want to do, just repeat what code I have previously. It should look like a periodic triangular waveform of length 832267.

Note: the significance of the number 832267 is the number of samples of a wave file that I am trying to manipulate.

Thanks
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, and I'm asking you to make an attempt at that code.
 
Jody Monahan
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh right, sorry. I have made an attempt just by putting it all in another for loop, but the way I have gone about it isn't exactly correct because I need the array to be exactly 832267 samples in length.

Attempt:

 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
edit Cross posting allegation posted in error. The OP isn't a cross poster.
 
Maneesh Godbole
Saloon Keeper
Posts: 10973
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...
[removed unnecessary link caused by a misunderstanding over cross posting]
 
Jody Monahan
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maneesh and Daryl, I hope you realise that that wasn't me posting a similar topic across different forums. Maneesh, I am fully aware of the rules and regulations of the site. If you read my posts I have asked a specific question about my code, and that question still stands if anyone can provide some help.

Thanks.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry, Jody, it appears Daryl was being a bit hasty, as the other posts are regarding graphs, and yours isn't. Plus the wording on all the other posts is identical, and this one isn't.
 
Jody Monahan
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clearing that up David. Any way, I have spent another few hours looking at the code and have come up with the following solution:



It doesn't look great but it does the trick. Thanks to anyone that looked at it.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you thought of any other possible approaches? Sometimes just posting "out loud" is enough to do the trick ("rubber ducking" it).
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jody Monahan wrote:Hi Maneesh and Daryl, I hope you realise that that wasn't me posting a similar topic across different forums. Maneesh, I am fully aware of the rules and regulations of the site. If you read my posts I have asked a specific question about my code, and that question still stands if anyone can provide some help.

Thanks.

Jody, my sincerest apologies to you, Maneesh and all forum members. I should have read the post, not just the subject line.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Darryl: just be careful when making accusations. Fortunately, I've learned this: Доверяй, но проверяй. (And am getting good pronunciation tips from my current boss, who's Russian.)
 
Maneesh Godbole
Saloon Keeper
Posts: 10973
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jody,
My sincerest apologies too. I should not have acted in haste.

 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:@Darryl: just be careful when making accusations. Fortunately, I've learned this: Доверяй, но проверяй. (And am getting good pronunciation tips from my current boss, who's Russian.)

Мы вас похороним!!!

Sorry, got carried away.

So, are we repealing the long-standing rule that this is an English-speaking forum, and that posts are expected to be in English? I kind of like being able to come here and read what people are saying without having to resort to Google or babelfish. I hope that can continue.
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. So here are the translations from Babelfish:
David's text: Entrust, but check
Mike's text: We will bury you
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That one's better in Russian, though, 'cuz it rhymes.
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not speaking any Russian I'll take your word for it. Now back on-topic!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic