[julia-users] Re: Generating MLS Sequences: modulo-2 polynomial factorization

2016-10-21 Thread CrocoDuck O'Ducks
These are very good info, thanks!

On Friday, 21 October 2016 11:49:42 UTC+1, Fredrik Johansson wrote:
>
> On Thursday, October 20, 2016 at 9:52:26 PM UTC+2, CrocoDuck O'Ducks wrote:
>>
>> Hi there cool people!
>>
>> I have implemented a simple MLS generator using linear feedback shift 
>> registers. I used as taps the ones provided in: 
>>
>> Vanderkooy, J. (1994). Aspects of MLS Measuring Systems. Journal of the 
>>> Audio Engineering Society, 42 (4), 219-231.
>>>
>>
>>  However, now that the theory is a little bit clearer to me, I would like 
>> to make it more general. The feedback taps are supplied by the coefficients 
>> of the primitive factors of the polynomial x^N + 1, where N is the length 
>> of the sequence (related to the number of registers). I would like to know 
>> from you guys if you think there is some Julia package I can use to 
>> calculate primitive factors of polynomials. As mentioned in the title, I 
>> need to perform this in modulo-2. Here 
>> <http://www.newwaveinstruments.com/resources/articles/m_sequence_linear_feedback_shift_register_lfsr.htm>
>>  
>> there are more info and the Berlekamp algorithm is mentioned. Has that 
>> algorithm already been implemented somewhere (couldn't really quite find 
>> out at the moment)? If not, do you know any good source that could assist 
>> me in the implementation?
>>
>
> You can factor polynomials with Nemo:
>
> julia> using Nemo
>
> julia> R = ResidueRing(ZZ, 2)
> Residue ring of Integer Ring modulo 2
>
> julia> S, x = PolynomialRing(R, "x")
> (Univariate Polynomial Ring in x over Residue ring of Integer Ring modulo 
> 2,x)
>
> julia> factor(x^23+1)
> Dict{Nemo.nmod_poly,Int64} with 3 entries:
>   x+1 => 1
>   x^11+x^9+x^7+x^6+x^5+x+1=> 1
>   x^11+x^10+x^6+x^5+x^4+x^2+1 => 1
>
> julia> length(factor(x^12345+1))
> 15
>
> Regarding implementation, the book Modern Computer Algebra by von zur 
> Gathen and Gerhard has a chapter on factoring polynomials over finite 
> fields, which might be helpful. Knuth also covers this topic.
>
> From memory, for Berlekamp's algorithm you need functions to compute the 
> modular product and GCD of polynomials, and a function to find the 
> nullspace of a matrix. Once you have those, Berlekamp's algorithm is 
> simple: you construct the matrix whose rows are the coefficients of a 
> sequence of polynomial powers modulo f, minus the identity matrix, then 
> compute the nullspace. Next, you pick a random linear combination of 
> nullspace basis vectors. There is a GCD test that tells you if the random 
> vector is a factor (or if the factorisation is complete). Continue picking 
> random vectors until done.
>
> The Cantor-Zassenhaus algorithm is an alternative to Berlekamp, but it is 
> slightly more complicated to code. If you need to factor polynomials of 
> very high degree, both algorithms can be sped up asymptotically using 
> various tricks.
>
> Nemo calls FLINT for polynomial factorisation, in which some of those 
> tricks are implemented.  It should be fast enough for most purposes, but 
> it's not really optimised for GF(2). Victor Shoup's C++ library NTL has a 
> faster implementation. I'm not aware of a Julia wrapper for NTL, but it 
> should be possible to call it with Cxx.
>
> Fredrik
>


[julia-users] Re: Generating MLS Sequences: modulo-2 polynomial factorization

2016-10-21 Thread CrocoDuck O'Ducks
Wow! Nice! Thank you very much, I will dive into the report.

As for non-linearity, I think I already read your comment when I was 
preparing my DSP assignment at uni. To detect and deal with non-linearity I 
have decide to stick with this swept sine method 
<http://ant-novak.com/swept-sine.php> though, as it is more intuitive for 
me. It also makes it pretty easy to identify Polynomial Hammerstein model 
filters.

On Friday, 21 October 2016 00:38:11 UTC+1, Matthew Wright wrote:
>
> Sorry I haven't got a Julia implementation but this report 
> <http://crc.stanford.edu/crc_papers/CRC-TR-04-03.pdf>, Primitive 
> Polynomial Generation Algorithms Implementation and Performance Analysis by 
> Nirmal R Saxena and Edward J McCluskey, gives efficient algorithms that 
> shouldn't be too hard to implement. The IntModN.jl 
> <https://github.com/andrewcooke/IntModN.jl> package might be useful to 
> you too, but I haven't used it myself.
>
> [BTW, if you're interested in the effects of nonlinearity on the MLS 
> identification procedure (which is the main topic of the Vanderkooy paper 
> you cite) you might want to read my comment on it in JAES 43(1-2) 48.]
>
> On Thursday, October 20, 2016 at 8:52:26 PM UTC+1, CrocoDuck O'Ducks wrote:
>>
>> Hi there cool people!
>>
>> I have implemented a simple MLS generator using linear feedback shift 
>> registers. I used as taps the ones provided in: 
>>
>> Vanderkooy, J. (1994). Aspects of MLS Measuring Systems. Journal of the 
>>> Audio Engineering Society, 42 (4), 219-231.
>>>
>>
>>  However, now that the theory is a little bit clearer to me, I would like 
>> to make it more general. The feedback taps are supplied by the coefficients 
>> of the primitive factors of the polynomial x^N + 1, where N is the length 
>> of the sequence (related to the number of registers). I would like to know 
>> from you guys if you think there is some Julia package I can use to 
>> calculate primitive factors of polynomials. As mentioned in the title, I 
>> need to perform this in modulo-2. Here 
>> <http://www.newwaveinstruments.com/resources/articles/m_sequence_linear_feedback_shift_register_lfsr.htm>
>>  
>> there are more info and the Berlekamp algorithm is mentioned. Has that 
>> algorithm already been implemented somewhere (couldn't really quite find 
>> out at the moment)? If not, do you know any good source that could assist 
>> me in the implementation?
>>
>

[julia-users] Generating MLS Sequences: modulo-2 polynomial factorization

2016-10-20 Thread CrocoDuck O'Ducks
Hi there cool people!

I have implemented a simple MLS generator using linear feedback shift 
registers. I used as taps the ones provided in: 

Vanderkooy, J. (1994). Aspects of MLS Measuring Systems. Journal of the 
> Audio Engineering Society, 42 (4), 219-231.
>

 However, now that the theory is a little bit clearer to me, I would like 
to make it more general. The feedback taps are supplied by the coefficients 
of the primitive factors of the polynomial x^N + 1, where N is the length 
of the sequence (related to the number of registers). I would like to know 
from you guys if you think there is some Julia package I can use to 
calculate primitive factors of polynomials. As mentioned in the title, I 
need to perform this in modulo-2. Here 

 
there are more info and the Berlekamp algorithm is mentioned. Has that 
algorithm already been implemented somewhere (couldn't really quite find 
out at the moment)? If not, do you know any good source that could assist 
me in the implementation?


[julia-users] Re: Plotting lots of data

2016-09-22 Thread CrocoDuck O'Ducks
Hi!

Thank you for your package. Yes, I managed to get my plots working with GR. 
For some reason now it is plotting all the lines, I don't get the weird 
white bands anymore.

