Next  |  Prev  |  Up  |  Top  |  REALSIMPLE Top

Fitting Filters in Matlab

  1. Measure the decay rate of each partial overtone, and calculate the desired amplitude response for the loop filter in a digital waveguide model. Take the EDR, and using the rate of decay of the signal, compute the necessary gains for the harmonic series of the signal. We will have code samples for fitting a line to the dB decay of one frequency in a later section.

    Figure 4 shows the resulting desired magnitude response of our loop filter as calculated from the EDR..

    Figure 4: Desired magnitude response of our loop filter.
    \resizebox{4.3in}{!}{\includegraphics{\figdir /06-05-22-04-desired-mag-response.eps}}

  2. Convert the desired amplitude response to minimum-phase form.4This simplifies complex behavior involving the phase of the excitation signal with the fitted filter. Figure 5 shows the magnitude response after converting to minimum phase.
    Figure 5: The desired magnitude response after converting to minimum phase
    \resizebox{4.3in}{!}{\includegraphics{\figdir /06-05-22-05-desired-mag-response-conv-min-phase.eps}}
    Figure 6 shows the resulting minimum-phase response.
    Figure 6: The phase response after converting to minimum phase.
    \resizebox{4.3in}{!}{\includegraphics{\figdir /06-05-22-06-desired-ang-response-conv-min-phase.eps}}

  3. Design the loop filter to approximate the minimum-phase frequency response. Figure 7 shows the result obtained for this example using invfreqz in Matlab (or Octave Forge).
    Figure 7: Magnitude and Phase responses of the fitted filter using invfreqz
    \resizebox{4.3in}{!}{\includegraphics{\figdir /06-05-22-07-freqz-from-invfreqz.eps}}

    The code segments demonstrates how we fitted a filter using invfreqz and stmcb.

    % Note that Hmin corresponds to the response of the minimum-phase filter
    % that we want to fit to obtain filter parameters using invfreqz
    wH = (0:Npt/2)*2*pi/Npt; % sampled normalized radian frequency axis
    wt = 1 ./ [wH(2),wH(2:end)]; % weight fn: boost low freqs, avoid 0
    [B,A] = invfreqz(Hmin(1:Npt/2+1),wH,25,25,wt);
    figure;freqz(B,A)
    title('freqz of filter obtained using invfreqz');
    
    % % Obtain filter parameters using stmcb
    hdesired = real(ifft(Hmin));
    figure;plot((0:length(hdesired)-1)/fs,(hdesired));
    title('impulse response of min phase filter')
    xlabel('seconds');
    ylabel('amplitude');
    [stmb,stma] = stmcb(hdesired,40,40);
    figure;freqz(stmb,stma)
    title('freqz of filter obtained using stmcb');
    

    Figure 8 shows the result obtained for this example using stmcb from the Matlab Signal Processing Tool Box.

    Figure 8: Magnitude and phase response of the filter
    \resizebox{4.3in}{!}{\includegraphics{\figdir /06-05-22-09-freqz-from-stmcb.eps}}

    Plotting the results in Matlab is simple, as the following code segments shows. Note that Matlab's freqz function takes as arguments the coefficients of a filter plots the magnitude and phase responses of the described filter.

    figure;freqz(B,A)
    title('freqz of filter obtained using invfreqz');
    
    figure;freqz(stmb,stma)
    title('freqz of filter obtained using stmcb');
    


Next  |  Prev  |  Up  |  Top  |  REALSIMPLE Top

Download vguitar.pdf

``REALSIMPLE Basic Virtual Acoustic Guitar Lab'', by Nelson Lee and Julius O. Smith III,
REALSIMPLE Project — work supported by the Wallenberg Global Learning Network .
Copyright © 2016-05-13, by Nelson Lee and Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA