electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
How to build a Frequency Shifter?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [21 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 17606
Location: Allentown, PA
Audio files: 124
G2 patch files: 60

PostPosted: Fri Jul 17, 2009 10:45 am    Post subject: How to build a Frequency Shifter? Reply with quote  Mark this post and the followings unread

In another topic about binaural sync, http://electro-music.com/forum/topic-35640.html , the question came up about using Chuck to make a frequency shifter. I understand from Inventor that there is a built in for PitShift, but that is probably not a frequency shifter. Pitch shifters generally transpose the input, up or down, but frequency shifters shift the frequencies algebraically. What is needed is a balanced modulator where the up and down sidebands are available separately.

Any ideas?

_________________
--Howard
my music and other stuff

Last edited by mosc on Fri Jul 17, 2009 11:40 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20480
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Fri Jul 17, 2009 10:50 am    Post subject: Reply with quote  Mark this post and the followings unread

What Les also said there that the chuck one was based upon a delay line, so likely with a write pointer and a read pointer running at different speeds, and so indeed a resampling pitch shifter.

What would be needed is the Bode frequency shifter, there is a description here (moog patents).

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 17606
Location: Allentown, PA
Audio files: 124
G2 patch files: 60

PostPosted: Fri Jul 17, 2009 11:37 am    Post subject: Reply with quote  Mark this post and the followings unread

Good link, thanks. Here is the block diagram from the patent itself.


Bode-Freq-Shift-Patent-Diagram.png
 Description:
Block diagram of the Bode Frequency Shifter from Patent
 Filesize:  97.26 KB
 Viewed:  553 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

Bode-Freq-Shift-Patent-Diagram.png



_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 5978
Location: San Antonio, Tx, USA
Audio files: 258

PostPosted: Fri Jul 17, 2009 1:06 pm    Post subject: Reply with quote  Mark this post and the followings unread

Here is a comment from the author of the excellent web page that Blue Hell cited, describing the difference between ChucK's PitShift and what we want to create for mosc:

Quote:
It's important to note that this effect is a frequency shift and not the pitch shift effect currently available in modern digital effects boxes. In a frequency shifter all frequency components of the input signal are offset by a specific number of Hz while in a pitch shifter all frequency components are multiplied by a specific factor. The former sounds something like a ring modulator while the latter sound something like playing back a tape at a different speed.


If I understand it right, we don't want to make the sound of a tape being played back at a different speed, which is what ChucK does with the PitShift UGen. Rather, we want to make the sound of an RF modulator with the upper and lower sidebands available as separate outputs.

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Jul 17, 2009 1:11 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hmmmm, would it do to take a Fourier transform, shift the data in the resultant array and take the inverse Fourier of that? Admittedly it's a bit on the crude side but it's easy Smile

A real Bode shifter should be possible as well but i'd have to read up on how those worked, again.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 5978
Location: San Antonio, Tx, USA
Audio files: 258

PostPosted: Fri Jul 17, 2009 1:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

Kassen, that would indeed be a crude yet effective way to do it, however in the other thread mosc mentioned that he needed a high recording sample rate to capture the nuances of the binaural effect. Something like a 1024 sample FFT, which is what's typically practical from a CPU usage standpoint, would be too crude. I think we should look at using ChucK to implement the Moog frequency shifter or some ChucKian simplification of it.
_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
TGV



Joined: Jul 03, 2009
Posts: 23
Location: Utrecht, The Netherlands

PostPosted: Sat Jul 18, 2009 12:30 am    Post subject: Granular? Reply with quote  Mark this post and the followings unread

In Max, there is an FFT based solution (called gizmo~) and a granular solution (called granola~), according to this thread:
http://www.cycling74.com/forums/forums.html?rid=0&S=709421774128ea8643aacc9362e368a6&t=msg&th=27101. Source code is probably not available, manual page is here http://www.cycling74.com/docs/max5/refpages/msp-ref/gizmo~.html.

FFT of course has the problem of time delay, but in ChucK it might not be such a problem, if I understand the "upchuck" properly. Granular resynthesis might work, but apparently doesn't sound as good.
Back to top
View user's profile Send private message
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 5978
Location: San Antonio, Tx, USA
Audio files: 258

PostPosted: Sat Jul 18, 2009 1:30 am    Post subject: Reply with quote  Mark this post and the followings unread

I found an excellent web page on the topic here:

http://www.cim.mcgill.ca/~clark/nordmodularbook/nm_spectrum_shift.html

The block diagram for the frequency shifter is shown below. This seems to be a very clean and simple design that is easily implemented in ChucK. In fact, I did so, also posted below.

Change the fdelta parameter to vary the amount of frequency shifting, and change the f1 parameter to vary the carrier frequency. Also the lpf cutoff and maybe it's Q can be mucked with if desired.

The ChucK docs do not clearly state how phase is represented. Is it a variable from 0 to 1 or from 0 to 2*pi? I implemented the phase shift of the cosine oscillator as 0.25, being 1/4 of a 0 to 1 phase shift. Kas or someone could you clarify this detail?

mosc, if you test this and it seems to work, then I'll put it in a class wrapper and make two of them, one for the left channel and the other for the right. Then we'll have our ChucKian binaural encoder, I believe.

Les


frequency_shifter_diagram.jpg
 Description:
Frequency Shifter Block Diagram
 Filesize:  25.01 KB
 Viewed:  12646 Time(s)

frequency_shifter_diagram.jpg



FrequencyShifter1.ck
 Description:
Frequency Shifter

Download
 Filename:  FrequencyShifter1.ck
 Filesize:  793 Bytes
 Downloaded:  229 Time(s)


_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20480
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Sat Jul 18, 2009 6:15 am    Post subject: Reply with quote  Mark this post and the followings unread

Ah Jim Clarck's site, of course Smile

Inventor wrote:
[...]make two of them, one for the left channel and the other for the right. Then we'll have our ChucKian binaural encoder, I believe.


The one on the G2 has two outputs, one output for an upshifted frequency and one for a downshifted frequency. Looking at the schematic that may just be the two points before the final summation, but I'm not sure there. Anyway, the way it's being used by me usually is that the up-shifted out goes to one channel and the downshifted down to the other channel, that way it makes some (moving) pseudo stereo from a mono signal (using a small frequency shift, less than 1 Hz typically). I've not seen Howard's patch, but I think that is what he did too.

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20480
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Sat Jul 18, 2009 7:09 am    Post subject: Reply with quote  Mark this post and the followings unread

Hmm .. that seems wrong ...

the low pas filters in the schematic above would cause the upper side bands of the first mix to be filtered out, I assume, at least when I calculate with that the output frequency would be shifted by the difference between f1 and f2, thus yielding only one shifted output.

I dont however see that it would shift by the absolute value of the difference, I just get :

fout = fin + f2 - f1

provided that the low pass filtering is perfect. Which means that a pretty high frequency should be used for both f1 and f2, but also that when f1 is smaller than f2 an upshift would occur.

Code:

sin( fin) * sin( f1) = ( cos( fin - f1) - cos( fin + f1)) / 2 = P

sin( fin) * cos( f1) = ( sin( fin + f2) + sin( fin - f1)) / 2 = Q

perfectly low pass filtering these gives

R = lpf( P) = cos( fin - f1) / 2

S = lpf( Q) = sin( fin - f1) / 2

then the 2nd mixer gives us :

sin( f2) * R = ( sin( f2 + fin - f1) + sin( f2 + f1 - fin)) / 4 = T

cos( f2) * S = ( sin( f2 + fin - f1) - sin( f2 + f1 - fin)) / 4 = U

now T + U = sin( fin + f2 - f1) / 2 = sin( fout) / 2

so fout = fin + f2 - f1

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Sat Jul 18, 2009 9:42 am    Post subject: Reply with quote  Mark this post and the followings unread

Inventor wrote:

The ChucK docs do not clearly state how phase is represented. Is it a variable from 0 to 1 or from 0 to 2*pi? I implemented the phase shift of the cosine oscillator as 0.25, being 1/4 of a 0 to 1 phase shift. Kas or someone could you clarify this detail?


Yes, phase ranges from 0 to 1. This is related to Phasor being the base-case for the (plain) oscillators, in the case of Phasor the literal output and it's phase are the same. This may be related to how Phasor refuses to react to plusewith settings, like the docs claim it should. It makes little sense to talk about pi in the case of -say- a SqrOsc. SinOsc, btw, is a exception in the source but still treats phase as a number from 0 to 1.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 5978
Location: San Antonio, Tx, USA
Audio files: 258

PostPosted: Sun Jul 19, 2009 3:27 am    Post subject: Reply with quote  Mark this post and the followings unread

I don't get it - I feel that Blue Hell's analysis must be correct, however when I program it in ChucK it always shifts up! I've tried all kinds of combinations of f1 and f2, yet every time it shifts up. This is in agreement with the text of the web page.

The attached text file has an input of 100 Hz and and fdelta of 100 Hz, so one of the channels should produce 200 Hz and the other 0 Hz (silence), yet both channels always produce the same tone no matter what I do. Is my filtering wrong or something? I dunno. Here is the ChucK file:


BinauralShifter3.ck
 Description:
Not so good binaural shifter

Download
 Filename:  BinauralShifter3.ck
 Filesize:  1.21 KB
 Downloaded:  195 Time(s)


_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20480
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Sun Jul 19, 2009 5:30 am    Post subject: Reply with quote  Mark this post and the followings unread

Maybe there is an issue with negative frequencies ... sin(-x) would be -sin(x) (for positive x) but cos(-x) would be cos(x)
_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
puretube



Joined: Mar 07, 2006
Posts: 2
Location: germany

PostPosted: Tue Oct 13, 2009 12:47 am    Post subject:   Reply with quote  Mark this post and the followings unread

For shifting down, you need to subtract the 2 mixers outputs
instead of adding them...
(i.e. instead of the sum, you need the difference...)
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20480
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Tue Oct 13, 2009 12:01 pm    Post subject: Reply with quote  Mark this post and the followings unread

Interesting ... and welcome

then we get

Code:

sin( f2) * R = ( sin( f2 + fin - f1) + sin( f2 + f1 - fin)) / 4 = T

cos( f2) * S = ( sin( f2 + fin - f1) - sin( f2 + f1 - fin)) / 4 = U

and - U = ( - sin( f2 - fin - f1) + sin( f2 + f1 - fin)) / 4

now T + ( - U) = sin( f2 + f1 - fin) / 2 = sin( fout) / 2

so fout = f2 + f1 - fin


So fout gets smaller when fin goes up in this case.

Can't really experiment right now ... Les you still here?

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 5978
Location: San Antonio, Tx, USA
Audio files: 258

PostPosted: Tue Oct 13, 2009 1:59 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hi Jan, I'll try to make time to test it out.

Les

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 5978
Location: San Antonio, Tx, USA
Audio files: 258

PostPosted: Tue Oct 13, 2009 2:26 pm    Post subject: Reply with quote  Mark this post and the followings unread

I'm not sure if I did this right, but the subtraction only makes that channel quieter and at the same frequency. Attached is the ChucK program. I set the frequency to 1kHz and the delta to 500 Hz to get a clearly identifiable tone of either 1.5 kHz or 500 Hz. Both ears come up with 1.5 kHz or so it sounds. So the subtraction does not seem to downshift with this algorithm.

Les


BinauralShifter4.ck
 Description:
Binaural Shifter with subtraction

Download
 Filename:  BinauralShifter4.ck
 Filesize:  1.23 KB
 Downloaded:  184 Time(s)


_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20480
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Tue Oct 13, 2009 2:39 pm    Post subject: Reply with quote  Mark this post and the followings unread

I think you'll need pretty high frequencies ... the carrier tones should be filtered out by the filters for it to work.
_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
puretube



Joined: Mar 07, 2006
Posts: 2
Location: germany

PostPosted: Wed Oct 14, 2009 12:59 am    Post subject: Reply with quote  Mark this post and the followings unread

(scratch head...)
Somehow I had fig.3 of the Bode patent in mind...

In the ChucK-case this would probably end up inverting the sin(f2 t) of the second oscillator to minus sin(f2 t), (i.e. turned around by 180°),
and then adding the 2 mixed signals at the output again, like before?


Sorry if I mixed things up and spread confusion...


Ahh, and thanx for the welcome:
Scott Stites, whom I had the honour to send a few TDA1022s a few years ago, brought my attention here from http://www.diystompboxes.com/smfforum/forums.html...
Back to top
View user's profile Send private message
Scott Stites
Janitor
Janitor


Joined: Dec 23, 2005
Posts: 4121
Location: Mount Hope, KS USA
Audio files: 96

PostPosted: Sat Oct 17, 2009 5:54 pm    Post subject: Reply with quote  Mark this post and the followings unread

OMG!!! Ton?

welcome verily!!!

It's fantastic to see you here!

_________________
My Site
Back to top
View user's profile Send private message
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 17606
Location: Allentown, PA
Audio files: 124
G2 patch files: 60

PostPosted: Mon Oct 19, 2009 8:43 pm    Post subject: Reply with quote  Mark this post and the followings unread

I read somewhere, but didn't bother to make a bookmark, that the best way to do a freq shifter in digital is using a Hilbert transform so you don't need dome filters. I was hopeful someone would know a bit more about this.
_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [21 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use