Help me. How to plot sqrt(0.5 + 0.5 cos(w))
이전 댓글 표시
Help me. How can I plot sqrt(0.5 + 0.5 cos(w))
Sampling frequency at 8000 Hz
close all,clear all
f = 0:4000;
w = 2*pi*f;
x = 0.5+(0.5*cos(w));
M = sqrt(x);
figure(1)
subplot(211),plot(M),grid
xlabel('\omega/\pi'),ylabel('Magnitude'),title('Magnitude Spectrum')
답변 (2개)
Birdman
2017년 10월 22일
f = 0:0.1:40;
w = f;
x = 0.5+(0.5*cos(w));
M = sqrt(x);
semilogx(w,M),grid on
xlabel('\omega/\pi'),ylabel('Magnitude'),title('Magnitude Spectrum')
Try this code. Note that for magnitude plots, you have to use semilogx.
Sampling frequency is the interval with which you sample
fs = 8000;
Now you use this to generate the 't' vector
t = 0:(1/fs):5;
then you calculate 'w'
w = 2*pi*t;
then you calculate your wave
y = sqrt(0.5+0.5*cos(w));
Now you plot y against t,
figure(1)
plot(t,y)
xlabel('\omega/\pi'),ylabel('Magnitude'),title('Magnitude Spectrum')
댓글 수: 3
Pruch Sawetratanastien
2017년 10월 22일
KL
2017년 10월 22일
when they tell you sampling frequency is 8000Hz, it means you are sampling the wave at 1/8000 second. That's why 1/fs. It is like the step size, read the following link
So when you write
0:(1/fs):5
it means you're creating a time vector from 0 to 5 seconds with a step size of 1/8000 second. You use 't' then to calculate 'w' and then the wave itself.
Pruch Sawetratanastien
2017년 10월 22일
카테고리
도움말 센터 및 File Exchange에서 Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!