首页 > 其他分享 >自定义卷积函数并计算窗函数的卷积

自定义卷积函数并计算窗函数的卷积

时间:2024-10-08 17:49:10浏览次数:14  
标签:end 函数 自定义 卷积 sum Nx figure Nw

一、自定义卷积

function y = Convu(x, W) 

Nx = length(x); 

Nw = length(W); 

y = zeros(1, Nx + Nw - 1); 

for n = 1:Nx + Nw - 1 

sum = 0; 

startIdx = max(1, n - Nw + 1); 

endIdx = min(n, Nx); 

for k = 1:Nw 

if startIdx + k - 1 <= endIdx 

sum = sum + x(startIdx + k - 1) * W(Nw - k + 1); 

end 

end 

y(n) = sum; 

end 

end

二、计算窗函数的卷积

N = 100; 
W = ones(1, N); 
figure
stem(W);
figure
Fs = 201; 
T = 1/Fs; 
L = 100; 
t = (0:L-1)*T; 
f = 2; 
A = 1; 
x = A*sin(2*pi*f*t ); 
stem(t,x);
y = Convu(x, W); 
t_conv = (0:length(y)-1) * T; 
figure; 
stem(t_conv, y, 'filled'); 
title('卷积'); 
grid on; 

标签:end,函数,自定义,卷积,sum,Nx,figure,Nw
From: https://blog.csdn.net/weixin_73825075/article/details/142765680

相关文章