• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Triangular Wave

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, and I'm asking you to make an attempt at that code.
 
Jody Monahan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
edit Cross posting allegation posted in error. The OP isn't a cross poster.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...
[removed unnecessary link caused by a misunderstanding over cross posting]
 
Jody Monahan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jody,
My sincerest apologies too. I should not have acted in haste.

 
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That one's better in Russian, though, 'cuz it rhymes.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not speaking any Russian I'll take your word for it. Now back on-topic!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic