Filter löschen
Filter löschen

Error using plot Vectors must be the same length.

1 Ansicht (letzte 30 Tage)
Sofiya
Sofiya am 1 Mär. 2024
Kommentiert: Sofiya am 4 Mär. 2024
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))

Antworten (1)

Walter Roberson
Walter Roberson am 1 Mär. 2024
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 Kommentare
Walter Roberson
Walter Roberson am 1 Mär. 2024
Possibly you want the second assignment to t to be
t = (0:(size(s,2)-1))/fs;
Sofiya
Sofiya am 4 Mär. 2024
Thanks a million!!!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by