Get your CodeRanch badge!*
The moose likes Java in General and the fly likes Triangular Wave Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Triangular Wave " Watch "Triangular Wave " New topic
Author

Triangular Wave

Jody Monahan
Greenhorn

Joined: Feb 10, 2010
Posts: 20
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 10, 2010
Posts: 20
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

Joined: Sep 29, 2008
Posts: 12617

Right, and I'm asking you to make an attempt at that code.
Jody Monahan
Greenhorn

Joined: Feb 10, 2010
Posts: 20
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

Joined: May 03, 2008
Posts: 4523
    
    5

edit Cross posting allegation posted in error. The OP isn't a cross poster.


luck, db
There are no new questions, but there may be new answers.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

...
[removed unnecessary link caused by a misunderstanding over cross posting]


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jody Monahan
Greenhorn

Joined: Feb 10, 2010
Posts: 20
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 10, 2010
Posts: 20
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 03, 2008
Posts: 4523
    
    5

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

Joined: Sep 29, 2008
Posts: 12617

@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

Joined: Jul 26, 2007
Posts: 9990
    
    7

Jody,
My sincerest apologies too. I should not have acted in haste.

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2969
    
    9
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

Joined: Oct 27, 2005
Posts: 19543
    
  16

I agree. So here are the translations from Babelfish:
David's text: Entrust, but check
Mike's text: We will bury you


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That one's better in Russian, though, 'cuz it rhymes.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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
 
subject: Triangular Wave
 
Similar Threads
Populate an array with given values
Updating GUI properties
Multidimensional Arrays
Proper Silence Detection - having problem
Fill a shape based on a General Path