Filter brewing for the Soekris R2R

This filter can be improved by multiplying by 8 all coefficients and leaving multiplier 1 This employs more FIR coefficients above e-9.

Good filter. The scene is big. It measures well in distortion.

I like 1021MinPhaseSlow rev1. but It could be one of the final filters collection.
With totalCRaP ™DAM1021 sounds great.
 
Disabled Account
Joined 2005
totalCRaP™ take two

OK this is the same FIR1 filters, but FIR2 has been changed.

I had a think about this after zfe's post in the vendor forum.
My feeling is that FIR1 should take care of aliasing for the first round of oversampling, and FIR2 should remove imaging for the final upsample.

If we remove imaging in FIR1 above 40kHz as the worst case, then the lowest frequency the mirrored image will extend to is 352.8-40 = 312.8kHz. There shouldn't be reason to attempt a steep cutoff before 176.4kHz.

To test the theory I've made a FIR2 filter that rolls off gently from around 30kHz and is -150dB by 275kHz. I'm not sure it makes a huge difference, but there is minimal ringing here.

Interested to hear opinions.



As a digression this what I'm using to create filters at the moment ;)
It is pretty rough but it works. It's needs Octave installed to use and requires manual editing of the script file to alter parameters.
You need to load the Octave signal package for it to work.


Code:
# Test script for creating FIR files in Octave
#  v0.001a  21FEB2015

conv_count = 1;
nb = 95;
#fs = 352800;
fs = 352800*8;
#fs = 384000;
fn = fs/2;
fpass = 90000/fn;
fstop = 135000/fn;
fnyl = (22050-250)/fn;
fnyu = (22050+250)/fn;
fedge = [ 0, fpass, fstop, 1];
famp = [ 1, 1, 0, 0];
n = floor( (nb/conv_count) - (conv_count/2)) ; # number of taps

b = fir2(n, fedge, famp, kaiser(n+1,15));
#b = fir1(n, fpass, "low", kaiser(n+1, 7));
#b=remez(n,fedge,famp,[1, 1]);
#b=firls(n, fedge, famp,[1, 1]);
d = b;

if conv_count > 1
	itt = 1 ;

	while (itt < (conv_count))
	d = conv (d , b);
	itt++;
	endwhile
endif

[H,f] = freqz ( d);
#[gd,f] = grpdelay ( d );
figure(1);
subplot(211);
plot((f/(2*pi))*fs,20*log10(abs(H)));
title(sprintf('Passband Ripple: fs: %d, fc: %d',fs,fpass*fn));
xlabel('Frequency (hz)');
ylabel('Amplitude Response (dB)');
axis([30000, 100000, -5, 5]);
grid('on');

subplot(212);
plot((f/(2*pi))*fs,20*log10(abs(H)));
title(sprintf('Filter response: fs: %d, fc: %d',fs,fpass*fn));
xlabel('Frequency (hz)');
ylabel('Amplitude Response (dB)');
axis([90000, 450000, -200, 5]);
grid('on');
figure(2);
subplot(111);
[Hi, Ti] = impz(d);
plot(Ti,Hi);
grid('on');
axis([0,95,-0.1,0.2]); 


dlmwrite("imp_3528_fir2.txt", d, "delimiter", "\\r");


1;

- conv_count is not getting much use but creates two fir filters and convolves them together. The results can be useful/interesting as it creates a gentler filter with greater attenuation in the stop band.
- nb is number of filter taps required
- fs is sampling frequency. a few variations are commented out.
- fpass - is the end of the passband in hz
- fstop - start of the passband in hz
- fedge is the spec for the edges of the bands for a couple of the filter types
- famp is the spec for the amplitude for the bands 1 being max, 0 = zero

There are four filter types setup. The windowing can be changed but requires tweaking.
if you wanted to use Hann you would replace
kaiser(n+1,15)
with
hann(n+1)

If you have a look at the signal package documentation you'll see what is going on...
Function Reference: signal

There are a a few bits and pieces for calculating the size of the filters for convolution, and then doing the convolve.

the rest of the script is just plotting commands

axis([30000, 100000, -5, 5]);

the above plots from 30kHz to 100kHz, -5dB to +5dB for example. Adjust as required - for passband ripple checking I usually set to -0.001dB, +0.001dB.

The file the coefficients are saved to is set in the dlmwrite command.

Best way to use the above is to save into a text file with a .m extension and load into Octave.
 

Attachments

  • FIR2example1.pdf
    169.4 KB · Views: 163
  • FIR2example2.pdf
    54 KB · Views: 149
  • totalCRaP_rev2.skr.zip
    6.4 KB · Views: 166
  • 1021filt.txt
    60 KB · Views: 151
Last edited:
Disabled Account
Joined 2005
Paul, do you think it is possible to have in the first page the latest versions of all the filters that you think are worthy, with all the relevant graphs? Thank you

Everyone seems to have different tastes, so might be difficult.

