View Single Post
  #33  
Old 01-07-2020, 11:50 AM
jonfields45 jonfields45 is offline
Registered User
 
Join Date: Jun 2011
Location: Allentown, PA
Posts: 4,605
Default A Baby Step Toward IR Generation Code in Matlab

I generated my first IR with Matlab this morning.

Nothing too exciting yet... I took a single 2^17 sample segment (about 3 seconds, starting about 6 seconds in) out of the RainSong CH-PA/HFN recording I sent Cuki79, Blackman windowed it (a slow rise and fall in volume at the beginning and end of the segment) as advised by Cuki79, and did the simplest FFT, divide, iFFT, and truncate to 2048 long.

As soon as I've got the code integrating multiple segments, generating the minimum phase version, and creating low/high cut versions; I'll be looking for some input from volunteers.

I tried it out today with Reaper's Reaverb effect and it sounded good to me. I'm not ready to take the trouble to download it to my HX Stomp quite yet.

I need to pony up another $50 for the DSP package to generate the minimum phase version. I might port my code to Octave (free) first, but the Matlab environment is very friendly with tons of useful error reporting and good tutorial information.

For the Google crawler and hopefully someone is interested (closing parenthesis on 'audiowrite' are being dropped by the AGF software):

input = 'input.wav' % input file
ss = (2^17); % segment size for analysis
n = 3; % index into wave file in segments
count = 0; % count variable for processed segments
pupl = 1; % pickup left, mic right
window = blackman(ss); % window function
accir = zeros(ss,1); % initialize IR accumulator

% to caclulate minimum phase version 'firminphase' requires DSP System Toolbox

start = ((n-1) * ss);
finish = ((n * ss) -1);
index = [start, finish];
[s,fs] = audioread(input,index); % load segment
smax = max(max(s)) % print max
clip = (smax > 0.999); % check for clipping
if clip == 0 % no clipping
count = count + 1;
if pupl == 1 % seperate pickup/mic & window
pickup = s(:,1) .* window;
mic = s(:,2) .* window;
else
pickup = s(:,2) .* window;
mic = s(:,1) .* window;
end
audiowrite('pickup.wav',pickup,fs); % output windowed wave file
audiowrite('mic.wav',mic,fs); % output windowed wave file
pupfft = fft(pickup); % Fourier transform pickup
micfft = fft(mic); % Fourier transform mic
irfft = micfft ./ pupfft; % divide mic/pup for IR calculation
ir = ifft (irfft); % inverse Fourier transform to calculate IR
ir = ir(1:2048); % truncate IR to 2048 terms
maxir = max(ir) % check IR for clipping
audiowrite('ir.wav',ir,fs); % write out IR
ir(1:10) % check for leading zeros
end

Quote:
Originally Posted by jonfields45 View Post

Edited plan:

I am currently using a Cuki79 IR (minimum phase version) with my HFN. I think the HFN sounds fine without the IR, but with the IR I get a fuller slightly more pleasant tone. In my duo it is probably only noticeable to me.

I found using an IR in a "louder not solo application" facilitated by direct control of the lower resonances in the 80-250 Hz range, which I am doing with two parametric EQ notches.
  1. Very large segments and optimal window function to minimize segmentation and frequency domain quantization effects.
  2. Support for IR loaders without low/high cut and/or parametric EQ.

A plan...

• Mic and guitar sample
o determine sample rate
• Segment sample into 3 second intervals
• Skip 6 seconds into sample
o scan mic and pickup segments for max > 0.999
o skip to next segment if clipping detected
o skip 1 segments, repeat and identify 10 segments of mic and guitar with no clipping
• Blackman window each chosen segment (as per Cuki)
• FFT all 10 segment pairs
• Coefficient by Coefficient divide mic FFT by corresponding pickup FFT
• Accumulate quotients
• Scale accumulated quotient by 1/10
• Create minimum phase version
• Option: set quotient coefficients to 1 below 100 and above 10 kHz
• Inverse FFT
• Normalize results to some reasonable gain compatible with 16 bit samples
• Truncate to 2048 points.
__________________
jf45ir Free DIY Acoustic Guitar IR Generator
.wav file, 30 seconds, pickup left, mic right, open position strumming best...send to direct email below
I'll send you 100/0, 75/25, 50/50 & 0/100 IR/Bypass IRs
IR Demo, read the description too: https://youtu.be/SELEE4yugjE
My duo's website and my email... [email protected]

Jon Fields

Last edited by jonfields45; 01-07-2020 at 12:00 PM.
Reply With Quote