SoundWave/signal info (amplitude, Freq, etc)

If you require help or assistance with anything then please post here

Moderators: electrogear, exonerate

SoundWave/signal info (amplitude, Freq, etc)

Postby distante on Wed Mar 28, 2012 11:20 am

I'm trying to generate the first armonic of a signal,

I'm using an 1k test tone to make my tests,

I have inside my module a code module with this code

Code: Select all
monoin in;
monoout out;


But I don't know how to extract the amplitude and frecuency of the [b]in[/in] variable so I can made the math with them

Help please?

Thank you
Last edited by distante on Sat Mar 31, 2012 11:02 pm, edited 1 time in total.
Sorry If I don't make myself clear sometimes, my English sucks!
User avatar
distante
essemist
 
Posts: 138
Joined: Thu Mar 15, 2012 4:22 pm

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby oddson on Thu Mar 29, 2012 3:28 am

The first harmonic is the fundamental...

If you mean the second harmonic or first overtone then you mean an octave.

The usual analog way of adding an octave is to rectify the signal -- which adds much more than just the first overtone but that plus filtering it about all you can do in analog.

There are other options but -- as I understand things -- none are simple.

Here some code that rectifies (take the absolute value), removes the DC offset and expands back to full range.
Code: Select all
streamin in;
streamout out;
out = 2 * abs(in) - 1;

A lowpass will remove some of the other overtones this will add.
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby martinvicanek on Thu Mar 29, 2012 8:16 am

Hey distante,

to get the amplitude of a signal you would use an envelope follower, which is basically a rectifier followed by a lowpass. Look at the stock module, there is a codeblock inside which you can examine.

Frequency or pitch extraction is a bit more tricky. If your signal is single-pitched with a dominant fundamental, then the zero crossing method is most efficient. Search for "zero crossing" on the forum, Trog has posted a ready-to-use module. There are alternatives based on autocorrelation, where you compare the original signal with a delayed version. If you can find a delay time where the signal essentially folds back on itself, that will give you the (inverse) frequency. These methods are more CPU demanding than zero crossing however they may perform better on signals with rich spectral content.

Hope that helps!
martinvicanek
essemilian
 
Posts: 306
Joined: Sun Mar 13, 2011 1:15 pm

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby distante on Thu Mar 29, 2012 10:49 am

oddson wrote:The first harmonic is the fundamental...

If you mean the second harmonic or first overtone then you mean an octave.

The usual analog way of adding an octave is to rectify the signal -- which adds much more than just the first overtone but that plus filtering it about all you can do in analog.

There are other options but -- as I understand things -- none are simple.

Here some code that rectifies (take the absolute value), removes the DC offset and expands back to full range.
Code: Select all
streamin in;
streamout out;
out = 2 * abs(in) - 1;

A lowpass will remove some of the other overtones this will add.


Yeap, I was talking about the second harmonic, Sometime I'm stuck with the musician theory where the second acoustic harmonic is the first musical one. Big Sorry!

I'm not afraid (yet) to enter into complicated low level coding, after all, I'm doing this for as a "final project" in my place of study; so I'm already prepare to take the hard path, It's just that somethings are managed in a different way in SW, so It's very possible that I will be posting a lot of stuff here :blush:.

I will take a look of your code and tried. Thanks!

martinvicanek wrote:Hey distante,

to get the amplitude of a signal you would use an envelope follower, which is basically a rectifier followed by a lowpass. Look at the stock module, there is a codeblock inside which you can examine.

Frequency or pitch extraction is a bit more tricky. If your signal is single-pitched with a dominant fundamental, then the zero crossing method is most efficient. Search for "zero crossing" on the forum, Trog has posted a ready-to-use module. There are alternatives based on autocorrelation, where you compare the original signal with a delayed version. If you can find a delay time where the signal essentially folds back on itself, that will give you the (inverse) frequency. These methods are more CPU demanding than zero crossing however they may perform better on signals with rich spectral content.

Hope that helps!


Hello martinvicanek,
In the end I want to run a real time vst (as in insert in a DAW) with this "harmonic generator" in a channel with some musical content , so I supposed that the delay stuff isn't the best option (I need to read it first). I will look for zero crossing and mess with the stock module thanks!

*****************************

