henryjames012 asked . 2021-02-19

How do I go about designing a filter with a very narrow passband?

How do I go about designing a filter with a very narrow passband? I have some data that was sampled at 10KHz for 500ms. The signal is extremely noisy and I only want the 60Hz component.

matlab , signal , signal processing

Expert Answer

Kshitij Singh answered . 2024-04-21 08:22:40

One way to perform this is to decimate the  signal prior to filtering. If your application permits a reduction in sample rate, then this is a very nice way to go.
 
Without decimation, you are looking to achieve a lowpass filter with a normalized cutoff of:
 
fc = 60 * 2/10000 = 0.012 (very small!)
 
Suppose you were going to design an FIR filter using REMEZ. With a 10 kHz sample rate, a cutoff of 60 Hz, a stopband at 75 Hz, and some typical ripple specifications, the filter order, N, is approximately:
N = remezord([60 75],[1 0],[.01 .1],10000)  

 N =

    898
If, for example, you had a sample rate of 150 Hz, your filter order would be approximately:
 
 
N = remezord([60 75],[1 0],[.01 .1],150)

 N =

     13
You can use RESAMPLE to achieve the reduction in sample rates.
 
Here's an example:
% ------------------------------------------

% Load a test signal

% ------------------------------------------

%   This has a rate of 7418 Hz, but we'll pretend it's at 10kHz anyway:

load mtlb; x=mtlb;

% ------------------------------------------

% Filter and decimate:

% ------------------------------------------

f1 = 10000;  % initial rate

f2 = 150;    % final rate

% Remove common factors:

c  = gcd(f1,f2);

p = f2/c;  % Upsample

q = f1/c;  % Downsample

% Simplest approach - use single stage resampling

% Resample signal from f1 to f2 Hz:

xr = resample(x,p,q);

% 60Hz LPF filter

b = fir1(32, 60*2/f2);  % Or whatever you'd like

y = filter(b,1,xr);

% ------------------------------------------

% All the rest is plotting!

% ------------------------------------------

% Setup time vectors:

t1 = (0:length(x)-1)/10000;

t2 = (0:length(y)-1)/150;

% Plot results:

subplot(2,1,1);

plot(t1,x, t2,y);

title('Decimated and Filtered')

% Compensated for filter delay:  "17" is the starting index for the "remainder" 

% of the data, which means I've chopped off the first 16 samples.

% Now, the filter order is 32, meaning the filter length is N=33 taps.  For a 

% linear phase FIR filter, the delay in samples is (N-1)/2, or exactly 16 samples.  

% Hence, I cut off the first 16 samples.

% Note that an even length (odd order) filter would have a fractional amount of 

% delay, so I couldn't easily illustrate that case.  Compensation can be achieved, 

% it's just not as trivial due to the required interpolations.

subplot(2,1,2);

plot(t1,x, t2,[y(17:end);zeros(16,1)]);

title('Compensated for filter delay')

You could use the FFT method which is also known as "frequency sampling". What you would do is take the FFT, remove any components above 60 Hz and then perform the IFFT.

However, this is not recommened. The FFT method, when implemented correctly is equivalent to a particular FIR filter whose frequency response is exactly 1 at the DFT coefficients 60 Hz and below, and exactly 0 at the DFT coefficients greater than 60 Hz. However, if you look at the DTFT (on a continuum of frequency points from 0 to half the sampling frequency), the frequency sampling filter's response deviates significantly from 1 below 60 Hz, and from 0 above, everywhere BESIDES those N points where it is constrained exactly.

So, usually, it is better to use a technique which minimizes the error over a continuous range of frequencies rather than at discrete points. Frequency sampling is a simplistic filter design method which is not too effective. It's unfortunate that it is the ONLY method suggested in Numerical Recipes.


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.