What I can probably do is put links to filters that are well liked but at this stage they are all essentially tweaks to the 44.1 and occasionally also 48kHz filters.

It might be a week or two before I can do anything, as I'll have limited access to the 'net.
 
Disabled Account
Joined 2005
Paul,
i think it is reasonable to make a minimum/intermediate-phase version with (almost) no pre-ringing, similar to Ayre's 'MP Listen'.
Would be a worthy addition to our filter collection.

Thanks!

I'll need to have a play in rePhase, as I haven't found a way to do minimum/intermediate filters with Octave's filter tools. There is a function in Matlab that does this but it hasn't been ported as far as I can tell.

Superdad mentioned that John S had a script that he used to create FIR filters from Sox. So clearly it is possible to do, but I'd have to try to work out how could be done, and that takes time...
 
Disabled Account
Joined 2005
More CRaP™

I might have to drop this CRaP™ seeing we already have Schitt doing scat routines...

Anyhow, one more dose to keep things "regular"...

This is loosely modelled on the Dac Magic Linear Phase setting.
The original is -0.1dB @ 20kHz, -10dB at 22kHz, and hits -140dB at some unspecified point - seems to be 23-24Khz.

Obviously this has to be called...
TotalCRaP™'s CRaP™Magic - linear phase (v1)
Both 44.1kHz and 48kHz use the same coefficients.
The 44.1kHz version is
-0.2dB @ 20kHz
-8dB @ 22kHz
-150dB @ 26kHz
and 496 taps.

FIR2 filters have been updated so that they are closer to flat between 20-30kHz. This version is something like -0.04dB @ 30kHz.

That should help fill in time until the toothfairy drops off a MSB Platinum VI for everyone...
 

Attachments

  • CRaPMagic_LP.skr.zip
    3.7 KB · Views: 162
  • CRaPMagic_LP.txt
    36.4 KB · Views: 150
  • CRaPMagic_LP_v1_imp.pdf
    45.5 KB · Views: 152
  • CRaPMagicLP_v1_FR.pdf
    152.3 KB · Views: 162
Last edited:
Disabled Account
Joined 2005
Pull up your SoX...

No magic or special scripts required, just RTFM...

So it took all of about 30 minutes of "suck it and see" to get 99% of the way...

The sneaky trick is the --plot option. What this does with selected SoX effects is to generate a command file which allows you to plot the transfer curve of the effect in Matlab or Octave.

When I first checked using the manual example the results weren't particularly promising - the resulting file contained a couple of equations of the transfer function and plotting commands.

Next attempt using the rate option that John S discusses in posts linked earlier in the thread was a waste of time. It basically doesn't work with --plot option, so no go.

Having a look through the effects listing I noticed that the "sinc" option used the same switches as "rate" but supported --plot. Now we are getting somewhere....

So after a quick peek at the manual page...

Code:
sox --plot octave /path/to/input.wav /path/to/output.wav sinc -20k -I -n 1016 > plot.plt

Holy CRaP™!! the output plot file contained 1016 filter coefficients!

The sampling rate is based on the input.wav, so you need short (1 second is enough) files with 358.2k and 384k sampling rates for FIR1.

From the SoX "rate" documentation...
Minimum, intermediate, or linear phase response is selected using the −M, −I, or −L option; a custom phase response can be created with the −p option. Note that phase responses between ‘linear’ and ‘maximum’ (greater than 50) are rarely useful.

I'm excited. ;)
 
In my opinion the passband for the higher sampling rate (88,96 and up) FIR1 filters should also only be something up to 20kHz while the stopband can be at higher frequencies than for the 44/48 case. At least I would wish such a filter set as option.
I think the main benefit of the higher sampling rates is that it makes live easier for building nice filters (as well for recording as for playback). All of my high sample rate recordings, I have looked at, have no content above -90dB from 18kHz, or at most 22kHz, on upwards.
... unless they are (or seem to be) converted DSD recordings which have a (noise) signal reaching higher levels above 35kHz again:
Spectrum.jpg
 
Last edited:
I'm really enjoying CrapMagic! Great work!

I might have to drop this CRaP™ seeing we already have Schitt doing scat routines...

Anyhow, one more dose to keep things "regular"...

This is loosely modelled on the Dac Magic Linear Phase setting.
The original is -0.1dB @ 20kHz, -10dB at 22kHz, and hits -140dB at some unspecified point - seems to be 23-24Khz.

Obviously this has to be called...
TotalCRaP™'s CRaP™Magic - linear phase (v1)
Both 44.1kHz and 48kHz use the same coefficients.
The 44.1kHz version is
-0.2dB @ 20kHz
-8dB @ 22kHz
-150dB @ 26kHz
and 496 taps.

FIR2 filters have been updated so that they are closer to flat between 20-30kHz. This version is something like -0.04dB @ 30kHz.

That should help fill in time until the toothfairy drops off a MSB Platinum VI for everyone...