I hope what I want to do is possible with SW, If not I will need to change my project request :(
Sorry If I don't make myself clear sometimes, my English sucks!
User avatar
distante
essemist
 
Posts: 138
Joined: Thu Mar 15, 2012 4:22 pm

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby treacherousumbrella on Thu Mar 29, 2012 11:10 am

A 2nd order Chebyshev polynomial will give you the 2nd harmonic if the input signal is a full value sine wave.
out=-1 + 2in^2
treacherousumbrella
essemist
 
Posts: 65
Joined: Mon Oct 04, 2010 4:44 pm

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby martinvicanek on Thu Mar 29, 2012 1:50 pm

distante wrote:I want to run a real time vst (as in insert in a DAW) with this "harmonic generator" in a channel with some musical content , so I supposed that the delay stuff isn't the best option

There will be some latency even with the zero crossing method, since you need to wait at least one complete cycle to know the actual period or frequency of a single-pitched signal. The correlation method will require a bit more than one cycle, however both methods are fast enough for real time applications.
distante wrote:I hope what I want to do is possible with SW, If not I will need to change my project request :(

If you want to add an octave (= second harmonic = first overtone) in real time to a single-pitched signal, yes, that's perfectly possible. I am stressing "single-pitched" because musical content is often polyphonic, and then pitch detection beomes really, really tricky. Only very advanced software like Melodyne can do that reasonably well, however not in real time.
martinvicanek
essemilian
 
Posts: 306
Joined: Sun Mar 13, 2011 1:15 pm

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby distante on Thu Mar 29, 2012 5:10 pm

Mmm, the ultimate goal will be to used this in music content.

I saw One person who did this using the language program that REAPER had inside: JESUSONIC (http://www.cockos.com/jesusonic/)

But had the disadvantage that you need or use REAPER for use the plugin or use a bridge.

Using that language (JESUSONIC) he managed to do this:

Image

using this code:
Code: Select all
// Alberto PG (C) 2012
// addons BWSD (C)
desc:APG/Valve 1.9
slider1:1<1,100,0.1>Drive%
slider2:20<20,400,1>Frequency (Hz)
slider3:2<0,4,1{0 dB,6 dB,12 dB,18 dB, 24 dB>HP Slope (db/oct)
slider4:0<-60,20,0.1>Level

@init
y0 = y1 = y2 = y3 = 0;
y4 = y5 = y6 = y7 = 0;

@slider
drive=slider1/100;
trim=32/slider1+0.00001*slider1;
level=10^(slider4/20);
C = exp(-2*$pi*slider2/srate);

@sample
wet0 = sin(spl0 * (drive*$pi)) + cos(spl0 * (drive*$pi)) - 1;
wet1 = sin(spl1 * (drive*$pi)) + cos(spl1 * (drive*$pi)) - 1;

spl0 = wet0*trim*level;
spl1 = wet1*trim*level;

slider3 > 0 ?
(
spl0 -= y0 = spl0 + C*(y0 - spl0);
spl1 -= y1 = spl1 + C*(y1 - spl1);
slider3 > 1 ? (
spl0 -= y2 = spl0 + C*(y2 - spl0);
spl1 -= y3 = spl1 + C*(y3 - spl1);
slider3 > 2 ?
(
spl0 -= y4 = spl0 + C*(y4 - spl0);
spl1 -= y5 = spl1 + C*(y5 - spl1);
slider3 > 3 ? (
spl0 -= y6 = spl0 + C*(y6 - spl0);
spl1 -= y7 = spl1 + C*(y7 - spl1);
))));


So... I'm trying to do something like that but in SM... But I'm not quite sure now if it's possible...
Sorry If I don't make myself clear sometimes, my English sucks!
User avatar
distante
essemist
 
Posts: 138
Joined: Thu Mar 15, 2012 4:22 pm

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby trogluddite on Thu Mar 29, 2012 8:09 pm

That JS code is definitely possible in SM - it's very much like oddson and treachorousumbrella's suggestions - adding the harmonics by distoritng the waveform directly. It will add much more than just 2nd harmonics - I couldn't begin to guess the harmonic content of that function, but most forms of distortion will have particular ones that they emphasise. It's also way, way less demanding on the CPU than frequency extraction etc.

The harmonic generation is actually only a tiny part of the code - just the two lines with the 'sin' and 'cos' functions, at the start of the code proper ("@sample"). The remainder of the code is just a series of 6dB filters - and there are many alternative filter modules around for SM that can be used for this.
Most of the stuff before the "@sample" marker needn't be in your code at all - it is just scaling the controls appropriately, which you can do using the properties of SM's knobs, and a few "green" maths modules.
Most of the maths formulae can be used in SM just as they are, it has all of the functions you need. SM code differs slightly in the way it uses variables, and the conditional bits ("?") have to be done a different way. I've used JS a bit, so if you want a hand porting the code, let me know and I'll post a few pointers.
Feel free to use any schematics and algorithms I post on the forum in your own designs - a credit is appreciated (but not a requirement).
Don't stagnate, mutate to create. Without randomness and serendipity the earth would be just another barren rock.
User avatar
trogluddite
smychopath
 
Posts: 3024
Joined: Mon Oct 20, 2008 3:52 pm
Location: Yorkshire, UK

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby distante on Fri Mar 30, 2012 11:35 pm

Well I really never used JS, I rater don't get my head into other language until I'm comfortable enough with SM (since you already confirm that want I want to do is possible, I will stick to SM, I'm in process to get the money to buy the student version :)

I'm now looking for the math expression for the pair and odd harmonics so I can try to distort the original signal and add this.

I'm still a little bit confused on how can I get the info of the freq and amplitude of the signal in a code box. Seems like the monoin or streamin (or whatever-in) just manage amplitude, that part in the manual doesn't specify what is what (maybe because is something that It's suppose to be known it by me :blush: :blush: )
Sorry If I don't make myself clear sometimes, my English sucks!
User avatar
distante
essemist
 
Posts: 138
Joined: Thu Mar 15, 2012 4:22 pm

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby trogluddite on Sat Mar 31, 2012 12:32 am

All of the stream connection (mono, mono4 and poly) only have the actual values of the samples as they pass through - so yes, just the instantaneous amplitude for a tiny fraction of a second. The stream data is like points on a graph that draw the "sound wave". For recording and playing audio that's just what is needed because the voltages in microphones, speakers etc. also follow the contour of the waveforms
As you may have guessed from the other posts, working out the frequencies that are there is actually a pretty difficult thing to do - kudos to nature for providing us with a brain and ears that do the same job so effortlessly!
For a hell of a lot of processes, this just doesn't matter - echo, chorus, synths etc. all work really well from the raw wave data. Other things like pitch-shifts, or time-stretches really do need to know the frequency if they are to work properly.

Your harmonics project is in the grey-area between these two extremes. On one hand, you have the option of a complex, CPU intensive frequency anaylsis etc. - which, in principle, could accurately generate a very clean, precise 2nd harmonic. Or, there are the "distortion" methods - less accurate, and they need some "side-effects" filtering out; but no sweat for your CPU.
Whether you prefer accuracy, or speed and simplicity, is your choice as the designer. If your tutor is a good one, he will not judge you for the complexity of your code - there is no shame in keeping things simple as long as you can explain why.
Feel free to use any schematics and algorithms I post on the forum in your own designs - a credit is appreciated (but not a requirement).
Don't stagnate, mutate to create. Without randomness and serendipity the earth would be just another barren rock.
User avatar
trogluddite
smychopath
 
Posts: 3024
Joined: Mon Oct 20, 2008 3:52 pm
Location: Yorkshire, UK

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby distante on Sat Mar 31, 2012 4:10 pm

Oh, So the stream is something like the array of amplitude values in time don't? Like in MatLab!

Well since I need to reproduce more than just the second harmonic, I will go for the distortion method, also because If I use the one that need a lot of CPU process using it in real time will be painful so a destructive off line method will be better, BUT I don't that I can't afford the cost of the SM Pro to export to .EXE

I will need to talk this things with my tutor, I hope to have my first meeting with him on Tuesday, until then I will continue exploring the modules and maybe work a little bit in the GUI.

Thanks to you all for your time and patience.
Sorry If I don't make myself clear sometimes, my English sucks!
User avatar
distante
essemist
 
Posts: 138
Joined: Thu Mar 15, 2012 4:22 pm

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby trogluddite on Sun Apr 01, 2012 11:52 am

distante wrote: BUT I don't that I can't afford the cost of the SM Pro to export to .EXE

Note that the Enterprise edition (half the price) will also export .exe's - and the "restrictions" to features are not likely to be a problem for the vast majority of designs.
Also the Free version will export VST's - there is an annoying "noise burst" on the sound sometimes (to encourage customers to pay for registered versions) - but that may not be a big problem if you just need to show your progress to your tutor.
If you (or your tutor) do not have a suitable VST host, then there are some freeware hosts (e.g. VSTHost) that you could use for testing etc.
Feel free to use any schematics and algorithms I post on the forum in your own designs - a credit is appreciated (but not a requirement).
Don't stagnate, mutate to create. Without randomness and serendipity the earth would be just another barren rock.
User avatar
trogluddite
smychopath
 
Posts: 3024
Joined: Mon Oct 20, 2008 3:52 pm
Location: Yorkshire, UK

Re: SoundWave/signal info (amplitude, Freq, etc)

Postby distante on Sun Apr 01, 2012 2:07 pm

trogluddite wrote:
distante wrote: BUT I don't that I can't afford the cost of the SM Pro to export to .EXE

Note that the Enterprise edition (half the price) will also export .exe's - and the "restrictions" to features are not likely to be a problem for the vast majority of designs.
Also the Free version will export VST's - there is an annoying "noise burst" on the sound sometimes (to encourage customers to pay for registered versions) - but that may not be a big problem if you just need to show your progress to your tutor.
If you (or your tutor) do not have a suitable VST host, then there are some freeware hosts (e.g. VSTHost) that you could use for testing etc.


I see, while I'm doing the vst "design" I can use the free version (hehe, I feel like I'm thinking too much of me for saying "do the design" )

Then after do my official presentation buy the Enterprise edition so the jury of my project (besides my tutor, there's 3 teachers) don't have any problem using the VST, and they can test it without any disturb :D
Sorry If I don't make myself clear sometimes, my English sucks!
User avatar
distante
essemist
 
Posts: 138
Joined: Thu Mar 15, 2012 4:22 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 0 guests