From: Jerry Avins on
On 5/29/2010 1:29 PM, Jerry Avins wrote:
> On 5/29/2010 1:10 PM, Fred Marshall wrote:
>> You might use exactly the same filter in each case (but with different
>> sample rates).
>>
>> Note: the filter coefficients *don't* depend on the sample rate but the
>> absolute frequency response does. If you normalize the frequency
>> response to fs, then the frequency response remains the same with the
>> same set of coefficients.
>>
>> You might use the same half-band filter in both situations. A half-band
>> filter is a lowpass at fs/4 with some special features included.
>>
>> For interpolation:
>>
>> 1) Intersperse in time with zeros. This may be a "no-op" depending on
>> your implementation.
>>
>> 2) Low pass filter (at the new fs) to fs/4 in order to get rid of the
>> content around fs/2 (which is an image of the content around zero and
>> fs). This is what a half-band filter does.
>>
>> One benefit of the half-band filter is that it has quite a few
>> zero-valued coefficients. So, implementation in time can be efficiently
>> done.
>>
>> For decimation:
>>
>> 1) Low pass filter at fs/4 in order to limit the bandwidth to below what
>> will become the *new* fs/2.
>>
>> 2) Decimate by dropping every other sample. Again, almost a "no-op".
>>
>> Halfband design program at:
>> ftp.mission-systems-inc.com
>> login: ourguest
>> password: hellothere.4
>> Directory: Halfband
>
> Fred,
>
> I supposed that a half-band filter might fall short of the needed
> performance. Isn't the attenuation at fs/4 only 3 dB?

Er, 6 dB. I do too much of that lately.

Jerry
--
Engineering is the art of making what you want from things you can get.
�����������������������������������������������������������������������
From: Tim Wescott on
On 05/29/2010 09:28 AM, Joe wrote:
> I was asked to create a Decimator/Interpolator to go between
> Narrow Band (8 KHz Sampling) and Wide Band (16 KHz Sampling).
>
> I am not so familiar with english engineer lingo, so does the above mean
> that the samplerate of the input signal which is fed to the
> decimator/interpolator-algorithm will either be 8KHz or 16KHz ?
>
> The implementation will be done in ANSI C. It has to a be a fixed point
> implementation and it must be efficient in terms of cpu usage.
>
> The implementation must support multi-instance. I'm assuming that this
> means
> that it should be possible to create several instances of a
> decimator/interpolator "class" and
> that the implementation should be somewhat object-oriented?
>
> The Decimator must have a passband of 3700 Hz. Stop Band is 4000 Hz.
> Minimum
> stopband attenuation 40 dB. Passband ripple 1.5 dB.
>
> I understand that the decimator is a preprocessing low pass filter and
> that you send the input signal
> through this filter...and that you then take every Mth output sample
> from the filter to
> construct the downsampled signal.
>
> I also understand that the interpolator is a post-processing low-pass
> filter which you apply to a signal x[k]
> where x[k] is an 'expanded' version of some input signal y[k]....x[k] is
> created by inserting zeros between
> every sample in the original signal y[k].
>
> I also understand that interpolation is done before decimation.
>
> I tried to do a simulation in matlab and it seems to work fine:
>
> ********* MATLAB CODE START **********
> %% 22050Hz signal
> [y,fs]=wavread('audiosignal.wav');
>
> %% Interpolator
> L = 2; % Interpolation factor
> Fp = 0.92*fs/2; % Passband-edge frequency
> Fst = fs/2; % Stopband-edge frequency
> Ap = 1.5; % Passband peak-to-peak ripple
> Ast = 40; % Minimum stopband attenuation
> Fs = fs; % Sampling frequency
> Hf = fdesign.interpolator(L,'lowpass',Fp,Fst,Ap,Ast,Fs);
> Hm = design(Hf,'equiripple');
>
> % Create interpolated signal. New sample rate = 44100 Hz
> z_i=zeros(1,length(y)*L);
> z_i(1:L:end)=y;
> z_i=filter(Hm.Numerator,1,z_i);
> wavplay(z_i,fs*L);
>
> %% Decimator
> M = 6; % Decimation factor
> Fp = 3700; % Passband-edge frequency
> Fst = 4000; % Stopband-edge frequency
> Ap = 1.5; % Passband peak-to-peak ripple
> Ast = 40; % Minimum stopband attenuation
> Fs = fs*L; % Sampling frequency
> Hf = fdesign.decimator(M,'lowpass',Fp,Fst,Ap,Ast,Fs);
> Hm = design(Hf,'equiripple');
>
> % Create decimated signal and play it. New sample rate = 7350Hz
> z=filter(Hm.Numerator,1,z_i);
> z=z(1:M:end);
> wavplay(z,fs*L/M);
> ********* MATLAB CODE END**********
>
> Since the filter coefficients depend on fs, I am wondering why the spec
> I was given doesn't say anything
> about the sample frequency of the input signal. Should I just assume
> that I also have to implement an
> algorithm which calculates the filter coefficients based on some fs
> specified by the user ? If it's a mistake
> and fs is known and fixed, I guess it should have been included in the
> spec? Or is the sample rate just either
> 8KHz or 16KHz (as mentioned in the beginning of this thread) ? In that
> case, the decimator filter coefficients
> still have to be calculated by some algorithm since they depend on the
> interpolator factor L, right?

