my graph looks weird

6 Ansichten (letzte 30 Tage)
Sachini Perera
Sachini Perera am 16 Apr. 2021
Kommentiert: Sachini Perera am 16 Apr. 2021
Hi,
My code is below and the answer i got also is below. But it looks weird with a lot of areas shaded. I want to remove the shaded part and make it so that only the lines are shown. How do i do this ?
fs = 200;
ts = 1/fs;
t = 0:ts:5;
z2 = 8*cos(30*pi*t+pi/3)+6*sin(50*pi*t-pi/3)+8*cos(70*pi*t-pi/4);
Y = fft(z2);
L = length(Y);
P2 = Y/L;
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = fs*(0:(L/2))/L;
figure;
subplot(221)
stem(f,abs(P1),'linewidth',0.5);grid on; xlim([-40 40]);
title('Single-Sided Amplitude Spectrum of z_2(t)')
xlabel('f (Hz)');ylabel('|P1(f)|');
subplot(222)
stem(f,angle(P1)*57.3,'linewidth',0.5);grid on; xlim([-40 40]);
title('Single-Sided Phase Spectrum of z_2(t)')
xlabel('f (Hz)');ylabel('Degrees');
N = nextpow2(length(z2));
X = fftshift(fft(z2,2^N));
X = 2* X / length(z2);
k = -(length(X)-1)/2:1:length(X)/2;
f = k/length(X) * fs;
subplot(223);
stem(f,abs(X),'linewidth',0.5);grid;
xlabel('Frequency in Hz');
ylabel('Amplitude');xlim([-40 40]);
title('Double sided Magnitude spectrum of z_2(t)');
subplot(224);
stem(f,angle(X)*57.3,'linewidth',0.5);grid;
xlabel('Frequency in Hz');
ylabel('Amplitude');xlim([-40 40]);
title('Double sided Phase spectrum of z_2(t)');

Akzeptierte Antwort

Jan
Jan am 16 Apr. 2021
Maybe you want to remove the markers?
stem(f,angle(X)*57.3,'linewidth',0.5, 'Marker', 'none');
If you want something else, explain, what "only the lines are shown" means.
  1 Kommentar
Sachini Perera
Sachini Perera am 16 Apr. 2021
sorry for the poor explanation. When i meant only lines i only wants to show the important frequency components. For example, in the first subplot i only wants to show the 3 points that is has a higher amplitude than others.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by