Digital filter design with matlab

In summary, if you are experiencing issues with your digital filter not matching the expected response, you can check for errors in the conversion from analog to digital, make sure your sampling frequency is correct, adjust your frequency range and resolution, and try using the freqz function instead of freqs.
  • #1
jon404
1
0
I'm to design a 2nd order, N=2, butterworth HPF starting from the normalized transfer function for a LPF:

HN(s)=1/(s^2+1.414*s+1)

Given:
T=0.004
Ωc=0.8 pi
wc=192 pi

To find the transfer function of the HPF, substitute s for wc/s:
H(s)=HN(wc/s)=s^2/(s^2+853*s+363833)

Here's my MATLAB code:

Code:
T=.8/192;
Fs=1/T;
nums=[1 0 0];
dens=[1 853.03 363833.1];

figure
[Hws,w]=freqs(nums,dens);
plot(w,abs(Hws))

[numz,denz]=impinvar(nums,dens,Fs);
tf(numz,denz,T)
figure
[Hwz,w]=freqz(numz,denz);
plot(w,abs(Hwz))

The transfer function of my analog filter looks good, but the transfer function of the digital filter is not right. Could someone help please?
 
Physics news on Phys.org
  • #2


Hello, thank you for sharing your code and progress so far. It seems like you are on the right track, but there may be a few small errors in your code that are causing the digital filter to not match the analog filter as expected. Here are a few suggestions to troubleshoot and improve your code:

1. Check your conversion from analog to digital filter. The impinvar function in MATLAB uses the bilinear transformation method, which may not be the most accurate for higher order filters. You can try using the matched z-transform method instead, which takes into account the frequency warping caused by the bilinear transformation. You can also check for any typos or errors in your coefficients when converting from analog to digital.

2. Make sure your sampling frequency (Fs) is correctly calculated. In your code, you have Fs = 1/T, where T is the time period. However, for a digital filter, Fs should be equal to the sampling rate, which is the number of samples per second. In this case, Fs should be equal to 192, not 1/0.8.

3. Double check your frequency range and resolution. When plotting the frequency response, it is important to make sure that the frequency range and resolution are appropriate to accurately represent the filter response. You can try increasing the number of points in the frequency vector or adjusting the range to see if that improves the plot.

4. Try using the freqz function instead of freqs. The freqz function is specifically designed for digital filters and may provide a more accurate representation of the filter response.

I hope these suggestions help you to troubleshoot and improve your code. Good luck with your project!
 
  • #3


Thank you for sharing your code and results. It looks like you are on the right track with your approach to designing the digital filter using the impinvar function in MATLAB. However, there may be a few issues with your code that could be causing the discrepancy between the analog and digital filter transfer functions.

Firstly, it appears that you have used the incorrect value for T in your code. In the given information, T is equal to 0.004, but in your code, you have used T = 0.8/192, which is equal to 0.0041667. This small difference in T could be causing errors in your digital filter design.

Additionally, when using the impinvar function, it is important to specify the sampling frequency (Fs) in radians per second, rather than in Hertz. In your code, you have used Fs = 1/T, which is in Hertz. However, the impinvar function requires Fs to be in radians per second. To convert from Hertz to radians per second, you can multiply Fs by 2*pi. Therefore, your code should be Fs = 2*pi/T.

Finally, it is also important to specify the cutoff frequency (wc) in radians per second when using the impinvar function. In your code, you have used wc = 192*pi, which is in Hertz. However, the impinvar function requires wc to be in radians per second. To convert from Hertz to radians per second, you can multiply wc by 2*pi. Therefore, your code should be wc = 2*pi*192*pi.

Making these changes to your code should result in a more accurate digital filter design. I hope this helps, and please let me know if you have any further questions.
 

1. What is Digital Filter Design with MATLAB?

Digital filter design with MATLAB is the process of creating and implementing a mathematical algorithm to remove unwanted components from a digital signal. It involves using MATLAB software to design, analyze, and implement digital filters.

2. What are the benefits of using MATLAB for digital filter design?

MATLAB offers a user-friendly interface and a wide range of tools for designing and analyzing digital filters. It also allows for easy implementation of filters on real-time data, making it a popular choice for digital signal processing.

3. What types of digital filters can be designed with MATLAB?

MATLAB can be used to design a variety of digital filters, including low-pass, high-pass, band-pass, and band-stop filters. It also allows for the design of finite impulse response (FIR) and infinite impulse response (IIR) filters.

4. How does MATLAB help in the design process?

MATLAB offers several built-in functions and tools for designing digital filters, such as filter design algorithms, filter visualization tools, and frequency analysis functions. This makes the design process more efficient and helps in achieving the desired filter characteristics.

5. Can MATLAB be used for real-time implementation of digital filters?

Yes, MATLAB has the capability to implement digital filters in real-time. This can be done by using MATLAB's Simulink toolbox, which allows for the creation of real-time models and the integration of filters into a real-time system.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
11
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
Back
Top