在matlab中计算两个函数的卷积
Calculating convolution of two function in matlab
我需要计算函数的卷积:
f(x)=1 当 -1< x <2, 否则为 0
g(x)=sgn(x)*dirac(abs(x)-1)
我有这个代码:
Fs=1;
t=-10:1/Fs:10;
d=dirac(abs(t)-1);
s=sign(t);
x=d.*s;
x2=1*(t>-1 & t<2);
spl=conv(x,x2,'same');
disp(spl);
但我得到的是很多 NaN 值。
我的错误在哪里?我应该改变什么?
以下是在discrete-time域中估计解的方法。这需要对您的代码进行一些更改:
提高采样率 Fs
以保留更多带宽。我在下面使用了 100 倍。
用 Kronecker delta 替换 Dirac delta 函数以启用 discrete-time 建模。
修改后的代码及结果如下:
Fs=100; % use higher sampling rate
t=-10:1/Fs:10;
d=(abs(t)-1)==0; % use kronecker delta function for discrete-time simulation
s=sign(t);
x=d.*s;
x2=1*(t>-1 & t<2);
spl=conv(x,x2,'same');
% plots to visualize the results
figure;
subplot(3,1,1);
plot(t, x2);
ylabel('f(x)');
subplot(3,1,2);
plot(t, x);
ylabel('g(x)');
subplot(3,1,3);
plot(t, spl);
xlabel('Time');
ylabel('convolution');
试试这个代码:
Fs=1;
t=-10:1/Fs:10;
g=t;
g(g~=1)=0; %g function
s=sign(t);
x=g.*s;
f=t;
f(f>-1 & f<2)=1;
f(f~=1)=0; %f function
x2=f;
spl=conv(x,x2,'same');
disp(spl)
我需要计算函数的卷积:
f(x)=1 当 -1< x <2, 否则为 0
g(x)=sgn(x)*dirac(abs(x)-1)
我有这个代码:
Fs=1;
t=-10:1/Fs:10;
d=dirac(abs(t)-1);
s=sign(t);
x=d.*s;
x2=1*(t>-1 & t<2);
spl=conv(x,x2,'same');
disp(spl);
但我得到的是很多 NaN 值。
我的错误在哪里?我应该改变什么?
以下是在discrete-time域中估计解的方法。这需要对您的代码进行一些更改:
提高采样率
Fs
以保留更多带宽。我在下面使用了 100 倍。用 Kronecker delta 替换 Dirac delta 函数以启用 discrete-time 建模。
修改后的代码及结果如下:
Fs=100; % use higher sampling rate
t=-10:1/Fs:10;
d=(abs(t)-1)==0; % use kronecker delta function for discrete-time simulation
s=sign(t);
x=d.*s;
x2=1*(t>-1 & t<2);
spl=conv(x,x2,'same');
% plots to visualize the results
figure;
subplot(3,1,1);
plot(t, x2);
ylabel('f(x)');
subplot(3,1,2);
plot(t, x);
ylabel('g(x)');
subplot(3,1,3);
plot(t, spl);
xlabel('Time');
ylabel('convolution');
试试这个代码:
Fs=1;
t=-10:1/Fs:10;
g=t;
g(g~=1)=0; %g function
s=sign(t);
x=g.*s;
f=t;
f(f>-1 & f<2)=1;
f(f~=1)=0; %f function
x2=f;
spl=conv(x,x2,'same');
disp(spl)