I face the following problem
I wanted to do some audio processing on teensy with sampling frequencies higher than 44.1 kHz.
OK, this is easy, but I wanted to use the usb-audio to listen to the acquired sound in real time.
First thought: modify usb-audio for other than 44.1 kHz, but this would interfere with teensyduino upgrades.
Second thought: convert on-teensy audio to 44.1 kHz and use standard usb-audio.
This is what I now follow
For this I need a resampling scheme that is somewhat efficient.
All my frequencies are above 44.1kHz so I need a decimation/interpolation scheme.
So I played with matlab and come up with
where the interpolation is obtained by using in integer division and modulo operations and compared to Matlab's interp1 function
The result is shown in this figure
I'm confident that this method can easily be implemented in 'C'.
If this is well know method, OK, I reinvented the wheel (which is part of the fun)
I wanted to do some audio processing on teensy with sampling frequencies higher than 44.1 kHz.
OK, this is easy, but I wanted to use the usb-audio to listen to the acquired sound in real time.
First thought: modify usb-audio for other than 44.1 kHz, but this would interfere with teensyduino upgrades.
Second thought: convert on-teensy audio to 44.1 kHz and use standard usb-audio.
This is what I now follow
For this I need a resampling scheme that is somewhat efficient.
All my frequencies are above 44.1kHz so I need a decimation/interpolation scheme.
So I played with matlab and come up with
Code:
% original signal
fo=1000;
fs1=375000;
i1=(0:fs1)';
t1=i1/fs1;
s1=sin(2*pi*fo*t1);
% output sampling rate
fs2=44100;
i2=(1:45)';
t2=i2/fs2;
% 'ideal' downsampling
s2=interp1(t1,s1,t2);
% sample-based resampling
% scale both sampling frequencies to smallest integer (to be done once)
jfs1=fs1; jfs2=fs2;
while((mod(jfs1,1)==0) && (mod(jfs2,1)==0)), jfs1 = jfs1/10; jfs2=jfs2/10; end
jfs1=jfs1*10;
jfs2=jfs2*10;
% interpolation using integer arithmetic
i3=1+floor((i2*jfs1+jfs2)/jfs2);
isc=mod(jfs1,jfs2);
s3=s1(i3-1)+mod(i2*isc,jfs2).*(s1(i3)-s1(i3-1))/jfs2;
%
figure(1)
plot(t1,s1,'.-', t2,s2,'*-',t2,s3,'ro-')
xlim([0 0.001])
The result is shown in this figure
I'm confident that this method can easily be implemented in 'C'.
If this is well know method, OK, I reinvented the wheel (which is part of the fun)
Last edited: