Error using plot Vectors must be the same length.
1 次查看(过去 30 天)
显示 更早的评论
Create a signal consisting of two successive sine waves with frequencies of 10 Hz and 20 Hz and additive noise. Filter the signal with an adaptive selective filter and plot in one graphic window: 1) the initial signal; 2) filtered signal; 3) error signal.
fs = 200; N = 1000; t = (0:(N-1))/fs;
s1 = sin(2*pi*10*t); s2 = sin(2*pi*20*t);
s = [s1, s2]; v = 0.4*randn(size(s));
t = (0:(N-1))/fs;
x = s + v;
delay = 5; % затримка
xd = [x(delay:end), zeros(1,delay-1)];
L = 64; mu = 0.001;
[w, y, e] = lms(x, xd, mu, L);
figure(4)
subplot(311), plot(t, x), grid on
subplot(312), plot(t,y), grid on
N = 1000
subplot(313), plot(t,e), grid on
fprintf('var(e) = %4.3f\n',var(e))
0 个评论
回答(1 个)
Walter Roberson
2024-3-1
t = (0:(N-1))/fs;
s1 = sin(2*pi*10*t); s2 = sin(2*pi*20*t);
s = [s1, s2];
s is a row vector that is twice as long as t (since it is two vectors put together, each the same size as t)
x = s + v;
x is the same size as s, so is twice as large as t
subplot(311), plot(t, x), grid on
there you try to plot t against x but x is twice as large as t.
2 个评论
Walter Roberson
2024-3-1
Possibly you want the second assignment to t to be
t = (0:(size(s,2)-1))/fs;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!