2
votes

I have a question about my low pass filter. I want to interpolate and upsampled signal however when I use my low pass filter it only partly interpolates the samples:

Interpolation

The code of my filter looks like this:

function Hd = lpf5mhz3
%LPF5MHZ3 Returns a discrete-time filter object.

% MATLAB Code
% Generated by MATLAB(R) 8.6 and the Signal Processing Toolbox 7.1.
% Generated on: 27-Nov-2015 14:28:27

% Equiripple Lowpass filter designed using the FIRPM function.

% All frequency values are in Hz.
Fs = 10000000;  % Sampling Frequency

N     = 20;       % Order
Fpass = 1200000;  % Passband Frequency
Fstop = 1250000;  % Stopband Frequency
Wpass = 1;        % Passband Weight
Wstop = 1;        % Stopband Weight
dens  = 20;       % Density Factor

% Calculate the coefficients using the FIRPM function.
b  = firpm(N, [0 Fpass Fstop Fs/2]/(Fs/2), [1 1 0 0], [Wpass Wstop], ...
           {dens});
Hd = dfilt.dffir(b);

% [EOF]

The expected outcome can be seen in my previous question: Applying low pass filter

Does anyone know how to solve this?

1

1 Answers

1
votes

Let's first look at your unfiltered upsampled signal xu (from your previous question) in the frequency domain to better understand what is going on:

enter image description here

As you can see there are 8 replications of the original low-frequency signal (often referred to as images) at Fs/8, 2*Fs/8, ..., 7*Fs/8. Those images includes both the positive and the negative frequency components, so the image around Fs/8 extends from approximately Fs/16 to 3*Fs/16.

Correspondingly, the design cutoff frequency of your filter should be around Fs/(2*M) = Fs/16 or

Fpass = 1200000/2;  % Passband Frequency
Fstop = 1250000/2;  % Stopband Frequency

The resulting magnitude response of the filter designed with:

N  = 20;
b  = firpm(N, [0 Fpass Fstop Fs/2]/(Fs/2), [1 1 0 0], [Wpass Wstop], ...
           {dens});    

can be seen with freqz(b,1):

enter image description here

As you may notice, the filter offers very little attenuation in the stopband. The images I alluded to earlier will thus still be providing a fairly significant contribution to the filtered output. Increasing the number of coefficients will help a little but you're likely to find out that you need a lot of coefficients (on the order of 500-1000) to get a decent stopband attenuation and a sharp transition band.

Comparatively, the filter coefficients generated with fir1(60, 0.125) (as used in my previous answer) provide a much better attenuation where the images are the strongest in the frequency domain, but also has a much wider transition band and uses more filter coefficients. The resulting filtered signal in the frequency are then:

enter image description here

So the question then come down to a tradeoff between the number of coefficients (which affect the computing requirements and the filter delay), the transition band width and the stopband attenuation. To properly answer we would need to know what are your specific application's requirements.

Provided you are trying to interpolate signals with similar bandwidth as the half Gaussian pulse you've used as input (thus not requiring as sharp a transition band as the 50000Hz you specified) and the number of coefficients is the primary concern, you may find the following design performs a little better (although it would still have some significant artifacts) for the same number of coefficients (i.e. 21):

Fpass =  550000/2;
Fstop = 1250000/2;
Wpass = 1;
Wstop = 22;
N  = 20;
b  = firpm(N, [0 Fpass Fstop Fs/2]/(Fs/2), [1 1 0 0], [Wpass Wstop], ...
           {dens});    

Of course, increasing the number of coefficients (as well as relaxing the transition band requirements as done above) would further reduce the interpolation filter's error. Alternatively, using a multi-stage filters (e.g. upsample by 2 then filter, three times in cascade) could also reduce the interpolation error with the same overall number of coefficients and transition bandwidth.