upfirdn increases number of samples

11 ビュー (過去 30 日間)
William Greenway
William Greenway 2022 年 1 月 24 日
コメント済み: Pratyush Roy 2022 年 1 月 31 日
I'm trying to apply a bandpass filter to an audio sound that I am inputting into MATLAB. When I apply my bandpass filter to the audio sound then I find that the number of samples increases.
[xx,fs] = audioread('funk.wav');
% resample at 8000Hz
xx_resamp = resample(xx,8000,44100);
% Create bandpass filter
fsamp = 8000;
% f = (-0.5:.001:0.5)*fsamp;
fcuts = [0 20 230 250];
mags = [0 1 0];
devs = [0.01 0.05 0.01];
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);
n = n + rem(n,2);
bpf = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
% Apply bandpass filter using upfirdn
y = upfirdn(xx_resamp,bpf);
% Find length of sample at different stages
lengthy = length(y) %returns 172915
lengthxxresamp = length(xx_resamp) %returns 172021
lengthbpf = length(bpf) %returns 895
% interestingly 172021 + 895 == 172915
Why does applying bpf using upfirdn increase the number of samples?

採用された回答

Pratyush Roy
Pratyush Roy 2022 年 1 月 27 日
編集済み: Pratyush Roy 2022 年 1 月 27 日
Hi William,
As per my understanding, the output sequence after appyling the bandpass filter has a length different from that of the input sequence.
The upfirdn function performs three steps:
  1. Upsample the input data in the matrix xx_resamp by a factor of the integer p by inserting zeroes, where p is the upsampling factor.
  2. FIR filter the upsampled signal data with the impulse response sequence given in the vector or matrix bpf. This is a convolution operation.
  3. Downsample the result by a factor of the integer by throwing away samples, where q is the downsampling factor.
If the input is of length and the FIR filter is of length then the output in the step 2 will be of length (which happened in this case as well, since 172021 + 895 - 1 = 172915). The upsampling and downsampling factors for the function upfirdn is 1 by default, hence a workaround would be to change these values so that the output sequence has the desired length.
Hope this helps!
  2 件のコメント
William Greenway
William Greenway 2022 年 1 月 29 日
Thanks very much! Why does a convolution operation increase the length?
Pratyush Roy
Pratyush Roy 2022 年 1 月 31 日
Hi William,
Please refer to this documentation page for more details.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by