Help me. How to plot sqrt(0.5 + 0.5 cos(w))

1 view (last 30 days)
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')

Answers (2)

Birdman
Birdman on 22 Oct 2017
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 on 22 Oct 2017
Edited: KL on 22 Oct 2017
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 Comments
KL
KL on 22 Oct 2017
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!