Convolution example: inputA[64],InputB[64] and Output[128]

12 次查看(过去 30 天)
Hi all,
I need help to reproduce a convolution example presented here:
A[k] = FFT(a[n],N)
B[k] = FFT(b[n],N)
conv(a[n], b[n]) = IFFT(A[k] * B[k], N)
/* ----------------------------------------------------------------------
* Test input data for Floating point Convolution example for 32-blockSize
* Generated by the MATLAB randn() function
* ------------------------------------------------------------------- */
float32_t Ak[MAX_BLOCKSIZE]; /* Input A */
float32_t Bk[MAX_BLOCKSIZE]; /* Input B */
float32_t AxB[MAX_BLOCKSIZE * 2]; /* Output */
  1 个评论
Bruno Luong
Bruno Luong 2022-12-12
编辑:Bruno Luong 2022-12-12
None of the standard (MATLAB) shape produce output of length nA+nB where nA and nB are the lenghs of a and b respectively (64 in the thread subject) , but
  • 'full': nA+nB-1
  • 'same': nA
  • 'valid': nA-nB+1

请先登录,再进行评论。

回答(1 个)

Paul
Paul 2022-12-12
Hi AndyK,
I'm going to assume that N = na + nb - 1, where na and nb are the lengths of a[n] and b[n] respectively. Under this assumption, the code would look like this. If we make N > na + nb - 1, like to the nextpower of 2, then ci should have N - (na + nb - 1) trailing zeros (to within rounding error)
rng(100)
na = 5;
nb = 5;
a = rand(1,na);
b = rand(1,nb);
c = conv(a,b);
N = na + nb - 1;
A = fft(a,N);
B = fft(b,N);
C = A.*B;
ci = ifft(C);
c
c = 1×9
0.0661 0.3983 0.6871 0.6916 1.2684 0.9189 0.3635 0.4865 0.0027
ci
ci = 1×9
0.0661 0.3983 0.6871 0.6916 1.2684 0.9189 0.3635 0.4865 0.0027

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by