How to Design Bandpass Filter Using Matlab

Bandpass Filter Matlab

Introduction to Bandpass Filter Matlab

Band Pass Filters are used to filter or isolate certain frequencies that lie in a particular range. These filters find their use in applications like audio amplifiers or circuits used in loudspeakers (crossover filters) or tone controls used in pre-amplifiers. In these applications, it is required to pass only a specific range of frequencies which don't start at DC (0HZ) or they end at a higher frequency point but lie within a specific range, which can be either wide or narrow.

Syntax:

F = bandpass (s, wp)

F = bandpass (s, fp, Fx)

Description:

  • F = bandpass(s, wp) is used to filter the signal 's' with passband frequency range provided by the 2-element vector 'wp'. If input 's' is a matrix, the bandpass function will filter each column of 's' independently
  • F = bandpass (s, fp, Fx) is used to specify that the signal 's' is sampled at a rate 'Fx' HZ. The 2-element vector 'fp' gives the passband frequency

Examples of Bandpass Filter Matlab

Let us now understand the code of 'Bandpass filter' in MATLAB with the help of various examples:

Example #1

In this example, we will create a sine signal which is sampled at 10000Hz for 1 second and will pass it through a Bandpass filter.

Below are the steps to be followed:

  • Define the sampling rate.
  • Define the tones for the signal.
  • Keep low frequency and high frequency tone at a level of three times the intermediate tone.
  • Pass the above signal through the bandpass filter by setting the allowed frequencies.

Code:

Fx = 1e4
T = 0:1/Fx:1

[Defining the sampling rate]

s = [3 1 3]*sin(pi*[50 100 300]'.*T) + randn(size(T))/20;

[Creating the signal with 3 tones, 50 Hz, 100 Hz and 300 Hz]

bandpass(s, [100 200], Fx)

[Passing the input signal to bandpass filter and setting the allowed frequency range as 100 to 200] [Bandpass filter will allow frequencies of 100 & 200 Hz. In the output, we will get the original & filtered signals along with their spectra]

Input:

Fx = 1e4
T = 0:1/Fx:1
s = [3 1 3]*sin(pi*[50 100 300]'.*T) + randn(size(T))/20;
bandpass(s, [100 200], Fx)

Output:

As we can see in the output, we have obtained the original & filtered signals along with their spectra. The Bandpass filter has removed the frequencies below the low pass frequency and frequencies above the high pass frequency.

Bandpass Filter Matlab-1.1

Example #2

In this example, we will create a cos signal which is sampled at 10000Hz for 1 second and will pass it through a Bandpass filter.

Below are the steps to be followed:

  • Define the sampling rate.
  • Define the tones for the signal.
  • Keep low frequency and high-frequency tone at a level of two times the intermediate tone.
  • Pass the above signal through the bandpass filter by setting the allowed frequencies.

Code:

Fx = 1e4
T = 0:1/Fx:1

[Defining the sampling rate]

s = [2 1 2]*cos(pi*[150 200 300]'.*T) + randn(size(T))/20;

[Creating the cos signal with 3 tones, 150 Hz, 200 Hz and 300 Hz]

bandpass(s, [100 200], Fx)

[Passing the input signal to bandpass filter and setting the allowed frequency range as 100 to 200] [Bandpass filter will allow frequencies of 100 & 200 Hz. In the output, we will get the original & filtered signals along with their spectra]

Input:

Fx = 1e4
T = 0:1/Fx:1
s = [2 1 2]*cos(pi*[150 200 300]'.*T) + randn(size(T))/20;
bandpass(s, [100 200], Fx)

Output :

Bandpass Filter Matlab-1.2

As we can see in the output, we have obtained the original & filtered signals for our input cos signal along with their spectra. The Bandpass filter has removed the frequencies below the low pass frequency and frequencies above the high pass frequency.

Example #3

In the above 2 examples, we used a three-channel signal, in this example, we will use a 2-channel signal and will pass it through a Bandpass filter.

Below are the steps to be followed:

  • Define the sampling rate.
  • Define the tones for the signal.
  • Keep high frequency twice the low frequency.
  • Pass the above signal through the bandpass filter by setting the allowed frequencies.

Code:

Fx = 1e4
T = 0:1/Fx:1

[Defining the sampling rate]

s = [2 1].*cos(2*pi*(0:64)'./[32 64])

[Creating the 2-channel cos signal]

bandpass(s, [100 200], Fx)

[Passing the input signal to bandpass filter and setting the allowed frequency range as 100 to 200] [Bandpass filter will allow frequencies of 100 & 200 Hz. In the output, we will get the original & filtered signals along with their spectra]

Input:

Fx = 1e4
T = 0:1/Fx:1
s = [2 1].*cos(2*pi*(0:64)'./[32 64])
bandpass(s, [100 200], Fx)

Output:

Bandpass Filter Matlab-1.3

As we can see in the output, we have obtained the original & filtered signals for our input cos signal along with their spectra. The Bandpass filter has removed the frequencies below the low pass frequency and frequencies above the high pass frequency.

Conclusion

  • Bandpass filters are used to get the frequencies that lie in a particular range.
  • We use the Bandpass function in MATLAB to execute a Bandpass filter.
  • The Bandpass function in MATLAB provides both original and filtered signals as output.
  •  This function also provides the spectra of the signals in the output.

Recommended Articles

This is a guide to Bandpass Filter Matlab. Here we also discuss the introduction and syntax of bandpass filter matlab along with a different example and its code implementation. You may also have a look at the following articles to learn more –

  1. Matlab Format
  2. Moving Average Matlab
  3. Convolution Matlab
  4. Magnitude Matlab

How to Design Bandpass Filter Using Matlab

Source: https://www.educba.com/bandpass-filter-matlab/

0 Response to "How to Design Bandpass Filter Using Matlab"

Mag-post ng isang Komento

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel