Hi there, I am analysing certain bio signals (with max freq of interest at approz 40Hz) within an a real-time audio program which runs at 48 Khz Samp Rate. The signals must be input at 48Khz but I can downsample by a factor of 256 which rounds down the new sampling rate to 187 Hz and therefore wish to anti-alias before I do. However I need to preserve the shape of the waveforms for accurate analysis which leads me to think an FIR is most suitable. I can use an FIR object within the software to input upto 256 filter co-effs to pass the input through. My question is: Is there any way to acheive such low pass operation (good attenuation at new nyquist approx 90Hz) with only 256 co-effecients? I have access to the fdatool in MATLAB and any FIR I've tried gives a huge numbers of co-effecients! Failing this should I just go for a butterworth and accept that I can't use an FIR? Thanks!
Downsampling 48Khz to 187Hz Filter Recommendation
Started by ●January 12, 2008
Reply by ●January 12, 20082008-01-12
On Jan 12, 11:08 am, "Jam" <JamKrom...@gmail.com> wrote:> Hi there, > > I am analysing certain bio signals (with max freq of interest at approz > 40Hz) within an a real-time audio program which runs at 48 Khz Samp Rate. > > The signals must be input at 48Khz but I can downsample by a factor of 256 > which rounds down the new sampling rate to 187 Hz and therefore wish to > anti-alias before I do. > > However I need to preserve the shape of the waveforms for accurate > analysis which leads me to think an FIR is most suitable. > > I can use an FIR object within the software to input upto 256 filter > co-effs to pass the input through. > > My question is: > > Is there any way to acheive such low pass operation (good attenuation at > new nyquist approx 90Hz) with only 256 co-effecients? > > I have access to the fdatool in MATLAB and any FIR I've tried gives a huge > numbers of co-effecients! > > Failing this should I just go for a butterworth and accept that I can't > use an FIR? > > Thanks!Try breaking the problem into 8 stages of filter and desample by 2. At each stage the transition band runs from 40 Hz to (Fs/2) - 40 Hz. The last stage is the hardest filter but it is performed at only an Fs of only 375 Hz and has a transition band of 40 to 147 Hz. For more points use halfband filters to make almost every other filter coefficient 0.0.This is the opposite end of the complexity/computional load tradeoff from a single filter/desample stage. You could have fewer stages with harder filters by desampling by 4 in 4 stages. But what about that 256 number? Where did it come from? Is 48K times 256 the maximum multiply rate you think you can achieve? Is 256 the size of some hardware or software allocation? Or part of a homework problem? If you don't state the constraints, how can we give useful responses? Dale B. Dalrymple http://dbdimages.com http://stores.lulu.com/dbd
Reply by ●January 12, 20082008-01-12
>Try breaking the problem into 8 stages of filter and desample by 2. At >each stage the transition band runs from 40 Hz to (Fs/2) - 40 Hz. The >last stage is the hardest filter but it is performed at only an Fs of >only 375 Hz and has a transition band of 40 to 147 Hz. For more points >use halfband filters to make almost every other filter coefficient >0.0.This is the opposite end of the complexity/computional load >tradeoff from a single filter/desample stage. You could have fewer >stages with harder filters by desampling by 4 in 4 stages. >sorry you've lost me a bit here. I'm not really sure what the term desample means. Also why does each transition band run from 40 to 48KHz/2 ?>But what about that 256 number? Where did it come from? Is 48K times >256 the maximum multiply rate you think you can achieve? Is 256 the >size of some hardware or software allocation? Or part of a homework >problem? If you don't state the constraints, how can we give useful >responses? >Basically there's an existing algorithm I can use in the software which can take upto 256 FIR co-effecients and perform the filtering in real-time. This would save me having to code my own FIR.
Reply by ●January 12, 20082008-01-12
> > Try breaking the problem into 8 stages of filter and desample by 2. At > each stage the transition band runs from 40 Hz to (Fs/2) - 40 Hz. The > last stage is the hardest filter but it is performed at only an Fs of > only 375 Hz and has a transition band of 40 to 147 Hz. For more points > use halfband filters to make almost every other filter coefficient > 0.0.This is the opposite end of the complexity/computional load > tradeoff from a single filter/desample stage. You could have fewer > stages with harder filters by desampling by 4 in 4 stages. ><remove text>> Dale B. Dalrymplehttp://dbdimages.comhttp://stores.lulu.com/dbd- Hide quoted text - > > - Show quoted text -Hello Dale, Welcome to comp.dsp group of Dsp Gurus! Describing is not correct. Aliaseing is possibl in transition band of last filter you describe. Last filter should remove "all" aliases. At stages, preserved spectrums must include 40 Hz and transition of last "anti-aliase" filter. You must rethink. Your describing leaves aliases in last transition band. Regards, Kamar Ruptan Dsp Guru
Reply by ●January 12, 20082008-01-12
>But what about that 256 number? Where did it come from? Is 48K timesAh you mean why to decimate by a factor of 256? It's because I can only down-sample by power of 2 from within the audio software.>>Try breaking the problem into 8 stages of filter and desample by 2. At >>each stage the transition band runs from 40 Hz to (Fs/2) - 40 Hz. The >>last stage is the hardest filter but it is performed at only an Fs of >>only 375 Hz and has a transition band of 40 to 147 Hz. For more pointsOk I've looked it up and you mean downsampling by a factor of 2 each time. I read on DSPguide guru that it's better to "Decimate in order from the largest to smallest factor" I see what you mean the 375 Hz will prove tricky. If I decimate by a factor of 128 though (I can live with sr = 375 Hz) I can do it in only 2 stages then: So are the steps?: 1) (a) FIR for (48KHz/2)/16 = low pass with 1500Hz stop band (b) keep every 16th sample. Now Fs = 3000 Hz 2)(a) FIR for (3KHz/2)/8 = low pass with a stop band smaller than 375/2 Hz (b) keep every 8th sample. Now Fs = 375 Hz Can I use any FIR from the fdatool (hanning window probably since that looks easiest to set and use!)?
Reply by ●January 13, 20082008-01-13
Jam wrote:>> But what about that 256 number? Where did it come from? Is 48K times > Ah you mean why to decimate by a factor of 256? It's because I can only > down-sample by power of 2 from within the audio software. > > >>> Try breaking the problem into 8 stages of filter and desample by 2. At >>> each stage the transition band runs from 40 Hz to (Fs/2) - 40 Hz. The >>> last stage is the hardest filter but it is performed at only an Fs of >>> only 375 Hz and has a transition band of 40 to 147 Hz. For more points > > Ok I've looked it up and you mean downsampling by a factor of 2 each time. > I read on DSPguide guru that it's better to "Decimate in order from the > largest to smallest factor" > > I see what you mean the 375 Hz will prove tricky. > > If I decimate by a factor of 128 though (I can live with sr = 375 Hz) I > can do it in only 2 stages then: > > > So are the steps?: > 1) (a) FIR for (48KHz/2)/16 = low pass with 1500Hz stop band > (b) keep every 16th sample. Now Fs = 3000 Hz > > 2)(a) FIR for (3KHz/2)/8 = low pass with a stop band smaller than 375/2 > Hz > (b) keep every 8th sample. Now Fs = 375 Hz > > > Can I use any FIR from the fdatool (hanning window probably since that > looks easiest to set and use!)?Here is one solution for eight stages. You can use CIC or polyphase filters for first six stages and polyphase filters for two last stages. -- Juha Fs = 48e3; % Sampling frequency for the input signal nGridPoints = 2^14; % Number of frequency grid points freqVect = linspace(0, pi, nGridPoints); % Frequency vector in rad b = [1 2 1]; % Coefficient values for the 1st stage for iStage = 1:8 switch iStage case {3,5,6} b = conv(b, [1 1]); case {7} b = firhalfband(10, 40/(Fs/2)); case {8} b = firhalfband(18, 40/(Fs/2)); end h = b/sum(b) % Coefficient values for the Kth stage H = freqz(h, 1, freqVect); % These frequencies alias to the passband (f \in[0, 40] Hz) iAliasToPassband = find(Fs/2*freqVect/pi > Fs/2-40); plot(Fs/2*freqVect/pi, 20*log10(abs(H))) hold on plot(Fs/2*freqVect(iAliasToPassband)/pi, ... 20*log10(abs(H(iAliasToPassband))), 'r') disp(['Max alias = ' num2str(max(dB(abs(H(iAliasToPassband))))) ' dB']) plot(Fs/2*freqVect(iAliasToPassband(1))/pi*[1 1], [-140 5], 'r--') hold off axis([0 Fs/2 -140 5]) grid on xlabel(['Frequency in Hz (fs = ' num2str(Fs) ' Hz)']) ylabel('Magnitude in dB') Fs = Fs/2; disp('Paused'),pause end
Reply by ●January 13, 20082008-01-13
"Jam" <JamKromium@gmail.com> wrote in message news:5JudnWrO2JqhjRTanZ2dnUVZ_hOdnZ2d@giganews.com...> Hi there, > > I am analysing certain bio signals (with max freq of interest at approz > 40Hz) within an a real-time audio program which runs at 48 Khz Samp Rate. > > The signals must be input at 48Khz but I can downsample by a factor of 256 > which rounds down the new sampling rate to 187 Hz and therefore wish to > anti-alias before I do. > > However I need to preserve the shape of the waveforms for accurate > analysis which leads me to think an FIR is most suitable. > > I can use an FIR object within the software to input upto 256 filter > co-effs to pass the input through. > > My question is: > > Is there any way to acheive such low pass operation (good attenuation at > new nyquist approx 90Hz) with only 256 co-effecients?How much is "good attenuation" ?> I have access to the fdatool in MATLAB and any FIR I've tried gives a huge > numbers of co-effecients!Taking the reasonable assumptions, the optimal approach would be 4 or 5 stages of polyphase FIR decimation. Something like 8/4/4/2 or /4/4/4/2/2. Yes, the total number of coefficients is likely to be less then 256.> Failing this should I just go for a butterworth and accept that I can't > use an FIR?IIR can be the option too, but beware of the numeric precision effects. Double floating point accuracy is required. Vladimir Vassilevsky DSP and Mixed Signal Consultant www.abvolt.com
Reply by ●January 13, 20082008-01-13
On Jan 12, 3:16 pm, DSPGURU <krup...@gmail.com> wrote:> > Try breaking the problem into 8 stages of filter and desample by 2. At > > each stage the transition band runs from 40 Hz to (Fs/2) - 40 Hz. The > > last stage is the hardest filter but it is performed at only an Fs of > > only 375 Hz and has a transition band of 40 to 147 Hz. For more points > > use halfband filters to make almost every other filter coefficient > > 0.0.This is the opposite end of the complexity/computional load > > tradeoff from a single filter/desample stage. You could have fewer > > stages with harder filters by desampling by 4 in 4 stages. > > <remove text> > > > Dale B. Dalrymplehttp://dbdimages.comhttp://stores.lulu.com/dbd-Hide quoted text - > > > - Show quoted text - > > Hello Dale, > > Welcome to comp.dsp group of Dsp Gurus! > > Describing is not correct. Aliaseing is possibl in transition band of > last filter you describe. Last filter should remove "all" aliases. At > stages, preserved spectrums must include 40 Hz and transition of last > "anti-aliase" filter. You must rethink. Your describing leaves aliases > in last transition band. > > Regards, > > Kamar Ruptan > Dsp GuruKamar Plugging the output frequency of the last stage into the formula I gave gives about 53 Hz, not 147, a value that the OP may have already come to understand. With only a few days posting here you have already achieved a narrow focussed parsing of English, misspelling, condescension and a disinterest in contributing to the OP's understanding of the question posed. You seem to fit right in. Dale B. Dalrymple
Reply by ●January 13, 20082008-01-13
On Jan 13, 1:42�pm, dbd <d...@ieee.org> wrote:> On Jan 12, 3:16 pm, DSPGURU <krup...@gmail.com> wrote: > > > > > > > > Try breaking the problem into 8 stages of filter and desample by 2. At > > > each stage the transition band runs from 40 Hz to (Fs/2) - 40 Hz. The > > > last stage is the hardest filter but it is performed at only an Fs of > > > only 375 Hz and has a transition band of 40 to 147 Hz. For more points > > > use halfband filters to make almost every other filter coefficient > > > 0.0.This is the opposite end of the complexity/computional load > > > tradeoff from a single filter/desample stage. You could have fewer > > > stages with harder filters by desampling by 4 in 4 stages. > > > <remove text> > > > > Dale B. Dalrymplehttp://dbdimages.comhttp://stores.lulu.com/dbd-Hidequoted text - > > > > - Show quoted text - > > > Hello Dale, > > > Welcome to comp.dsp group of Dsp Gurus! > > > Describing is not correct. �Aliaseing is possibl in transition band of > > last filter you describe. �Last filter should remove "all" aliases. At > > stages, preserved spectrums must include 40 Hz and transition of last > > "anti-aliase" filter. You must rethink. Your describing leaves aliases > > in last transition band. > > > Regards, > > > Kamar Ruptan > > Dsp Guru > > Kamar > > Plugging the output frequency of the last stage into the formula I > gave gives about 53 Hz, not 147, a value that the OP may have already > come to understand.Hello Dale, What you say was: "The last stage is the hardest filter but it is performed at only an Fs of only 375 Hz and has a transition band of 40 to 147 Hz." No formula, no 53 Hz. Above 40 has aliases from before stages that you do not remove in transition band.> > With only a few days posting here you have already achieved a narrow > focussed parsing of English, misspelling, condescension and a > disinterest in contributing to the OP's understanding of the question > posed. You seem to fit right in.I do all of that? Whatever. You still wrong. Do not have shame, hang around to learn. Regards, Kamar Ruptan Dsp Guru> > Dale B. Dalrymple- Hide quoted text - > > - Show quoted text -
Reply by ●January 13, 20082008-01-13
On 12 Jan, 20:08, "Jam" <JamKrom...@gmail.com> wrote:> Hi there, > > I am analysing certain bio signals (with max freq of interest at approz > 40Hz) within an a real-time audio program which runs at 48 Khz Samp Rate. > > The signals must be input at 48Khz but I can downsample by a factor of 256 > which rounds down the new sampling rate to 187 Hz and therefore wish to > anti-alias before I do. > > However I need to preserve the shape of the waveforms for accurate > analysis which leads me to think an FIR is most suitable. �You don't mention exactly what type of signals you analuze, but I take it you want to analyze the exact shape of the transients to get whatever information you want from the data? Something like an EKG? If so, be very careful with what you do. There is no way to filter the data *and* preserve the transinet waveforms. All (linear) filtering is equivalent to convolving the signal with an impulse response, which by definition alters the shape of the transients. The best you can hope for is to use a filter before the decimation, which effect on the transients can be removed "sufficiently well" afterwards. My candidate would be a minimum phase IIR filter. A minimum phase IIR filter has a stable, causal inverse which "undoes" the effect of the filter. I would try to find a minimum phase IIR for the antialias filter, downsample, and then find the downsampled equivalent of the inverse filter. I don't say it can be done; I don't say it's easy. However, that's the approach I would have checked out if I were presented with that sort of task. Rune






