2017-09-17 22 views
0

我怎樣才能總結兩個不同時間指標的離散時間信號,即。在時間索引n1=-3:1,和第二信號y=[1 1 2 2 3]在時間索引n2=0:4給定的第一信號x=[1 2 3 4 5]。 由於長度不同,我不能只添加這兩個信號。到目前爲止,我的代碼是:如何繪製不同時間索引的兩個離散時間信號的總和?

n1=-3:1; 
x=input('Enter the value of X:'); 
y=input('Enter the value of Y:'); 
subplot(3,1,1); 
stem(n1,x); 
grid on; 
xlabel('Time index'); 
ylabel('Amplitude'); 
axis([-10 10 0 10]); 
title('signal X'); 


n2=0:4; 
subplot(3,1,2); 
stem(n2,y); 
grid on; 
xlabel('Time index'); 
ylabel('Amplitude'); 
axis([-10 10 0 10]); 
title('signal Y'); 

我應該怎麼做?我怎樣才能繼續添加這兩個信號?

+0

你遇到成像的情況下,像N1 = 1:3,並且N2 = 0.5:3.5? – Tokkot

回答

0

作爲一種簡化的方法,你可以衡量你的時域的大小並創建一個最終的變量S具有相同的尺寸。此外,創建一個索引校正m,使我們能夠使用n1n2作爲矩陣索引中。最後,總計xy與他們正確的偏移量。

m=1-min([n1 n2]) 
S= zeros(1+max([n1 n2]) - min([n1 n2]),1) 
S(m+[n1])= S(m+[n1])+x 
S(m+[n2])= S(m+[n2])+y 
stem([1:1:size(S,1)]-m,S) 

您可以對此進行感應式擴展以兼容更多的時間序列。

相關問題