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
Birdman 2017년 10월 22일

0 개 추천

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.
KL
KL 2017년 10월 22일
편집: KL 2017년 10월 22일

0 개 추천

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

Excuse me, why t = 0:(1/fs):5;
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.
Thank you!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

질문:

2017년 10월 22일

댓글:

2017년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by