Building Low-pass filter with Sinc function

조회 수: 37 (최근 30일)
Liang
Liang 2020년 9월 18일
답변: Preston Pan 2022년 7월 1일
Dear Community,
I am trying to build a low-pass filter by using a sinc function for my homework assignment. I then use convolution to later filter an audio sample with this filter. However, when I plot the filter in a bode plot it looks like a high-pass filter. Can anyone tell me what I'm doing wrong?
Thanks in advance!
%% Downsampled by K with low-pass filter
% Build filter
clear all; close all
K = 2;
fs = 1600;
N = 51;
n = (-(N-1)/2:1:(N-1)/2);
h = (1/K) * sinc((pi/K)*n);
% Plot frequency response filter
[H, H_vec] = fftFreq(h, fs, 1 );
figure
plot(H_vec*2*pi/fs, abs(H))
filt_tf =tf(h,1,1/fs,'Variable','z^-1');
figure
bode(filt_tf)
function [ X , f ] = fftFreq( data , fs, w )
% Number of FFT points
NFFT = length( data );
% calculate FFT
X = fft(data .* w);
% calculate frequency spacing
df = fs/NFFT;
% calculate unshifted frequency vector
f = (0:(NFFT-1)) * df;
end
  댓글 수: 1
Bas Zweers
Bas Zweers 2020년 9월 22일
You need to use fftshift for the correct frequency plot

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2020년 9월 18일
I am not exactly certain what the problem is from a theoretical prespective (I will leave it to you to explore that), however the sinc pulse is too narrow. Increase ‘K’ to 4 or more, and you get a lowpass result.
Also, since this is a discrete filter, the freqz function will do what you want:
figure
freqz(h,1,2^16,fs)
If you are going to use it as a FIR discrete filter, do the actual filtering with the filtfilt function for the best results.
.
  댓글 수: 4
Liang
Liang 2020년 9월 22일
UPDATE:
Apparently, I made a mistake in the mathematical procedure to come up with my sinc low-pass filter. The pi in the sinc function shouldn't be there. Now everything is working correctly. Thanks again for the help.
Star Strider
Star Strider 2020년 9월 23일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Preston Pan
Preston Pan 2022년 7월 1일
Consider removing the pi in the argument of sinc. I get that scaling is necessary to respect the fourier scaling relationship and preserve unit gain in the passband but I think that would just be rect(K*t) <--> 1/|K| * sinc(f/K).
When I removed it and did
h=(1/K)*sinc(n/K)
the filter produced the desired behavior.

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by