Turntable -> PC (RIAA EQ done by software filter)

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Here is the BLT of the 318us/3180us shelf

H(z) = (1+((1-2Tzfs)/(1+2Tzfs)) z-1)/((1+((1-2Tpfs)/(1+2Tpfs)) z-1)

with scaling: H(z) = H(z) * (1+2Tzfs)/(1+2Tpfs)

For 48k, Tz = 318us, Tp = 3180us

H(z) = (31.528/306.28) * ((1-29.528/31.528z-1))/(1-(304.28/306.28)z-1

H(z) = .1029385 (1-.9365643z-1)/(1-.99347z-1)

A complete composite (including the 75us filter from my previous post:

H(z) = .02170972 (1-.786543z-1-.1404815z-2)/(1-1.750935z-1+.7525189z-2)

This looks reasonable accurate but I haven't compared in fine detail. The same approach should give very good results are higher sample rates.

The filter has unity gain at 0 Hz

Al Clark
 
danville said:
I am very interested in Remez's second algorithm as referenced by Robert Orban. The results of this method are very impressive.

I was wondering if anyone knows of a C program, Matlab program or a good tutorial article on this method.

....



Hmm... I googled these articles earlier (there are plenty of links returned ..) ... there are some books mentioned and even fortran implementation (didn't found that one but I suppose it's there somewhere)

- http://portal.acm.org/citation.cfm?id=362890
- http://mathworld.wolfram.com/RemezAlgorithm.html
- http://freespace.virgin.net/boost.regex/toolkit/html/math_toolkit/backgrounders/remez.html
- http://elib.zib.de/netlib/toms/414 (source code, but is it the min-max method?)
- lisp code for Rabiner's (1975) Fortran Implementation (mentioned in Wolframs site) - http://www.dxarts.washington.edu/docs/clmman/fltdes.lisp


but, ... too hard reading for me ;).


jiitee
 
Hi danville -

Thanks for your procedure, it works quite nicely, and is straightforward, wish the compensating zero could be gotten without guesswork but it's not so critical.

For 48kHz z-plane I ended up with:

poles = 0.99347, 0.757465 from bilinear transform and impulse invariance

zeroes = 0.9365643, -0.13 from bilinear transform and your guidelines

gain = 0.02209 to match s-plane function which has gain = 0dB at 0Hz, can be scaled to suit.

The biquad coefficients can be calculated straightforwardly:

b0 = 0.02209 b1 = -0.0178192 b2 = 0.00268986 a1 = -1.750935 a2 = 0.7525188, or

(0.02209*z^2 - 0.0178192*z +0.00268986)/(z^2 - 1.75094*z + 0.752519)

Frequency response is +/- 0.02dB to 5kHz, +/- 0.04dB to 15kHz, +/- 0.25dB to 20kHz. I think this is the best FR I've seen in a single 48kHz biquad below 15kHz. Using -0.15 instead of -0.13 reduces the 20kHz error but droops by 0.1dB between 10 and 15kHz, this may not be significant. Phase response is +/- 1.5 deg to 15kHz after incorporating an 8.5us delay into the phase calculation.

Hi jiitteepee -

The articles you googled refer to FIR filters, not the IIR filters we have been discussing here. I have not found any references to Remez applied to IIR filters.

This raises a point - why not consider FIR filters?

I think IIR is preferred here since we want to duplicate the magnitude and phase response of an RIAA eq. An FIR filter can be easily made to duplicate the magnitude response but most FIR filters design procedures yield linear phase, not the minimum phase of an analog filter, while IIR design procedures usually yield minimum phase. Also IIR filters require less computing power but this does not seem to be an issue with 21st century PCs.
 
I've looked at jcx's suggestion of analog 50Hz pole, digital 500Hz zero/2122Hz pole. The digital part can be formed very precisely with minor adjustment to danville's procedure, just get the pole by impulse invariance and the zero by bilinear transform, calculations are completely closed-form, in fact they were done earlier.

For 48kHz,

pole = 0.757465 zero = 0.9365643

gain = 0.903 for 0db at ~ 24kHz

biquad coefficients:

b0 = 0 b1 = 0.9035 b2 = -0.846186

a0 = 0 a1 = 1 a2 = -0.757645

Frequency response of the digital vs analog is +/- 0.02dB to 20kHz. Phase response is +/- 0.1deg after a 0.4us advance.
 
When you add the zero, you get a compromise with the freq response. The .15 gives a better fit at higher frequency, the smaller .13 fits better at lower numbers. You could create a very simple optimizing procedure by just measuring the variation at various points. For example, the test frequencies might be placed logarithmically and then minimized. In all cases, you will have deviations from ideal since the digital response cannot follow thew s plane exactly. This is very easy to see when you plot the data.

The BLT will always cause the response to fall too fast and the impulse invariant too slow. The zeros are at -1 and 0 respectively.

It is also easy to see that if you are willing to increase the sample rate that you can meet the curve quite well. I used 48k because it was the hardest. I would probably never use it otherwise since all good audio ADCs can sample at least 96k and many at 192k.

You don't want to scale the coefficients before the filter if you are using a fixed point implementation. It will waste bits of precision. It doesn't matter in a floating point realization. The fixed point DFI will work better however.

You can get an exact solution algebraically if you are willing to do a bit of math. It will be valid at only one point however.

Assume as a starting place that the "a" coefficient is determined by the impulse invariant method. This will determine the -3dB point. The actual -3dB corner lies somewhere between the pole as determined by BLT and II, but it will be closer to the II calculation. This is because the zero is closer to 0 than -1. Moving it slightly toward the BLT solution will will almost no effect when the corner is still relatively far from nyquist.

You next pick a frequency where you want the digital filter to match the analog filter exactly. For example, you might pick 3*fc (magnitude will be 1/SQRT(10)) or something higher. You can then calculate the zero to match this condition. It will deviate at all other frequencies however. Its just a matter of choosing where you want to tolerate the most mismatch.

The important thing to remember is that digital filters map unambiguously into a frequency range of fs/2 whereas analog filters map to infinity. You can't match the filters perfectly (Blame the universe for being unfair if you like).

You may also have noticed that nothing in my procedure addresssed the phase response.

The crazy thing about RIAA is that it implies that the roll off should be -6dB forever. This means that the recording needed to be boosted by +6dB forever. I would hate to have to deal with a 1GHz bandwidth on an LP. This means that a perfect RIAA filter combined with an RIAA encoded source is never going to yield a flat frequency response because the source will always run at of boost at some high frequency.

I did the exercise in part to show that you don't necessarily need fancy computer programs or esoteric math skills to address this problem in a reasonable way.

BTW, I still think a good analog implemention will probably be better.

The citations were mostly for remez's more famous exchange algorithm that is the basis for the PM FIR filter method. The real papers were only available by spending money to download. I would still like a copy or a program, etc.,

You can also use an FIR filter to solve this problem. The coefficients of the FIR would be the impulse response of an RIAA filter. It will be very large!. I suppose, you could do just the 75uS portion but it will still be large. It would be easier to interpolate to a much higher frequency (do the 318/3180 pair first), and then use another IIR filter for the 75uS. You want to remember that FIR are as the name suggests - finite length. The IIR is not actually infinite in practice, at some point you run out of bits, nevertheless, an IIR approximation is going to be substantially easier to meet the desired performance.

Keep having fun, I am.


Al Clark
 
Thanks again for your interest and information, as I noted before I'm no DSP expert, and my interest is personal rather than professional, but I've designed and built a number of phono stages, mostly active feedback with a single eq network using op amps or discrete transistors but also some tube, and I've done some eq tweaking in simulation and by hand with signal generators and inverse RIAA networks.

Over time I've been doing more and more transfers to digital so I've been investigating digital equalization, starting with frequency response correction based on test records and leading to digital phono eq. I've tried to tweak the analog networks to add correction with limited success.

Since an analog preamp to match the phono cartridge output to an ADC is needed anyway, digital phono eq may seem like an academic exercise, but it may be useful as part of a comprehensive eq system for transfers. The open source sound editor Audacity incorporates "Nyquist" which supports simple plugin programming including IIR biquads, the numerical design is the hard part.

The information in this thread with design data of digital filters based on the s-plane poles/zeroes defining RIAA eq has been difficult to locate online. Your procedure is easily incorporated into a spreadsheet which I will get around to writing sometime.

The 48kHz single biquad results are much better than I expected and quite adequate, phono cartridge variations will be greater than the digital eq deviations. The resolution loss is a more significant concern but may be tolerable in practice with a -120dB ADC noise floor and would probably be small enough with a 50 or 2122 analog pole in the preamp.

The RIAA curve can't be followed indefinitely above 2122Hz because the cutter head runs out of power at some point, and there's little power content above 15kHz or so anyway. A 50kHz zero is often added to eq networks, it's especially useful with active feedback to allow closed loop gain > 1 above 100kHz for non-unity-gain stable stages. I looked at adding this to the II solution but it didn't help much for me.

It appears that the IIR filters disclosed here that match the magnitude response of the analog prototype have also matched the phase response, and the matching is easy to prove by calculation, this seems to be more difficult to ensure for FIR filters. The match is so good that I see no point in using FIR here if floating point is available.
 
nuvistor said:
The biquad coefficients can be calculated straightforwardly:

b0 = 0.02209 b1 = -0.0178192 b2 = 0.00268986 a1 = -1.750935 a2 = 0.7525188

...

biquad coefficients:

b0 = 0 b1 = 0.9035 b2 = -0.846186

a0 = 0 a1 = 1 a2 = -0.757645

Frequency response of the digital vs analog is +/- 0.02dB to 20kHz. Phase response is +/- 0.1deg after a 0.4us advance. [/B]


Hmm... have you tested those filters outside the software you're using for to create/analyze them (stable)?

If you don't have proper software for testing then just download
- SynthMaker Demo
- VST Analyzer (works @ 44.1kHz only but, ...)
- editable schematic file for RIAA Filter

* install SynthMaker
* install the Analyzer software
* save the RIAA schematic under folder "Program Files\Outsim\SynthMaker\"
* start SynthMaker and load the linked schematic

Now you'll be able to edit the filter and prepare a VST of it (or standalone version too if you just add I/Os in Top screen)) as long as the Trial period of your SM install is valid (there is periodical hissing sound added by the SM so ...).

Some basics for SynthMaker:

http://img224.imageshack.us/img224/235/sminstrlz7.png


To analyze the VST plug-in, just load the VST plug-in into analyzer ...


Came into mind, if the filter is implemented as hybrid, does the digital part need to be fit in by the results measured from the analog part ... meaning, is it possible to prepare the analog part so accurate (cut steep enough) that it don't effect the frequency area meant for digital filter (and vice versa)?


jiitee
 


...

Came into mind, if the filter is implemented as hybrid, does the digital part need to be fit in by the results measured from the analog part ... meaning, is it possible to prepare the analog part so accurate (cut steep enough) that it don't effect the frequency area meant for digital filter (and vice versa)?

jiitee [/B]



Maybe that "cut steep" was a wrong phrase. What I'm after is that as all hardware included in this analog part of hybrid variates by the used components (pre-amp, soundcard, ADC, etc.) so, it's not same 'balance' between analog and digital stage in every system ... (also doesn't the balance between analog and digital stage depend on settings used for input the analog signal too?) ... you propably need to adjust the gain for the digital filter by the results get from analog part (i.e. it isn't same for all). IMO, getting this done 'exactly' (menaing least as accurate as the possible advantage is) you need some additional equipments/software for that purpose. Could the difference be worth of that much?

BTW, are those coefficients stable/OK (or am I using wrong formula w/ them)?

jiitee
 
Most forums I'm member with allows user to edit his posts when ever he wants. Why on eart isn't this possible here too?

nuvistor said:
...

The main problem I see with the all-digital eq has been noted before, 20Hz is amplified 40dB more than 20kHz, suggesting a loss in A/D resolution of 40dB or 6-7 bits at 20Hz, or 20dB/3 bits at 1kHz. As jcx notes, music power bandwidth is limited so there may not be as much resolution loss in practice with careful level setting, but overload margin for pops/clicks may be too small.

...

I agree that computing precision is an issue here, jiiteepee's project is run on a PC, he doesn't mention data format but 32 bit floating point is a standard representation for audio data, hopefully this is sufficient. I found 6 significant digits to be enough when I verified the poles/zeroes, does higher coefficient precision reduce roundoff errors?

...

Hmm... loosing 6-7 bits is maybe not an issue if you're using 24-bit input (recording) format since, it's still >16-bit accuracy you have in use (same as the Audio CD format bit-depth). I think the issue is the lower samplerates.

What comes to the data format/accuracy, as I compared earlier the effect of rounding (link given in one of my posts), I now compared two higher order filters, using same coefficients, one made with SynthMaker Trial and the other with Delphi/VST SDK.
I suppose the 'big' difference in Harmonic Distortion comes from data format/accuracy (SynthMaker maybe rounds the data (uses maybe only 6-7 decimal accuracy).

An externally hosted image should be here but it was not working when we last tested it.



jiitee
 
jiiteepee said:


Hmm... have you tested those filters outside the software you're using for to create/analyze them (stable)?


I have not tested the biquad coefficients in a sampled-data system. The z poles and zeroes are between -1 and +1 so the resulting filter is theoretically stable and minimum phase, but of course calculation or transcription errors are possible. In fact in post #23, b2 should be -0.00268986.

I use a Mathcad spreadsheet to calculate and plot the responses, a pdf for the filter in post #23 is attached.

jiiteepee said:


Came into mind, if the filter is implemented as hybrid, does the digital part need to be fit in by the results measured from the analog part ...


This would be the best thing to do, but it's probably easier to adjust the analog part, by designing a digital filter that closely matches the inverse of the analog part and use it with DAC applying test signal to analog input and ADC measuring analog output, and adjust for flat response. The analog part can be a buffered RC network so just adjust R.


jiiteepee said:


Hmm... loosing 6-7 bits is maybe not an issue if you're using 24-bit input (recording) format since, it's still >16-bit accuracy you have in use (same as the Audio CD format bit-depth). I think the issue is the lower samplerates.




I agree in theory, in practice you don't get 24-bit noise floor from a good soundcard but more like 16 to 18. For instance RMAA loopback testing for EMU 0404 shows -130dB at 20 Hz, -140dB at 200Hz and above, assuming a 4096 point FFT the noise floor in bits is:

bits = -(dB noise + (1.76 + 10log(points/2))/6.02

or 17.5 bits at 200Hz, 15.8 bits at 20Hz.

After the RIAA filter gain (dB/6.02) you have 9.5 bits at 20Hz, 13 bits at 200Hz, 14.5 bits at 1kHz.

This is all numbers, and considers only measured ADC noise floor, what counts is the experienced sound reproduction which depends on many factors. Vinyl records have high noise levels compared to this soundcard, with my LynxOne at 44.1kHz connected to solid-state analog RIAA preamp and MM cartridge I see about -75dB at 50Hz, -95dB at 1kHz with a quiet record and 4096-point FFT. I suggest comparing digital and digital/analog filter and decide for oneself, after all this is diyaudio.

Digital filter harmonic distortion will be dwarfed by the vinyl noise floor and distortion which is about 0.5 to 1%.
 

Attachments

  • riaa48ktf_danville.pdf
    28.6 KB · Views: 88
Hi Nuvistor,

The picture you show is very interesting. I didn't actually plot anything this detailed.

It would be heuristically enlightening to plot a family of curves using zeros from about -.1 to -.2 This would illustrate how the placement of the zero effects the deviation.

You might also recalculate with 96k sampling. I suspect that the error becomes completely negligible up to 20kHz with a good choice of the zero.

Of course, the reason the fit is good is that the real pole is only 2122Hz which is a long way from 48kHz. The reason it deviates as much as it does is that 16 to 20kHz is not all that far from Nyquist.

I have been playing a little with fitting A weighting curves which are also defined by standard as a set of real poles and zeros in the s plane. The catch here is that there are two poles at 12.2kHz. This is where using more digital poles and zeros to fit the curve is attractive.

Ironically, I have the hardware with the required S/N (AKM AK5394 + SHARC DSP) but I no longer have a turntable or records.

Al Clark
 
nuvistor said:
I agree in theory, in practice you don't get 24-bit noise floor from a good soundcard but more like 16 to 18. For instance RMAA loopback testing for EMU 0404 shows -130dB at 20 Hz, -140dB at 200Hz and above, assuming a 4096 point FFT the noise floor in bits is:

bits = -(dB noise + (1.76 + 10log(points/2))/6.02

or 17.5 bits at 200Hz, 15.8 bits at 20Hz.

After the RIAA filter gain (dB/6.02) you have 9.5 bits at 20Hz, 13 bits at 200Hz, 14.5 bits at 1kHz.

Aren't the wideness of vinyls dynamic range somewhere around 45dB? If so then, doesn't min 8 bits (8x6=48) be enough for to represent this though, there were some comparisons done for vinyls @ http://www.audioholics.com/education/audio-formats-technology

BTW, those cefficients listed in linked document produced a stable filter (didn't check those earlier ones w/ fixed b2).

jiitee
 
Concerning the no of bits, etc.....


You want the ADC frontend to have gain. The idea is to have enough gain so that the maximum signal from the cartridge responds to the full scale voltage of the ADC. If you don't do this you are throwing away bits of precision.

Before, the RIAA filter you can write an overdetector. This is a simple peak detector that looks for consectuative 0x7FFFFF.... (full scale positive) or 0x80000......(full scale negative). If you have consecutive samples with these values you can assume that you are clipping.

You have to use input scaling for the RIAA filter to keep from overloading the filter if you have met the input gain scaling as mentioned above and you are implementing the filter in fixed point. This is not important in a floating point implementation. However, a good fixed point implementation will result in a better filter. I discussed this earlier in this thread.

Please note that the input amplifier gain scaling should be done regardless since you will still have a fix to float conversion in the floating point case.

Concerning stability. The coefficients are all inside the unit circle. This is a requirement for poles. Since none of the coefficients are too close to the unit circle, this filter is relatively easy to implement. It will be stable. If you use a much higher sample rate the 50Hz pole is going to get much closer to the unit circle. This means that the implementation structure (DF I, DF II transpose, etc) and the precision (number of bits, fixed versus float) will be more critical. OTOH, assuming you use good precision, the filter responses will be very close to perfect.

The last thing to consider is that assuming that you have not overloaded but have added gain in the front end, you can add a post scaling multiplication to normalize the output level to whatever you want. This insures that you are maximizing the number of bits and therefore maximizing S/N.


Al Clark
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.