Help me. How to plot sqrt(0.5 + 0.5 cos(w))
2 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
回答(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.
KL
2017-10-22
编辑:KL
2017-10-22
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 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!