I would like to know how can I plot amplitude and phase

1 view (last 30 days)
I would like to know how can I plot amplitude and phase for (x=sin (t)+sin(t).*cos(t) ; for t=[0:0.07:20]
is this correct? or it needs correction?
t=[1:0.07:20];
x=sin(t)+sin(t).*cos(t);
y=fft(x,272);
y1=abs(y);
f=(100/7)/272*(1:272);
plot (f,y1(1:272))
title (‘ Frequency Domain’)
xlabel("f (Hz)")
ylabel("|y1(f)|")
y2=angle(y);
stem (f,y2)

Accepted Answer

Star Strider
Star Strider on 25 Oct 2022
I tweaked your code slightly.
Try this —
t=1:0.07:20;
x=sin(t)+sin(t).*cos(t);
Fs = 1/0.07; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(t);
nfft = 2^nextpow2(L); % For Efficiency
y=fft(x,nfft)/L;
y1=abs(y);
f=(0:nfft/2)*Fn*2/nfft;
figure
plot (f,y1(1:numel(f)))
title ('‘Frequency Domain’')
xlabel("f (Hz)")
ylabel("|y1(f)|")
grid
y2=angle(y);
figure
stem (f,y2(1:numel(f)))
grid
It could be interesting to see what the unwrap function does to the phase angle ‘y2’. I leave that experiment to you.
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!