On Wednesday, 21 September 2016 12:52:43 UTC+1, Igor wrote:
>
> Hello!
> did you managed to plot big data sets? You can try to use my small package 
> for this (  https://github.com/ig-or/qwtwplot.jl ) - it's very 
> interesting for me how it can handle big data sets.
>
> Best regards, Igor
>
>
> четверг, 16 июня 2016 г., 0:08:42 UTC+3 пользователь CrocoDuck O'Ducks 
> написал:
>>
>>
>> <https://lh3.googleusercontent.com/-8krr2WeB6rg/V2HDxDDxC2I/AHc/i9bcirHz4pgfCB14XpRB8dEKSUIbT7ZrQCLcB/s1600/10%2BkHz.png>
>>
>>
>> <https://lh3.googleusercontent.com/-bEY0cKEt1uc/V2HDtv11kEI/AHU/qcDhekOYjUsOsKoDJXnqPMuVCjZlFwuagCLcB/s1600/100%2BHz.png>
>> Hi, thank you very much, really appreciated. GR seems pretty much what I 
>> need. I like I can use Plots.jl with it. PlotlyJS.jl is very hot, I guess I 
>> will use it when I need interactivity. I will look into OpenGL related 
>> visualization tools for more advanced plots/renders.
>>
>> I just have a quick question. I just did a quick test with GR plotting 
>> two 1 second long sine waves sampled at 192 kHz, one of frequency 100 Hz 
>> and one of frequency 10 kHz. The 100 Hz looks fine but the 10 kHz plot has 
>> blank areas (see attached pictures). I guess it is due to the density of 
>> lines... probably solved by making the plot bigger?
>>
>>

[julia-users] Re: Few questions about methods and sub()

2016-07-16 Thread CrocoDuck O'Ducks
Hey!

I started having a deeper look at the code. I tried this first fix:

function xcorr_fix(u, v)

su = size(u, 1)
sv = size(v, 1)

if su < sv
# if u is a SubArray this will changes its type:
# u = [u; zeros(eltype(u),sv-su)]
# This avoids type instability, but forces array copy:
U = [u; zeros(eltype(u), sv - su)] 
elseif sv < su
# See above:
V = [v; zeros(eltype(v), su - sv)]
else
U = collect(u)
V = collect(v)
end

flipdim(conv(flipdim(U, 1), V), 1)

end

This appears to be somewhat effective, but there are few problems:

   - It defeats the purpose of passing views to the function, as a copy of 
   the parent arrays is performed. Is that right?
   - Passing SubArrays to conv() seems to produce type instability of p and 
   y variables.

Which makes me think that first conv() should be fixed (maybe adding a 
method for the Real signals case?). Second, I feel like views should be 
allowed to go all the way to fft() in order to have a performance boost by 
using them. Is there any way to append elements through SubArrays? I tried 
append!(), insert!() and push!() but none worked... Maybe I could overwrite 
to the input SubArrays new SubArrays of this kind?


sub([u.parent; zeros(whatever_pad_length)], :, 1)


I guess I will make more experiments to get comfortable with SubArrays. Any 
suggestion is welcome!



Re: [julia-users] Few questions about methods and sub()

2016-07-09 Thread CrocoDuck O'Ducks
Thanks!

I filed the issue right now. I will also have a deeper look at the source 
code <https://github.com/JuliaLang/julia/blob/master/base/dsp.jl>... 
although I am probably too much of a coding noob to figure out what to do 
(even with your precious hint).

On Saturday, 9 July 2016 14:15:29 UTC+1, Tim Holy wrote:
>
> Looks like xcorr has a type-instability. You can see this from 
>
> x = rand(10 * 192000); u = rand(10 * 192000, 3); 
> su = sub(u, :, 1); 
> @code_warntype xcorr(x, su) 
>
> Would you mind filing an issue? 
> https://github.com/JuliaLang/julia/issues/new 
> Alternatively, if you feel up to fixing it, the hint is "don't reuse 
> variable 
> names when the type might change." 
>
> Best, 
> --Tim 
>
> On Saturday, July 9, 2016 5:01:24 AM CDT CrocoDuck O'Ducks wrote: 
> > Hi there! 
> > 
> > I am making few experiments with simple methods. This method calculates 
> the 
> > delay between two signals (mono-dimensional arrays) using xcorr(): 
> > 
> > function finddelay{T <: Real}(x::AbstractArray{T, 1}, 
> u::AbstractArray{T, 1 
> > }) 
> > 
> > # Delay as lag between cross correlation from origin of time 
> > 
> > sₓᵤ = xcorr(x, u) 
> > 
> > ct_idx = cld(length(sₓᵤ), 2) 
> > 
> > _, pk_idx = findmax(sₓᵤ, 1) 
> > 
> > δ = ct_idx - pk_idx[1] 
> > 
> > return δ 
> > 
> > end 
> > 
> > Now, I would like to add a method that picks up a mono-dimensional array 
> x, 
> > a bi-dimensional array u, and then calculates the delay between x and 
> each 
> > of the columns of u.  I tried this: 
> > 
> > function finddelay{T <: Real}(x::AbstractArray{T, 1}, 
> u::AbstractArray{T, 2 
> > }) 
> > 
> > nᵤ = size(u, 2) 
> > 
> > δ = Array(Int, 1, nᵤ) 
> > 
> > for s = 1:nᵤ 
> > δ[s] = finddelay(x, u[:, s]) 
> > end 
> > 
> > return δ 
> > 
> > end 
> > 
> > It works good enough, here the benchmarks: 
> > 
> > x = rand(10 * 192000); u = rand(10 * 192000, 3) 
> > 
> > @benchmark finddelay(x, u) 
> >  Benchmark Results  
> >  Time per evaluation: 1.78 s [1.65 s, 1.91 s] 
> > Proportion of time in GC: 13.60% [10.52%, 16.69%] 
> > Memory allocated: 878.94 mb 
> >Number of allocations: 718 allocations 
> >Number of samples: 4 
> >Number of evaluations: 4 
> >  Time spent benchmarking: 9.21 s 
> > 
> > 
> >  However, by reading this cool book 
> > <https://www.packtpub.com/application-development/julia-high-performance>, 
>
> > I was suggested that using Array Views through sub() should reduce 
> memory 
> > usage. So I tried it: 
> > 
> > function finddelay{T <: Real}(x::AbstractArray{T, 1}, 
> u::AbstractArray{T, 2 
> > }) 
> > 
> > nᵤ = size(u, 2) 
> > 
> > δ = Array(Int, 1, nᵤ) 
> > 
> > xs = sub(x, :, 1) # I need all arguments of xcorr() to be Views 
> > 
> > for s = 1:nᵤ 
> > 
> > us = sub(u, :, s) 
> > 
> > δ[s] = finddelay(xs, us) 
> > 
> > end 
> > 
> > return δ 
> > 
> > end 
> > 
> > Which benchmarks as follows (same input arrays): 
> > 
> > @benchmark finddelay(x, u) 
> >  Benchmark Results  
> >  Time per evaluation: 2.44 s [2.41 s, 2.47 s] 
> > Proportion of time in GC: 12.55% [12.54%, 12.57%] 
> > Memory allocated: 1.07 gb 
> >Number of allocations: 17279216 allocations 
> >Number of samples: 3 
> >Number of evaluations: 3 
> >  Time spent benchmarking: 9.93 s 
> > 
> > 
> > 
> > I obtained the same benchmark by trying to copy the body of first method 
> in 
> > the loop of the second, adapting it to use with sub(). 
> > 
> > As such, I have few questions: 
> > 
> >- First of all, it is good practice to nest methods like this? 
> >- Second, why is sub associated with a huge increase in allocations? 
> Am 
> >I doing it wrong? Or maybe it is xcorr() that needs values and cannot 
> > work with references? 
>
>
>

[julia-users] Few questions about methods and sub()

2016-07-09 Thread CrocoDuck O'Ducks
Hi there!

I am making few experiments with simple methods. This method calculates the 
delay between two signals (mono-dimensional arrays) using xcorr():

function finddelay{T <: Real}(x::AbstractArray{T, 1}, u::AbstractArray{T, 1
})

# Delay as lag between cross correlation from origin of time 

sₓᵤ = xcorr(x, u)

ct_idx = cld(length(sₓᵤ), 2)

_, pk_idx = findmax(sₓᵤ, 1)

δ = ct_idx - pk_idx[1]

return δ

end

Now, I would like to add a method that picks up a mono-dimensional array x, 
a bi-dimensional array u, and then calculates the delay between x and each 
of the columns of u.  I tried this:

function finddelay{T <: Real}(x::AbstractArray{T, 1}, u::AbstractArray{T, 2
})

nᵤ = size(u, 2)

δ = Array(Int, 1, nᵤ)

for s = 1:nᵤ
δ[s] = finddelay(x, u[:, s])
end

return δ

end

It works good enough, here the benchmarks:

x = rand(10 * 192000); u = rand(10 * 192000, 3)

@benchmark finddelay(x, u)
 Benchmark Results 
 Time per evaluation: 1.78 s [1.65 s, 1.91 s]
Proportion of time in GC: 13.60% [10.52%, 16.69%]
Memory allocated: 878.94 mb
   Number of allocations: 718 allocations
   Number of samples: 4
   Number of evaluations: 4
 Time spent benchmarking: 9.21 s


 However, by reading this cool book 
, 
I was suggested that using Array Views through sub() should reduce memory 
usage. So I tried it:

function finddelay{T <: Real}(x::AbstractArray{T, 1}, u::AbstractArray{T, 2
})

nᵤ = size(u, 2)

δ = Array(Int, 1, nᵤ)

xs = sub(x, :, 1) # I need all arguments of xcorr() to be Views

for s = 1:nᵤ

us = sub(u, :, s)

δ[s] = finddelay(xs, us)

end

return δ

end

Which benchmarks as follows (same input arrays):

@benchmark finddelay(x, u)
 Benchmark Results 
 Time per evaluation: 2.44 s [2.41 s, 2.47 s]
Proportion of time in GC: 12.55% [12.54%, 12.57%]
Memory allocated: 1.07 gb
   Number of allocations: 17279216 allocations
   Number of samples: 3
   Number of evaluations: 3
 Time spent benchmarking: 9.93 s



I obtained the same benchmark by trying to copy the body of first method in 
the loop of the second, adapting it to use with sub().

As such, I have few questions:

   - First of all, it is good practice to nest methods like this?
   - Second, why is sub associated with a huge increase in allocations? Am 
   I doing it wrong? Or maybe it is xcorr() that needs values and cannot work 
   with references?
   


[julia-users] Re: Plotting lots of data

2016-06-15 Thread CrocoDuck O'Ducks





Hi, thank you very much, really appreciated. GR seems pretty much what I 
need. I like I can use Plots.jl with it. PlotlyJS.jl is very hot, I guess I 
will use it when I need interactivity. I will look into OpenGL related 
visualization tools for more advanced plots/renders.

I just have a quick question. I just did a quick test with GR plotting two 
1 second long sine waves sampled at 192 kHz, one of frequency 100 Hz and 
one of frequency 10 kHz. The 100 Hz looks fine but the 10 kHz plot has 
blank areas (see attached pictures). I guess it is due to the density of 
lines... probably solved by making the plot bigger?



[julia-users] Plotting lots of data

2016-06-12 Thread CrocoDuck O'Ducks
Hi there!

I have been experimenting a little with many plotting packages recently. 
Being used to Matlab PyPlot seemed to work well for me... until this bug 
 I did not figure out how 
to workaround. I often need to plot a lot of data. The fact is that I often 
work with sampled data, like audio. For example, I could have to plot 10 
seconds of 192 kHz sampled audio. Even when PyPlot was working it was hard 
to plot so many data: PyPlot was used to give up after few errors. I tried 
also other packages (Gadfly and few others) but seems like they really 
struggle to plot so much stuff: they often kinda freeze. I am not sure 
wether I am missing something or using the packages improperly or the 
packages are somewhat limited at this stage. I have resorted to export the 
data to .mat files and plot with matlab...

My question is:  how do you guys plot large data sets? Do you suggest a 
plot package in particular?


[julia-users] Re: Status of FEM packages

2016-06-12 Thread CrocoDuck O'Ducks
Cool stuff! Many thanks for the info, plenty of stuff to look at. Glad to 
see that a lot is going on.


[julia-users] Re: Status of FEM packages

2016-06-09 Thread CrocoDuck O'Ducks
Pretty cool! Thank you!

On Thursday, 9 June 2016 02:19:00 UTC+1, Paulo Jabardo wrote:
>
> I am implementing a spectral element code. For now it is only 1d but in 
> the next few weeks I will extend it to 2d/3d and write a Navier-Stokes 
> solver.
>
> https://github.com/pjabardo/HPFEM.jl
>


[julia-users] Re: Status of FEM packages

2016-06-08 Thread CrocoDuck O'Ducks
Thanks guys. Exciting times ahead. I will look into these packages as soon 
as I have a problem I can use to tackle them. The problems I am into now 
are about acoustics, so I guess that for the time being I will keep on 
using Elmer (which is pretty hot, by the way).


[julia-users] Status of FEM packages

2016-06-08 Thread CrocoDuck O'Ducks
Hi There!

I am involved into some multiphysics FEM problems I solve with ElmerFEM 
. Seems to me that everything being 
maintained is pretty much gravitating around JuliaFEM 
 and ElipticFEM 
. Any of you guys doing 
some FEM with Julia? If so, what do you use?


Re: [julia-users] Suppressing plot windows by default - is this purposeful?

2016-05-24 Thread CrocoDuck O'Ducks
Just a couple of cents from a newbie. I come from Matlab as well and I 
really love the way Julia works actually. There are many cases in Matlab 
where I get plots when I don't really ask for them and I end up with slow 
code and the need to close programmatically windows on the screen to avoid 
to have it covered with stuff. I am not sure I can find an example right 
now (I have few somewhere in my stuff) but functions like thd(), freqz() 
and so on generate plots that I too often have to deal with. I prefer to be 
able to programmatically decide whether or not display stuff instead to 
work around a default that easily slows things down and makes code less 
clean and harder to read, with "plotting correction" lines just in the 
middle of the ones doing the actual computations... Just my preference.

On Tuesday, 24 May 2016 08:28:46 UTC+1, NotSoRecentConvert wrote:
>
> plt[:show](), display(), or whatever is a minor nuisance so if it's the 
> developers' wishes that it is so then so be it. I would feature it 
> prominently in the documentation of the various plotting packages though. 
>
> plot()  -  Create a plot object in the background which can be later 
> displayed with display()
>
> A note about the differences between environments would also be important.
>
> The coding environment will also effect the usage of plot(). In the REPL 
> or using Atom/Juno plot() creates a plot in the background whereas IJulia 
> immediately displays the results inline. If an environment is not 
> displaying a plot as expected try using display() or checking the 
> defaults of the plotting package.
>
> Chris' suggestion about putting something in "Noteworthy Differences from 
> Other Languages" is good too.
>
> Tom, in what way am I forcing my perspective? Some portion of the Julia 
> community will see it this way so it's important to take it into 
> consideration.
>


[julia-users] Re: Good practices for constrained constructors

2016-04-27 Thread CrocoDuck O'Ducks
Thanks Jeffrey, that seems to work. Seems to me that to prevent Lint to 
complain you need a new() statement outside the if. I like the structure 
"if OK then new() else error" tho, it looks clearer. Your script seems to 
have just the same functionality anyway.

Thanks Stefan. Yeah, what you say makes sense: it does not seem that the 
design "if OK then new() else error" is bad. Still, I wanted to ask cause I 
am a total noob.


[julia-users] Good practices for constrained constructors

2016-04-26 Thread CrocoDuck O'Ducks
Hi there!

I was reading this 

 
and trying the code, which I saved into a file called test.jl:

type OrderedPair
  x::Real
  y::Real

  OrderedPair(x,y) = x > y ? error("out of order") : new(x,y)
end


If I use lintfile("test.jl") I get this:

ConstrTest.jl:5 E611 : constructor doesn't seem to return the constructed 
object

I am implementing a similar constructor for a project of mine and I was 
wondering whether, in general, the use of error() in the constructor is 
good practice or if I should prefer other ways to solve the problem.


Re: [julia-users] Cross-correlation: rfft() VS fft() VS xcorr() performances

2016-04-08 Thread CrocoDuck O'Ducks
I think so. MATLAB xcorr 
 implementation accepts 
a maxlag argument, which is probably handy for many people.

I don't think I will write my xcorr version. I will probably take a dirty 
shortcut: calculate the cross correlation only on windowed segments of 
signals. It should give the correct lag anyway.

On Friday, 8 April 2016 14:49:59 UTC+1, Stefan Karpinski wrote:
>
> Would it make sense to have a maxlag keyword option on xcorr to limit how 
> big the lags it considers are?
>
> On Friday, April 8, 2016, DNF  wrote:
>
>> The xcorr function calls the conv function, which again uses fft. If you 
>> know the general structure and length of your signals ahead of time, you 
>> can probably gain some performance by planning the ffts beforehand. I don't 
>> know why it doesn't work for you, but you could have a look in at conv in 
>> dsp.jl.
>>
>> If you *really* want to speed things up, though, you might implement 
>> your own xcorr.  xcorr dominates the runtime in your function, and if you 
>> know an upper bound on the signal lags, you can implement xcorr with a 
>> limited number of lags. By default xcorr calculates for all lags (in your 
>> case that's 2*48000*60-1 ~ 6million lags). If you know that the max lag is 
>> 1 second, you can save ~98% percent of the runtime of xcorr.
>>
>> A couple of other remarks:
>> * There's no need to put type annotations next to the function outputs, 
>> it's just visual noise
>> * Use ct_idx = cld(lₛ, 2) and forget about the mod.
>>
>

[julia-users] Re: Cross-correlation: rfft() VS fft() VS xcorr() performances

2016-04-08 Thread CrocoDuck O'Ducks
Oh cool, thanks for the tips. I'll dive in and be back!

On Friday, 8 April 2016 08:18:17 UTC+1, DNF wrote:
>
> The xcorr function calls the conv function, which again uses fft. If you 
> know the general structure and length of your signals ahead of time, you 
> can probably gain some performance by planning the ffts beforehand. I don't 
> know why it doesn't work for you, but you could have a look in at conv in 
> dsp.jl.
>
> If you *really* want to speed things up, though, you might implement your 
> own xcorr.  xcorr dominates the runtime in your function, and if you know 
> an upper bound on the signal lags, you can implement xcorr with a limited 
> number of lags. By default xcorr calculates for all lags (in your case 
> that's 2*48000*60-1 ~ 6million lags). If you know that the max lag is 1 
> second, you can save ~98% percent of the runtime of xcorr.
>
> A couple of other remarks:
> * There's no need to put type annotations next to the function outputs, 
> it's just visual noise
> * Use ct_idx = cld(lₛ, 2) and forget about the mod.
>


[julia-users] Cross-correlation: rfft() VS fft() VS xcorr() performances

2016-04-07 Thread CrocoDuck O'Ducks
Hey there cool people!

Seems like this topic will be pretty similar to this one 
.

So, I am trying to write my version of alignsignals 
.
 
In few words, I calculate the cross-correlation, find the peak, calculate 
its shift from the origin of time, use it to align the signals. I got three 
version of a function to achieve this, using xcorr, fft and rfft 
respectively. When using two signals one minute long, sampled at 48 kHz, 
they benchmark  as follows:

xcorr() version:

 Benchmark Results 
 Time per evaluation: 832.16 ms [663.40 ms, 1.00 s]
Proportion of time in GC: 15.94% [14.32%, 17.57%]
Memory allocated: 460.01 mb
   Number of allocations: 239 allocations
   Number of samples: 10
   Number of evaluations: 10
 Time spent benchmarking: 9.73 s

rfft() version:

 Benchmark Results 
 Time per evaluation: 1.01 s [654.63 ms, 1.36 s]
Proportion of time in GC: 12.11% [8.30%, 15.91%]
Memory allocated: 306.21 mb
   Number of allocations: 344 allocations
   Number of samples: 6
   Number of evaluations: 6
 Time spent benchmarking: 7.58 s

fft() version:

 Benchmark Results 
 Time per evaluation: 715.45 ms [536.86 ms, 894.04 ms]
Proportion of time in GC: 20.37% [16.49%, 24.24%]
Memory allocated: 569.87 mb
   Number of allocations: 276 allocations
   Number of samples: 13
   Number of evaluations: 13
 Time spent benchmarking: 10.56 s

It seems that the fft() version is the fastest while the rfft() version is 
the one that allocates less memory. According to my understanding, rfft() 
should also be faster with respect fft(). Unfortunately, the FFTW plan in 
the post I linked above does not seem to work. Are you able to suggest how 
to plan rfft() to make it faster? I will have to align many data 
collections sampled at 96 kHz minium, usually at least 30 s long. I plan to 
do it in a loopy structure, so it would be of great advantage to have 
quickest execution and lowest memory usage.

Here the code defining the functions:

function alignsignals{T <: Real}(x::Array{T, 1}, u::Array{T, 1})

# Delay as lag of cross correlation peak from origin of time.
lₓ = length(x)
lᵤ = length(u)
lₛ = lₓ + lᵤ - 1

sₓᵤ::Array{T, 1} = xcorr(x, u)

if mod(lₛ, 2) == 0
ct_idx = fld(lₛ, 2)
else
ct_idx = fld(lₛ, 2) + 1
end

_::Array{T, 1}, pk_idx::Array{Int, 1} = findmax(sₓᵤ, 1)

δ::Int = ct_idx - pk_idx[1]

# Align:
y = zeros(T, lᵤ)

if δ > 0
y[1:(lᵤ - δ)] = u[(δ + 1):lᵤ]
else
y[(-δ + 1):lᵤ] = u[1:(lᵤ - -δ)]
end

return y, δ

end

function rfftalignsignals{T <: Real}(x::Array{T, 1}, u::Array{T, 1}; ncores
::Int = 1)

lₓ = length(x)
lᵤ = length(u)

FFTW.set_num_threads(ncores)

x_nfft = nextprod(primes(10), lₓ)
u_nfft = nextprod(primes(10), lᵤ)
nfft = max(x_nfft, u_nfft)

X = rfft([x; zeros(nfft - lₓ)])
U = rfft([u; zeros(nfft - lᵤ)])

Sₓᵤ = conj(X) .* U

sₓᵤ = flipdim(fftshift(irfft(Sₓᵤ, 2 * length(Sₓᵤ) - 1)), 1)

lₛ = length(sₓᵤ)

if mod(lₛ, 2) == 0
ct_idx = fld(lₛ, 2)
else
ct_idx = fld(lₛ, 2) + 1
end

_::Array{T, 1}, pk_idx::Array{Int, 1} = findmax(sₓᵤ, 1)

δ::Int = ct_idx - pk_idx[1]

# Align:
y = zeros(T, lᵤ)

if δ > 0
y[1:(lᵤ - δ)] = u[(δ + 1):lᵤ]
else
y[(-δ + 1):lᵤ] = u[1:(lᵤ - -δ)]
end

return y, δ

end

function fftalignsignals{T <: Real}(x::Array{T, 1}, u::Array{T, 1}; ncores::
Int = 1)

lₓ = length(x)
lᵤ = length(u)

FFTW.set_num_threads(ncores)

x_nfft = nextprod(primes(10), lₓ)
u_nfft = nextprod(primes(10), lᵤ)
nfft = max(x_nfft, u_nfft)

X = fft([x; zeros(x_nfft - lₓ)])
U = fft([u; zeros(u_nfft - lᵤ)])

Sₓᵤ = conj(X) .* U

sₓᵤ = abs(flipdim(fftshift(ifft(Sₓᵤ)), 1))

lₛ = length(sₓᵤ)

if mod(lₛ, 2) == 0
ct_idx = fld(lₛ, 2)
else
ct_idx = fld(lₛ, 2) + 1
end

_::Array{T, 1}, pk_idx::Array{Int, 1} = findmax(sₓᵤ, 1)

δ::Int = ct_idx - pk_idx[1]

# Align:
y = zeros(T, lᵤ)

if δ > 0
y[1:(lᵤ - δ)] = u[(δ + 1):lᵤ]
else
y[(-δ + 1):lᵤ] = u[1:(lᵤ - -δ)]
end

return y, δ

end





[julia-users] Re: fft normalization

2016-03-20 Thread CrocoDuck O'Ducks
Hi there, sorry for the late reply.

I get slightly confused when using DSP.jl 
<https://github.com/JuliaDSP/DSP.jl>. I am trying to implement the inverse 
filter technique to measure linear systems impulse response. So, I define a 
filter with DSP.jl and the test signal x (a log swept sine), with sample 
rate fs. Then, I calculate the inverse filter z (which is an operation on 
x, pretty much a time reversal with an exponential amplitude envelope). If 
y is the output of the linear filter the impulse response is given by the 
convolution of y with z. So, I am running this algorithm and comparing with 
the results from impz in order to understand whether it works correctly. My 
results:


   - Manual Convolution:
   Y = (1 / fs) * fft(y)
   Z = (1 / fs) * fft(z)
   H = Y .* Z
   h = fs * ifft(H)
   - Convolution with conv():
   h = (1 / fs) * conv(y, z)
   - Impz:
   h = impz(filter, t)
   where t is the same time array resulting from the other operations.

What happens is that the first two operations agree, while the results from 
impz need to be multiplied by fs to agree with them. However, calling freqz 
produces good agreement:
H = freqz(filter, f, fs)
I am tempted to conclude that freqz makes the normalization (knowing fs), 
while impz doesn't. But I was also wondering whether my normalizations are 
wrong.

By the way, if I calculate h with conv() and then H as (1 / fs) * fft(h) 
the magnitudes are ok, but the phase of H is completely different from the 
expected one. In this case, the manual convolution works way better. Do you 
have an idea why this is happening? (maybe I will open a separate thread 
for this)

By the way, I am following this <http://ant-novak.com/swept-sine.php> to 
define test signal and inverse filter.


On Saturday, 19 March 2016 10:01:17 UTC, Jeffrey Sarnoff wrote:
>
> What do you feel is missing?
>
> On Monday, March 14, 2016 at 6:20:39 PM UTC-4, CrocoDuck O'Ducks wrote:
>>
>> Hi there cool people!
>>
>> I am making some Julia experiments around fft, conv and normalization. 
>> Long story short, by using signals for which it is simple to calculate 
>> analytically transforms and convolutions, I just play with normalization 
>> until I find match of the Julia calculated quantities with the analytical 
>> ones. Here what I found so far:
>>
>>- .fft output needs to be normalized by (1/fs), with fs the sample 
>>rate of the input signal (ifft will be then normalized by fs)
>>- conv output needs to be normalized by (1/fs) as well
>>
>> The fft normalization is not surprising (I was used to the same in 
>> Matlab). What do you think? It seems to be working ok but I also feel like 
>> I am missing something... Here the playground scripts:
>>
>>
>> # convplay.jl
>>
>> #=
>>   Make some experiment with known convolutions:
>> =#
>>
>> using PyPlot
>>
>> # Sampling Variables:
>> Fₛ = 96000 # Sample Rate
>>
>> # Time windows of the signals:
>> T₁ = -20 # seconds
>> T₂ = 20 # seconds
>>
>> # Define two rectangular pulses:
>> α = 2 # Amplitude
>> τ₁ = 4 # seconds
>> τ₂ = 6 # seconds
>>
>> a = 1 # Amplitude
>> t₁ = 0 # seconds
>> t₂ = 4 # seconds
>>
>> S₁ = ceil(T₁ * Fₛ) # Everything before the first sample is lost.
>> S₂ = floor(T₂ * Fₛ) # Everything after the last sample is lost.
>>
>> t = (1 / Fₛ) * (S₁:S₂)
>>
>> # Initialize and populate the signals:
>> x₁ = zeros(t)
>> x₂ = zeros(t)
>>
>> for s = 1:length(t)
>>
>>   if t[s] >= τ₁ && t[s] <= τ₂
>> x₁[s] = α
>>   end
>>
>>   if t[s] >= t₁ && t[s] <= t₂
>> x₂[s] = a
>>   end
>>
>> end
>>
>> # Convolve:
>> c = (1 / Fₛ) * conv(x₁, x₂) # 4, the correct peak of c, is found with 
>> this normalization.
>>
>> # fftplay.jl
>>
>> #=
>>   Have some PHUN with fft.
>> =#
>>
>> using PyPlot
>>
>> # Close existing plot windows:
>> close("all")
>>
>> # Define Signal stuff:
>> Fₛ = 96000   # Sample Rate. Hz.
>> P = 1# Amplitude
>> t₁ = -0.5# Initial instant of signal time window (with pads). s.
>> t₂ = 0.5 # Final instant of signal time window (with pads). s.
>> T = 3e-3 # Width of window containing the actual signal (N pulse). 
>> s. Centered on 0 s.
>>
>> # Define Processing Stuff:
>> Mprime = 10 # 
>> https://groups.google.com/forum/#!topic/julia-dev/MdTBxgVoab0
>> # ^^ fft is more efficient if the signal is operating on has a length 
>> that can
>> # be expressed as a product of small prime numbers:
>&

[julia-users] fft normalization

2016-03-14 Thread CrocoDuck O'Ducks
Hi there cool people!

I am making some Julia experiments around fft, conv and normalization. Long 
story short, by using signals for which it is simple to calculate 
analytically transforms and convolutions, I just play with normalization 
until I find match of the Julia calculated quantities with the analytical 
ones. Here what I found so far:

   - .fft output needs to be normalized by (1/fs), with fs the sample rate 
   of the input signal (ifft will be then normalized by fs)
   - conv output needs to be normalized by (1/fs) as well

The fft normalization is not surprising (I was used to the same in Matlab). 
What do you think? It seems to be working ok but I also feel like I am 
missing something... Here the playground scripts:


# convplay.jl

#=
  Make some experiment with known convolutions:
=#

using PyPlot

# Sampling Variables:
Fₛ = 96000 # Sample Rate

# Time windows of the signals:
T₁ = -20 # seconds
T₂ = 20 # seconds

# Define two rectangular pulses:
α = 2 # Amplitude
τ₁ = 4 # seconds
τ₂ = 6 # seconds

a = 1 # Amplitude
t₁ = 0 # seconds
t₂ = 4 # seconds

S₁ = ceil(T₁ * Fₛ) # Everything before the first sample is lost.
S₂ = floor(T₂ * Fₛ) # Everything after the last sample is lost.

t = (1 / Fₛ) * (S₁:S₂)

# Initialize and populate the signals:
x₁ = zeros(t)
x₂ = zeros(t)

for s = 1:length(t)

  if t[s] >= τ₁ && t[s] <= τ₂
x₁[s] = α
  end

  if t[s] >= t₁ && t[s] <= t₂
x₂[s] = a
  end

end

# Convolve:
c = (1 / Fₛ) * conv(x₁, x₂) # 4, the correct peak of c, is found with this 
normalization.

# fftplay.jl

#=
  Have some PHUN with fft.
=#

using PyPlot

# Close existing plot windows:
close("all")

# Define Signal stuff:
Fₛ = 96000   # Sample Rate. Hz.
P = 1# Amplitude
t₁ = -0.5# Initial instant of signal time window (with pads). s.
t₂ = 0.5 # Final instant of signal time window (with pads). s.
T = 3e-3 # Width of window containing the actual signal (N pulse). s. 
Centered on 0 s.

# Define Processing Stuff:
Mprime = 10 # https://groups.google.com/forum/#!topic/julia-dev/MdTBxgVoab0
# ^^ fft is more efficient if the signal is operating on has a length that 
can
# be expressed as a product of small prime numbers:
# p1^e1 * p2^e2 * ... ei integer exponents, pi prime numbes, i = 1,2,...
# Small: smaller than ten.

# Define the N pulse signal:
Δt = t₂ - t₁ # Global Signal Window. s.
Δtₛ = floor(Δt * Fₛ) # Same in samples.
t = (1 / Fₛ) * ((1 : Δtₛ) - floor(Δtₛ / 2)) # Time. Keep as range and don't 
waste memory. s.
# Signal ranges in samples:
_ , T₁ = findmin(abs(t - (-T / 2)))
_ , T₂ = findmin(abs(t - (+T / 2)))
# Define Signal:
x = zeros(t)
x[T₁ : T₂] = (-2 * P / T) * t[T₁ : T₂]
# Plot the signal:
figure(1)
plot(t, x)

# Prepare for transform:
nfft = nextprod(primes(Mprime), Δtₛ) # this is pretty much how to optimize 
fourier transform length.
x_pad = [x; zeros(nfft - length(x))]

# We are now ready for fft stuff:
# Set up multithread:
FFTW.set_num_threads(2) # I got two cores.

X = (1 / Fₛ) * fft(x_pad)

# Define Frequency Stuff:
f = linspace(0, Fₛ, nfft + 1) # A snake biting its tail...
f = f[1 : nfft]
# Nyquist Sample:
if mod(nfft, 2) == 0
  nyq = convert(Int, floor(nfft/ 2))
else
  nyq = convert(Int, floor(nfft/ 2) + 1)
end
# Positive frequencies and transforms:
f₊ = f[1 : nyq]
# Multiply for sqrt(2) so that the integral of the square magnitude over 
the positive frequency
# gives the correct total power:
X₊ = sqrt(2) * X[1 : nyq]

figure(2)
semilogx(f₊, abs(X₊))
xlim(xmax = 20e3)
ylim(ymax = 2e-3)

# For real signals the positive frequency trasform can be calculated 
directly:
X₊ᵈ = (sqrt(2) / Fₛ) * rfft(x_pad)
# This will contain the very last frequency sample (Nyquist frequency) as 
well:
f₊ᵈ = [f₊; Fₛ/2]

# Check if any differences:
isdif_transf = isequal(X₊, X₊ᵈ[1 : nyq])

# Try to reconstruct the original signal:
x₁ = Fₛ * ifft(X) # This has an unexpected very small imaginary part.
# A good way to get rid of the imaginary part appears to be irfft, that 
works assuming
# exact Hermitian symmetry. So, use only the positive frequency transform, 
However, you must
# include all the info (so, up to Nyquist frequency included):
x₂ = Fₛ * irfft(X[1 : (nyq + 1)], length(x))
# Similarly:
x₃ = (Fₛ / sqrt(2)) * irfft(X₊ᵈ, length(x))

# Check if any differences:
isdif_sig_1 = isequal(x, x₂)
isdif_sig_2 = isequal(x, x₃)

# It is to be expected that all the isdif variables will be false.
# Update the figures with the new plots:
figure(1)
plot(t, x₂)
plot(t, x₃)
xlabel(L"$t$ s", fontsize = 20)
ylabel(L"$x\left(t\right)$", fontsize = 20)
xlim(xmin = -T - T/3, xmax = T + T/3)
ylim(ymin = -P - P/4, ymax = P + P/4)
grid(b = true)

figure(2)
plot(f₊, abs(X₊ᵈ[1 : nyq]))
xlabel(L"$f$ Hz", fontsize = 20)
ylabel(L"\left|X\left(f\right)\right|", fontsize = 20)
grid(b = true)




[julia-users] Re: Realtime Audio Processing with PortAudio.jl

2016-03-14 Thread CrocoDuck O'Ducks
Brilliantly cool! Thanks for notifying the update! I will test it very 
soon. I guess it would be possible to use this technique also to synthesize 
something. Like "white noise until CTRL + C is pressed", so to speak..

On Sunday, 13 March 2016 19:54:48 UTC, Sebastian Kraft wrote:
>
> In the last days I added some code to allow realtime and asynchronous IO. 
> I think it is still quite hackish, but absolutely have no clue how to pass 
> something like a callback object in Julia. 
>
> The thing is I want to open a stream and pass it an initialized 
> "processor" object which is then doing the realtime processing in the 
> background until the stream is closed. My current solution looks like shown 
> in this example:
>
> https://github.com/seebk/PortAudio.jl/blob/master/examples/async_processing.jl
>
> Maybe the whole concept of async IO as I have planned it is not possible 
> in Julia?
>
> Any ideas how this could be done more in a smart (Julia style) way?
>
> Sebastian
>
> Am Montag, 22. Februar 2016 09:51:04 UTC+1 schrieb CrocoDuck O'Ducks:
>>
>> Cool! I will stay updated. Thanks!
>>
>> On Monday, 22 February 2016 07:50:39 UTC, Sebastian Kraft wrote:
>>>
>>> Please only stick to the examples given in the Readme.md file. Single 
>>> buffer IO is not working properly, yet. 
>>> My current plan is to extend open() so you can pass a callback function 
>>> which does the processing asynchronously. However, it does not seem to work 
>>> when C code is called in an @async block... Have to investigate that 
>>> further in the next days...
>>>
>>> Am Sonntag, 21. Februar 2016 16:44:50 UTC+1 schrieb CrocoDuck O'Ducks:
>>>>
>>>> Hi there!
>>>>
>>>> I got into PortAudio.jl <https://github.com/seebk/PortAudio.jl> 
>>>> recently (see this 
>>>> <https://groups.google.com/forum/#!topic/julia-users/ooyT55TI-jk> 
>>>> thread). I would like to code realtime digital filters. By that I mean 
>>>> that 
>>>> I would like to acquire data from sound-card input(s) and, while the 
>>>> acquisition goes on, filter the acquired samples and write the result to 
>>>> the sound-card output(s). Latency does not need to be low. I have mostly 
>>>> loudspeaker pre-hemphasis applications for acoustic measurements in mind 
>>>> for that, that means I will time align what I need later on... I think the 
>>>> PortAudio module should make me able to do that... but I have not figured 
>>>> out how. Here what I have (very naively) tried:
>>>>
>>>> iostream = open(devID, (max_input_channels, max_output_channels), 
>>>> sample_rate, buf_size)
>>>>
>>>> # Use a loop. Ctrl + C to exit the loop.
>>>>
>>>> doloop = true
>>>>
>>>> try
>>>>   while doloop
>>>>
>>>> ibuffer = read(iostream, buf_size) # Collect Input
>>>> obuffer = some_filtering_of(ibuffer) # Do some processing
>>>> write(iostream, obuffer) # Write it to output
>>>>
>>>>   end
>>>> catch excp
>>>>
>>>>   if isa(excp, InterruptException) # Ctrl + C generates an 
>>>> InterruptException
>>>> doloop = false
>>>>   end
>>>>
>>>> end
>>>>
>>>> Of course, there are many problems with that (it is not collecting 
>>>> consecutive buffers, for example). I guess it can help you understanding 
>>>> what I have in mind though.
>>>>
>>>

[julia-users] Re: Realtime Audio Processing with PortAudio.jl

2016-02-22 Thread CrocoDuck O'Ducks
Cool! I will stay updated. Thanks!

On Monday, 22 February 2016 07:50:39 UTC, Sebastian Kraft wrote:
>
> Please only stick to the examples given in the Readme.md file. Single 
> buffer IO is not working properly, yet. 
> My current plan is to extend open() so you can pass a callback function 
> which does the processing asynchronously. However, it does not seem to work 
> when C code is called in an @async block... Have to investigate that 
> further in the next days...
>
> Am Sonntag, 21. Februar 2016 16:44:50 UTC+1 schrieb CrocoDuck O'Ducks:
>>
>> Hi there!
>>
>> I got into PortAudio.jl <https://github.com/seebk/PortAudio.jl> recently 
>> (see this 
>> <https://groups.google.com/forum/#!topic/julia-users/ooyT55TI-jk> 
>> thread). I would like to code realtime digital filters. By that I mean that 
>> I would like to acquire data from sound-card input(s) and, while the 
>> acquisition goes on, filter the acquired samples and write the result to 
>> the sound-card output(s). Latency does not need to be low. I have mostly 
>> loudspeaker pre-hemphasis applications for acoustic measurements in mind 
>> for that, that means I will time align what I need later on... I think the 
>> PortAudio module should make me able to do that... but I have not figured 
>> out how. Here what I have (very naively) tried:
>>
>> iostream = open(devID, (max_input_channels, max_output_channels), 
>> sample_rate, buf_size)
>>
>> # Use a loop. Ctrl + C to exit the loop.
>>
>> doloop = true
>>
>> try
>>   while doloop
>>
>> ibuffer = read(iostream, buf_size) # Collect Input
>> obuffer = some_filtering_of(ibuffer) # Do some processing
>> write(iostream, obuffer) # Write it to output
>>
>>   end
>> catch excp
>>
>>   if isa(excp, InterruptException) # Ctrl + C generates an 
>> InterruptException
>> doloop = false
>>   end
>>
>> end
>>
>> Of course, there are many problems with that (it is not collecting 
>> consecutive buffers, for example). I guess it can help you understanding 
>> what I have in mind though.
>>
>

[julia-users] Realtime Audio Processing with PortAudio.jl

2016-02-21 Thread CrocoDuck O'Ducks
Hi there!

I got into PortAudio.jl  recently 
(see this  
thread). I would like to code realtime digital filters. By that I mean that 
I would like to acquire data from sound-card input(s) and, while the 
acquisition goes on, filter the acquired samples and write the result to 
the sound-card output(s). Latency does not need to be low. I have mostly 
loudspeaker pre-hemphasis applications for acoustic measurements in mind 
for that, that means I will time align what I need later on... I think the 
PortAudio module should make me able to do that... but I have not figured 
out how. Here what I have (very naively) tried:

iostream = open(devID, (max_input_channels, max_output_channels), 
sample_rate, buf_size)

# Use a loop. Ctrl + C to exit the loop.

doloop = true

try
  while doloop

ibuffer = read(iostream, buf_size) # Collect Input
obuffer = some_filtering_of(ibuffer) # Do some processing
write(iostream, obuffer) # Write it to output

  end
catch excp

  if isa(excp, InterruptException) # Ctrl + C generates an 
InterruptException
doloop = false
  end

end

Of course, there are many problems with that (it is not collecting 
consecutive buffers, for example). I guess it can help you understanding 
what I have in mind though.


[julia-users] Re: Simultaneous audio playback / recording.

2016-02-15 Thread CrocoDuck O'Ducks
Sorry for the late reply, I am taking quite a lot of time to properly 
understand Julia while I learn it. Sir, your module is very nice! It seems 
to be working fine and I was able to get started pretty soon. JACK support! 
YUM!!! I already see how to design my script: make it write the .jackdrc 
file, make it launch jack, find the correct device ID and unleash the 
measurement process.

Thanks for your module, I think it will be very useful for me. Keep on the 
good work!

On Sunday, 7 February 2016 16:31:57 UTC, Sebastian Kraft wrote:
>
> Am Sonntag, 7. Februar 2016 16:51:35 UTC+1 schrieb CrocoDuck O'Ducks:
>>
>> I am starting looking into your module and... ehm... what is the proper 
>> way to install it?
>>
>
> It's not a registered package, yet. Therefore, it requires the following 
> steps:
>
> Pkg.clone("https://github.com/seebk/PortAudio.jl.git;)
> Pkg.build("PortAudio")
>
>  
>


[julia-users] Re: Simultaneous audio playback / recording.

2016-02-07 Thread CrocoDuck O'Ducks
I am starting looking into your module and... ehm... what is the proper way 
to install it?

On Wednesday, 3 February 2016 18:54:49 UTC, Sebastian Kraft wrote:
>
>
> Hi,
>
> in the last weeks I started a PortAudio.jl package (based on parts of the 
> AudioIO.jl package). It is still under development and far from perfect, 
> but should already work well for basic audio IO.
>
> https://github.com/seebk/PortAudio.jl
>
> Sebastian
>


[julia-users] Re: Simultaneous audio playback / recording.

2016-02-07 Thread CrocoDuck O'Ducks
Thanks! The module is installed. I will make some experiment and report 
back!

On Sunday, 7 February 2016 16:31:57 UTC, Sebastian Kraft wrote:
>
> Am Sonntag, 7. Februar 2016 16:51:35 UTC+1 schrieb CrocoDuck O'Ducks:
>>
>> I am starting looking into your module and... ehm... what is the proper 
>> way to install it?
>>
>
> It's not a registered package, yet. Therefore, it requires the following 
> steps:
>
> Pkg.clone("https://github.com/seebk/PortAudio.jl.git;)
> Pkg.build("PortAudio")
>
>  
>


[julia-users] Re: Simultaneous audio playback / recording.

2016-02-04 Thread CrocoDuck O'Ducks
Wow! Seems it could do the job. I think I will test it soon. Thanks!

On Wednesday, 3 February 2016 18:54:49 UTC, Sebastian Kraft wrote:
>
>
> Hi,
>
> in the last weeks I started a PortAudio.jl package (based on parts of the 
> AudioIO.jl package). It is still under development and far from perfect, 
> but should already work well for basic audio IO.
>
> https://github.com/seebk/PortAudio.jl
>
> Sebastian
>


Re: [julia-users] Simultaneous audio playback / recording.

2016-01-24 Thread CrocoDuck O'Ducks
Ok cool people! I got the first prototype working:

# sinegen.jl

#=
  Just a simple generator of sine waves. It even records stuff!
=#

using WAV

# User defined stuff:

# Define Sample Frequency:
Fs = 96000# Hz
# Define Frequency of Wave:
f = 440 # Hz
# Define Duration:
T = 10 #s

# Define Audio File variables:
nbits = 32
# Format:
fformat = "wav"

# Define Audio Driver and AudioDevice for playback
adriver = "alsa"
adev = "hw:1"

# Execute:

# Time window:
t = (1/Fs) * collect(0:(T*Fs - 1)) #s
# Signal:
y = sin(2π*f*t)

# File Name:
fname = "Sine $f.$fformat"
# Save the sine wave:
wavwrite(y,Fs,nbits,fname)

# Set Driver and device for sox:
ENV["AUDIODRIVER"] = adriver
ENV["AUDIODEV"] = adev

# And now, play it with sox from command line.
# run(`play -b $nbits -r $Fs $fname`)

# To record for a lenght of time T:
# run(`rec -b $nbits -r $Fs Output.wav trim 0 $T `)

# To play and record simultaneously:
run(`play -b $nbits -r $Fs $fname` & `rec -b $nbits -r $Fs Output.wav trim 
0 $T `)

It is using sox as suggested above. Do you have any particular suggestion 
about calling these two commands simultaneously in the last line?


On Wednesday, 20 January 2016 00:15:45 UTC, CrocoDuck O'Ducks wrote:
>
> Wow! Sounds amazing! Can't wait for that!
>
> On Monday, 18 January 2016 23:42:30 UTC, Spencer Russell wrote:
>>
>> AudioIO is going to be going deprecated soon in favor of a family of 
>> packages that are each a bit more focused and simpler to interface with. 
>> They’re not quite release-ready but have been making a lot of progress 
>> lately, and I wanted folks to know what’s coming before you sink a bunch of 
>> time into working with the AudioIO implementation. Currently there’s a 
>> mostly working JACK library, and I’ll probably port over the PortAudio 
>> support from AudioIO after that.
>>
>> -s
>>
>> On Jan 17, 2016, at 1:30 PM, CrocoDuck O'Ducks <crocoduc...@gmail.com> 
>> wrote:
>>
>> Hi there!
>>
>> I have a number MATLAB scripts that I use for electro-acoustic 
>> measurements (mainly impulse responses) and I would like to port them to 
>> JULIA. I also written the data acquisition in MATLAB. It works by streaming 
>> the test signal to the soundcard outputs while recording from the soundcard 
>> inputs. I would like to implement that as well. I was looking at AudioIO 
>> but there are few issues:
>>
>>
>>- I cannot find documentation/examples on how to record from 
>>soundcard input.
>>- I cannot find documentation/examples on selecting the audio device 
>>to use.
>>- I cannot find documentation/examples on setting sampling variables 
>>(it is in my best interest to use the highest sample rate available).
>>
>> Are these things possible with JULIA? I think I can use aplayer and 
>> arecord through JULIA (I am on Linux), but I was wishing to have all the 
>> code contained within JULIA.
>>
>> Many thanks, I hope you can point me in the right direction.
>>
>>
>>

Re: [julia-users] Simultaneous audio playback / recording.

2016-01-19 Thread CrocoDuck O'Ducks
I forgot about sox. Good point. I will look into and be back if I need your 
code as an example. Thanks!

On Monday, 18 January 2016 22:33:20 UTC, Miguel Bazdresch wrote:
>
> An alternative would be to interact with the sound card using sox (
> http://sox.sourceforge.net/). In the past, I used sox from Octave to 
> record and play audio simultaneously. Let me know if you'd like to see the 
> code; I can probably dig it out of my old backups.
>
> -- mb
>
> On Sun, Jan 17, 2016 at 1:30 PM, CrocoDuck O'Ducks <crocoduc...@gmail.com 
> > wrote:
>
>> Hi there!
>>
>> I have a number MATLAB scripts that I use for electro-acoustic 
>> measurements (mainly impulse responses) and I would like to port them to 
>> JULIA. I also written the data acquisition in MATLAB. It works by streaming 
>> the test signal to the soundcard outputs while recording from the soundcard 
>> inputs. I would like to implement that as well. I was looking at AudioIO 
>> but there are few issues:
>>
>>
>>- I cannot find documentation/examples on how to record from 
>>soundcard input.
>>- I cannot find documentation/examples on selecting the audio device 
>>to use.
>>- I cannot find documentation/examples on setting sampling variables 
>>(it is in my best interest to use the highest sample rate available).
>>
>> Are these things possible with JULIA? I think I can use aplayer and 
>> arecord through JULIA (I am on Linux), but I was wishing to have all the 
>> code contained within JULIA.
>>
>> Many thanks, I hope you can point me in the right direction.
>>
>
>

Re: [julia-users] Simultaneous audio playback / recording.

2016-01-19 Thread CrocoDuck O'Ducks
Wow! Sounds amazing! Can't wait for that!

On Monday, 18 January 2016 23:42:30 UTC, Spencer Russell wrote:
>
> AudioIO is going to be going deprecated soon in favor of a family of 
> packages that are each a bit more focused and simpler to interface with. 
> They’re not quite release-ready but have been making a lot of progress 
> lately, and I wanted folks to know what’s coming before you sink a bunch of 
> time into working with the AudioIO implementation. Currently there’s a 
> mostly working JACK library, and I’ll probably port over the PortAudio 
> support from AudioIO after that.
>
> -s
>
> On Jan 17, 2016, at 1:30 PM, CrocoDuck O'Ducks <crocoduc...@gmail.com 
> > wrote:
>
> Hi there!
>
> I have a number MATLAB scripts that I use for electro-acoustic 
> measurements (mainly impulse responses) and I would like to port them to 
> JULIA. I also written the data acquisition in MATLAB. It works by streaming 
> the test signal to the soundcard outputs while recording from the soundcard 
> inputs. I would like to implement that as well. I was looking at AudioIO 
> but there are few issues:
>
>
>- I cannot find documentation/examples on how to record from soundcard 
>input.
>- I cannot find documentation/examples on selecting the audio device 
>to use.
>- I cannot find documentation/examples on setting sampling variables 
>(it is in my best interest to use the highest sample rate available).
>
> Are these things possible with JULIA? I think I can use aplayer and 
> arecord through JULIA (I am on Linux), but I was wishing to have all the 
> code contained within JULIA.
>
> Many thanks, I hope you can point me in the right direction.
>
>
>

[julia-users] Re: Simultaneous audio playback / recording.

2016-01-18 Thread CrocoDuck O'Ducks
Thanks for the tips. I guess this is a sign of destiny: time for me to look 
deep into PortAudio.

On Sunday, 17 January 2016 22:01:04 UTC, STAR0SS wrote:
>
> When dealing with small packages you often need to look at the code, 
> because the documentation is sometimes lacking.
>
> AudioIO.jl uses the C library PortAudio, so in theory anything that can be 
> done with PortAudio can be done in Julia, you need
> to have the right wrappers for the C functions. It seems AudioIO.jl 
> implementation isn't complete, so probably some things cannot
> be done currently without getting your hands dirty (meaning reading the 
> Julia code and the PortAudio doc and trying to understand what's going on).
>
> if you look the constructor of PortAudioStream you can see you can change 
> the sampling rate there (the PortAudioStream can then be passed to play it 
> seems), 
> however it call the default stream (Pa_OpenDefaultStream) so I'm not sure 
> you can select the audio device.
>
> There's also a get_portaudio_devices function, but it's not used anywhere 
> it seems (you can search the repository to see where things are used)
>
>
> https://github.com/ssfrr/AudioIO.jl/blob/26fd1fdf232fbe8a0115203f8c253c8cff7a0827/src/portaudio.jl#L53
>
> I don't know much about PortAudio, so take that with a grain of salt, I'm 
> just guessing.
>


[julia-users] Simultaneous audio playback / recording.

2016-01-17 Thread CrocoDuck O'Ducks
Hi there!

I have a number MATLAB scripts that I use for electro-acoustic measurements 
(mainly impulse responses) and I would like to port them to JULIA. I also 
written the data acquisition in MATLAB. It works by streaming the test 
signal to the soundcard outputs while recording from the soundcard inputs. 
I would like to implement that as well. I was looking at AudioIO but there 
are few issues:


   - I cannot find documentation/examples on how to record from soundcard 
   input.
   - I cannot find documentation/examples on selecting the audio device to 
   use.
   - I cannot find documentation/examples on setting sampling variables (it 
   is in my best interest to use the highest sample rate available).

Are these things possible with JULIA? I think I can use aplayer and arecord 
through JULIA (I am on Linux), but I was wishing to have all the code 
contained within JULIA.

Many thanks, I hope you can point me in the right direction.