Azzera filtri
Azzera filtri

Error using plot Vectors must be the same length.

1 visualizzazione (ultimi 30 giorni)
Sofiya
Sofiya il 1 Mar 2024
Commentato: Sofiya il 4 Mar 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))

Risposte (1)

Walter Roberson
Walter Roberson il 1 Mar 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.

Community Treasure Hunt

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

Start Hunting!

Translated by