[英]How to do a 10-fold cross validation without using built-in function in MATLAB?
[英]How do i create my own convolution code on Matlab without using the built-in function
我試圖在Matlab上創建一個程序來顯示2個信號的卷積,但不使用'conv'函數。
輸入為𝑣(𝑡)=𝑒xp(-4t + 4)*𝑢(𝑡-1)+0.5𝑢(𝑡-5)+ 2𝛿(𝑡-10)
我已經算出h(t)= 4 * exp(-4t)* u(t)。 我試圖在MATLAB上編寫一個程序,以計算和顯示代表兩個信號的兩個數組的卷積,但不使用內置的“ conv”函數。 我有一個有效的代碼,但其中包含“ conv”,因此我嘗試不使用此代碼。
t=linspace(0,11,1101);
%create more than 500 time-series values
vs=exp(-4*(t-1)).*heaviside(t-1)+0.5*heaviside(t-5)+2*dirac(t-10);
%Input signal array
h=4*exp(-4*t).*heaviside(t);
%Input signal array
vc=conv(vs,h);
t1=linspace(0,22,2201);
%Convolution of two arrays
subplot(3,1,1)
plot(t,vs)
xlabel('t')
ylabel('v_s(t)')
title('Input signal')
subplot(3,1,2)
plot(t,h)
xlabel('t')
ylabel('h(t)')
title('System impulse response')
subplot(3,1,3)
plot(t1,vc)
xlabel('t')
ylabel('v_c(t)')
title('Output signal')
嘗試用此替換conv行:
N = length(vs);
M = length(h);
lout=N+M-1;
vc=zeros(1,lout);
for i = 1:N
for k = 1:M
vc(i+k-1) = vc(i+k-1) + h(k)*vs(i);
end
end
這是卷積公式的基本Matlab實現
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.