Help with complex numbers wanted
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
8 posts
• Page 1 of 1
Help with complex numbers wanted
I have a requirement to convert a complex number , say 16J220 to 16J440 (multiplying just the imaginary part by 2), without changing the value of the real part.
Is these any easy way of performing this simple operation ?
Currently I am having to split the complex number using
multiplying the "imaginary" by 2 and then recombining them into the new complex number with the unaltered real part.
I am using the complex number to storey two independent values (the duration of a musical note and the frequency in Hz), and wish to transpose the frequency by an octave ( or some other amount).
I am dealing with thousands of "notes" within complex structures of varying depth and need to maintain the initial structure.
Any suggestions? Thanks
Ray
Is these any easy way of performing this simple operation ?
Currently I am having to split the complex number using
- Code: Select all
real imagnary←9 11 ○ complex
multiplying the "imaginary" by 2 and then recombining them into the new complex number with the unaltered real part.
I am using the complex number to storey two independent values (the duration of a musical note and the frequency in Hz), and wish to transpose the frequency by an octave ( or some other amount).
I am dealing with thousands of "notes" within complex structures of varying depth and need to maintain the initial structure.
Any suggestions? Thanks
Ray
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: Help with complex numbers wanted
Hi, Ray
is this for any help?
-Veli-Matti
is this for any help?
ComplexTimes←{(⍺,¯11○1)+.×9 11∘.○⍵}
⎕←vec←0J220+⍳5
1J220 2J220 3J220 4J220 5J220
2 ComplexTimes vec
2J220 4J220 6J220 8J220 10J220
100 ComplexTimes vec
100J220 200J220 300J220 400J220 500J220
-Veli-Matti
- Veli-Matti
- Posts: 94
- Joined: Sat Nov 28, 2009 3:12 pm
Re: Help with complex numbers wanted
Ray-- I tried clever alternatives, but I think you've hit on the most natural (and hence, likely most time-efficient) solution in APL. Veli-Matti's version is more efficient than the naive solutions I thought of, but I think you want the ⍺ and the 1 reversed in the leftmost expression, giving you this revision, CT1a:
Cheers,
Pete S
- Code: Select all
CT1a←{(1,¯11○⍺)+.×9 11∘.○⍵}
Cheers,
Pete S
- petermsiegel
- Posts: 159
- Joined: Thu Nov 11, 2010 11:04 pm
Re: Help with complex numbers wanted
Many thanks for these suggestions.
I have replaced my code with Peter's suggestion as it is very much neater and efficient than the code I was using.
Originally I was just using it for transposing code by an octave, but now will use it to create chords from a single root frequency as well.
I have chord ratios for : Major(Root), 6th, Major7th, 7th, 9th, 7th9th, 11th, 13th, +(plus), 7th+, 7b5th, minor, minor6th, minor7th and Diminished.
So an Am (A minor) chord would use A2 (220 Hz) as the root, with the chord built up of the 1, 7, 8, 13 and 16 note in the scale of A.
Rather than using an "equal temperament" scale, I feel that chords should really use a "well tempered" scale based on the root. On a real instrument, this would not be possible, but with virtual instruments, re-tuning on the fly is perfectly possible. However, people with perfect pitch might disagree!
Sorry for going off topic.
Thanks again.
Ray
I have replaced my code with Peter's suggestion as it is very much neater and efficient than the code I was using.
Originally I was just using it for transposing code by an octave, but now will use it to create chords from a single root frequency as well.
I have chord ratios for : Major(Root), 6th, Major7th, 7th, 9th, 7th9th, 11th, 13th, +(plus), 7th+, 7b5th, minor, minor6th, minor7th and Diminished.
So an Am (A minor) chord would use A2 (220 Hz) as the root, with the chord built up of the 1, 7, 8, 13 and 16 note in the scale of A.
Rather than using an "equal temperament" scale, I feel that chords should really use a "well tempered" scale based on the root. On a real instrument, this would not be possible, but with virtual instruments, re-tuning on the fly is perfectly possible. However, people with perfect pitch might disagree!
Sorry for going off topic.
Thanks again.
Ray
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: Help with complex numbers wanted
My sense of pitch is quite bad, so what I am going to write is hardly from direct experience. I read more than once that choirs drift towards perfect intervals (a.k.a. just intonation) almost instinctively. Therefore, especially in emotional moments like important cadences, they sing perfect thirds and fifths disregarding common equal temperament, even in pieces that were composed with equal temperament in mind.
The same applies to bowed instruments (like string quartets) which often stray towards just intonation.
Then there are people who do it very consciously. Take for instance this cover of Moon River https://www.youtube.com/watch?v=VPLCk-FTVvw. The guy has perfect pitch (https://youtu.be/5vrhKI7JHQc?si=x4-L-xfF6tmwV2ZV&t=930) but instead of being bothered by notes that are not in the equal temperament he uses microtonality as he pleases https://www.youtube.com/watch?v=RGDWXe2u9kw). Most of what he does flies well over my head but I've seen transcriptions and commentaries of this cover (for instance: https://www.youtube.com/watch?v=UTDHylJZMXU). The power of certain chords (like the last one in Moon River) stems from the fact that they are just-intoned.
Fanboy here, but the joy with which Jacob describes modulating to G half sharp is contagious: https://www.youtube.com/watch?v=HUGoUHKAGAE. The tune is "In The Bleak Midwinter".
The same applies to bowed instruments (like string quartets) which often stray towards just intonation.
Then there are people who do it very consciously. Take for instance this cover of Moon River https://www.youtube.com/watch?v=VPLCk-FTVvw. The guy has perfect pitch (https://youtu.be/5vrhKI7JHQc?si=x4-L-xfF6tmwV2ZV&t=930) but instead of being bothered by notes that are not in the equal temperament he uses microtonality as he pleases https://www.youtube.com/watch?v=RGDWXe2u9kw). Most of what he does flies well over my head but I've seen transcriptions and commentaries of this cover (for instance: https://www.youtube.com/watch?v=UTDHylJZMXU). The power of certain chords (like the last one in Moon River) stems from the fact that they are just-intoned.
Fanboy here, but the joy with which Jacob describes modulating to G half sharp is contagious: https://www.youtube.com/watch?v=HUGoUHKAGAE. The tune is "In The Bleak Midwinter".
-
StefanoLanzavecchia - Posts: 113
- Joined: Fri Oct 03, 2008 9:37 am
Re: Help with complex numbers wanted
Maybe I'm missing something here, but for this specific case (doubling the imaginary part), the following would seem sufficient and fairly efficient:
⎕←vec←0J220+⍳5
1J220 2J220 3J220 4J220 5J220
(+⍨-9∘○) vec
1J440 2J440 3J440 4J440 5J440
{⍵+⍵-9○⍵} vec ⍝ if you don't want tacit
1J440 2J440 3J440 4J440 5J440
-
Adam|Dyalog - Posts: 143
- Joined: Thu Jun 25, 2015 1:13 pm
Re: Help with complex numbers wanted
I was keying off the "requirement" in parens, viz. the general case:
[I] wish to transpose the frequency by an octave ( or some other amount).
- petermsiegel
- Posts: 159
- Joined: Thu Nov 11, 2010 11:04 pm
Re: Help with complex numbers wanted
Thanks Adam.
My most common use is to just double the frequency, and your code is great for that.
The ability of creating chords from a single note, or transposing into another key, however open up new opportunities.
I really must get into writing and using tacit code.
My most common use is to just double the frequency, and your code is great for that.
The ability of creating chords from a single note, or transposing into another key, however open up new opportunities.
I really must get into writing and using tacit code.
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 238
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group