DSPRelated.com
Forums

Downsampling

Started by samersamy September 7, 2011
Hi all, 

It is my first time to post here. I working on something that involves
down-sampling an audio stream from 44.1 Khz to 5512 Hz.
After a lot of reading i end up with implementing a Windowed-sinc
low-pass-filter with a cut of frequency 2756 Hz (half 5512 Hz). After that
i use FFT to make convolution. 
My filter Java code implementation works fine and also i followed some
algorithm in "The Scientist and Engineer's Guide to Digital Signal
Processing" eBook for FFT convolution.

The problem is that when i pass run the program and play the sound after
that i hear nothing but "shshshshshshshsh", i mean just noise ... no music
or anything ... looks like the audio is ruined.
Is there any thing i could have missed ?

P.S: i read the audio file in bytes and then cast them to doubles to apply
the FFT and cast the doubles back to bytes to play them ... i  think this
casting may cause the problem ?!!

I can post the Java code if anyone can help me with it.

Thanks 


On Wed, 07 Sep 2011 10:39:53 -0500, "samersamy"
<samer.samy.nazzir@n_o_s_p_a_m.gmail.com> wrote:

>It is my first time to post here. I working on something that involves >down-sampling an audio stream from 44.1 Khz to 5512 Hz. >After a lot of reading i end up with implementing a Windowed-sinc >low-pass-filter with a cut of frequency 2756 Hz (half 5512 Hz). After that >i use FFT to make convolution.
Please describe in much greater detail exactly what you did. By "cutoff", do you mean that the filter is -3 dB at 2756 Hz? Or do you mean that your stopband starts at 2756 Hz? If your filter is -3 dB or -6 dB at 2756 Hz, then you will likely suffer some pretty severe aliasing. What kind of window did you apply to your "windowed sinc"? What are the length of your filter, the length of your data sets, and the length of your FFT? Did you FFT the 44100 Hz data, then apply your filter, then inverse FFT, then decimate? Or did you decimate first, and then FFT the 5512 Hz data and apply the filter?
>My filter Java code implementation works fine and also i followed some >algorithm in "The Scientist and Engineer's Guide to Digital Signal >Processing" eBook for FFT convolution.
How do you know that it works fine?
>The problem is that when i pass run the program and play the sound after >that i hear nothing but "shshshshshshshsh", i mean just noise ... no music >or anything ... looks like the audio is ruined. >Is there any thing i could have missed ?
Yes, there is quite a lot you could have missed, starting with the questions listed above. Did you implement overlap-and-add or overlap-and-save? Did you get your 1/N normalization constant right?
>P.S: i read the audio file in bytes and then cast them to doubles to apply >the FFT and cast the doubles back to bytes to play them ... i think this >casting may cause the problem ?!!
Probably not, unless you got the big-endian/little-endian byte order wrong. But if you just cast from integers to doubles, the language should have taken care of that for you.
>I can post the Java code if anyone can help me with it.
Start with answers to the background questions, above. Greg
On 9/7/11 11:39 AM, samersamy wrote:
> Hi all, > > It is my first time to post here. I working on something that involves > down-sampling an audio stream from 44.1 Khz to 5512 Hz. > After a lot of reading i end up with implementing a Windowed-sinc > low-pass-filter with a cut of frequency 2756 Hz (half 5512 Hz). After that > i use FFT to make convolution.
the low-pass filtering (at 2750 Hz) is an important thing to do. (BTW, how badly does that affect the sound? can you try LPFing without any downsampling and hear the result of that at 44.1 kHz? but don't use an FFT for any downsampling. use some form of polyphase resampling, perhaps a windowed-sinc based interpolation. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Hello,

for the fractional resampling part, this algorithm should give good
results:
http://www.dsprelated.com/showcode/3.php
There is no need for FFT, as was mentioned earlier. 

You can find a C implementation in the source code of open source
"fluidsynth".

It will be functional without low-pass filtering, but you'll get rather
weird aliasing results.
On Wed, 07 Sep 2011 10:39:53 -0500, samersamy wrote:

> Hi all, > > It is my first time to post here. I working on something that involves > down-sampling an audio stream from 44.1 Khz to 5512 Hz. After a lot of > reading i end up with implementing a Windowed-sinc low-pass-filter with > a cut of frequency 2756 Hz (half 5512 Hz). After that i use FFT to make > convolution. > My filter Java code implementation works fine and also i followed some > algorithm in "The Scientist and Engineer's Guide to Digital Signal > Processing" eBook for FFT convolution. > > The problem is that when i pass run the program and play the sound after > that i hear nothing but "shshshshshshshsh", i mean just noise ... no > music or anything ... looks like the audio is ruined. Is there any thing > i could have missed ? > > P.S: i read the audio file in bytes and then cast them to doubles to > apply the FFT and cast the doubles back to bytes to play them ... i > think this casting may cause the problem ?!! > > I can post the Java code if anyone can help me with it. > > Thanks
Divide and conquer: Try to play your file back without doing anything. Then try to play your file back after resampling but without filtering. Then try playing square waves (or whatever). Sneak up on what you have now in stages, until you find out what stage makes it not work. Then figure out what's wrong with that stage. -- www.wescottdesign.com