How to plot separately figures?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jaya
2021-5-22
What is the problem you are facing? Please state it. Because the code is producing the graphs.
采纳的回答
Sulaymon Eshkabilov
2021-5-22
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!