* Your written 'regular' English is certainly fine.

* Never be afraid to go back to the customer and clarify the
specification. The eventual unpleasantnesses that result from
incorrectly interpreting a specification, or even correctly interpreting
an erroneous one, far outweigh any unpleasantness of asking for
clarification. I do this all the time, and rarely do my questions get
greeted with impatience or other negative emotion: usually they are seen
as proof that I'm paying attention and want to get all the details right.

* Look into polyphase filtering, this seems to be a prime candidate.

* When you clarify the spec, make sure you clarify the bit about whether
the input sampling rate varies -- the size of your job will vary hugely
depending on whether the sample rates are a fixed 1:2 ratio or they are
arbitrary.

--
Tim Wescott
Control system and signal processing consulting
www.wescottdesign.com
From: Joe on
> Please be a little more explicit. When you write "go between
> Narrow Band (8 KHz Sampling) and Wide Band (16 KHz Sampling)", I take it
> that you mean that signals with a sample rate of 8KHz must be converted to
> 16 KHz, and signals with a sample rate of 16KHz must be converted to 8
> KHz. If so, the sample rates are given. Likewise the interpolation and
> decimation factors; both 2.

Yeah, I also think that the sentence "go between
Narrow Band (8 KHz Sampling) and Wide Band (16 KHz Sampling)"
is too vague. That's why I was wondering if I just don't understand the
subtleties of english (engineer) lingo. But I guess it makes more sense that
the decimator/interpolator must either convert a signal sampled at 16kHz
to 8kHz or convert a signal sampled at 8kHz to 16kHz.

If that is the case then my MATLAB simulation should look like this
(right?):



*************************************************************
%% Interpolator (upsampling)
fs=8000;
y=y_narrowband; % 8kHz sample rate
L = 2; % Interpolation factor
Fp = 0.97*fs/2; % Passband-edge frequency
Fst = fs/2; % Stopband-edge frequency
Ap = 1.5; % Passband peak-to-peak ripple
Ast = 40; % Minimum stopband attenuation
Fs = fs*L; % Sampling frequency
Hf = fdesign.interpolator(L,'lowpass',Fp,Fst,Ap,Ast,Fs);
Hm = design(Hf,'equiripple');
upsampled_signal=zeros(1,length(y)*L);
upsampled_signal(1:L:end)=y;
upsampled_signal=filter(Hm.Numerator,1,upsampled_signal);

%% Decimator (downsampling)
fs=16000;
y=y_wideband; % 16kHz sample rate
M = 2; % Decimation factor
Fp = 3700; % Passband-edge frequency
Fst = 4000; % Stopband-edge frequency
Ap = 1.5; % Passband peak-to-peak ripple
Ast = 40; % Minimum stopband attenuation
Fs = fs; % Sampling frequency
Hf = fdesign.decimator(M,'lowpass',Fp,Fst,Ap,Ast,Fs);
Hm = design(Hf,'equiripple');
downsampled_signal=filter(Hm.Numerator,1,y);
downsampled_signal=downsampled_signal(1:M:end);
*************************************************************


From: Joe on
> * Your written 'regular' English is certainly fine.

Thank you :o)



> * Look into polyphase filtering, this seems to be a prime candidate.

For which reason(s) ?


> * When you clarify the spec, make sure you clarify the bit about whether
> the input sampling rate varies -- the size of your job will vary hugely
> depending on whether the sample rates are a fixed 1:2 ratio or they are
> arbitrary.

Yes. I will do that. I realized that the size of the job hugely depends on
whether
or not the sample rate of the input signal is fixed/known
or arbitrary. So I just wanted to run it by this forum to see if I was
overlooking something.
But I guess my feeling about the spec being too vague was right then...



From: Fred Marshall on
Jerry,

>>
>> I supposed that a half-band filter might fall short of the needed
>> performance. Isn't the attenuation at fs/4 only 3 dB?
>
> Er, 6 dB. I do too much of that lately.
>

Well, yes it is. But then one hopes that the guard band in the signal
is maybe 20% also. So, in that case it makes sense. If there is some
bandwidth margin then the cutoff frequency (where the passband and/or
stopband departs from its normal / average value beyond the ripple
value) can be at the edge of the margin.

If there is *no* margin then one may not be sure what one is working
with in the first place as it has all the appearance of not meeting the
sampling requirements.

Either one is willing to get some aliasing or one must be willing to do
some pre-processing filtering to get some band margin in order to rather
guarantee acceptable aliasing or *no* aliasing if that's possible....

Then, you use a half band filter when efficiency of implementation is
important. And, this might also lead to a polyphase implementation of
same.

I note that "polyphase" filtering is an implementation technique and not
a filter design technique - at least where coefficients are concerned.
You first have to design a filter with coefficients such that the filter
*can* be implemented as a polyphase structure and then you can use a
polyphase structure.

Fred