How to plot separately figures?

3 visualizaciones (últimos 30 días)
Talha Gungor
Talha Gungor el 21 de Mayo de 2021
Respondida: Sulaymon Eshkabilov el 22 de Mayo de 2021
I want to plot a second figure with 2x1 subplot, the first subplot must contain both x (original signal) and xn(noise added signal), and second subplot must contain x (original signal) and y(filtered signal). What should I change ?
fs = 5000;
tiv=1/fs;
t = 0:tiv:0.05;
t1=2*pi*100*t;
t2=2*pi*500*t;
x = sin(t1)+0.7*cos(t2);
xn = x + 5.*randn(size(t));
originalSpectrum = fft(x);
noisySpectrum = fft(xn);
xdb=mag2db(originalSpectrum);
xndb=mag2db(abs(noisySpectrum));
figure(1)
subplot(2, 1, 1);
plot((xdb),'b-', 'LineWidth', 2);
xlabel('Frequency (Hz)')
ylabel('Magnitude(dB)')
title('Original Signal (No Noise)')
subplot(2, 1, 2);
plot(abs(xndb), 'b-', 'LineWidth', 2);
xlabel('Frequency (Hz)')
ylabel('Magnitude(dB)')
title('Noisy Signal')
d = designfilt('lowpassfir', 'PassbandFrequency', 500, ...
'StopbandFrequency', 600, ...
'PassbandRipple', 1, 'StopbandAttenuation', 100, ...
'SampleRate', fs);
y=filter(d,x);
figure(2)
subplot(2,1,1);
plot(x); hold on; plot(xn);
subplot(2,1,2);
plot(x); hold on; plot(y);
  1 comentario
Jaya
Jaya el 22 de Mayo de 2021
What is the problem you are facing? Please state it. Because the code is producing the graphs.

Iniciar sesión para comentar.

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 22 de Mayo de 2021
Here are the plot parts as you were aiming to get:
...
subplot(2,1,1);
plot(t, x, 'b', t, xn, 'r'); grid on
legend('Original Signal', 'Noise Added Signal')
ylabel('Signal')
subplot(2,1,2);
plot(t, x, 'b', t, y, 'r');
legend('Original Signal', 'Filtered Signal', 'location', 'southwest')
ylabel('Signal'), xlabel('Time')
Good luck

Más respuestas (0)

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by