How to plot separately figures?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Talha Gungor
le 21 Mai 2021
Réponse apportée : Sulaymon Eshkabilov
le 22 Mai 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 commentaire
Jaya
le 22 Mai 2021
What is the problem you are facing? Please state it. Because the code is producing the graphs.
Réponse acceptée
Sulaymon Eshkabilov
le 22 Mai 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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!