The plot of cosine is not shown

6 次查看(过去 30 天)
I am representing a cosine function as a CT signal and as a DT signal. The issue is that: the CT signal is not shown in the figure below:
This the code script:
%% CT signal
t = -2:0.01:2; % sample points from 0 to 2 in steps of 0.01
xt = cos(2*pi*100*t); %
subplot(2,1,1); % Two rows, one column, first plot
plot(t,xt,'b'); % Create plot with blue line
% Label axis
xlabel('t in sec');
ylabel('x(t)');
title('Plot of cos(2\pi100t)'); % Title plot
%% DT signal
n = -40:1:40;% sample index from 0 to 40
f = 2000;
xn = cos(2*pi*(100/f)*n); % Evaluate
subplot(2,1,2); % Two rows, one column, second plot
Hs = stem(n,xn,'r','filled','markersize',4); % Stem-plot
% Label axis
xlabel('n');
ylabel('x(n)'); % Label axis
title('Stem Plot of cos(2\pi0.5n)'); % Title plot

采纳的回答

David Hill
David Hill 2022-11-16
xt will always be 1 and is plotting correctly. cos(2*pi*100*t) will always be an interger multiplied by 2*pi, and cos(2*pi)==1.

更多回答(2 个)

Steven Lord
Steven Lord 2022-11-16
What multiples of pi are you taking the cosine of?
t = -2:0.01:2;
A = 2*100*t;
What's the largest difference in absolute value between the elements of A and integer values?
delta = max(abs(A-round(A)))
delta = 5.6843e-14
So the elements of A are effectively all integer values.
Are all the elements of A (when rounded to eliminate that small difference) even or odd?
allEven = all(mod(round(A), 2) == 0)
allEven = logical
1
So essentially all the values in xt are the cosine of an even integer multiple of pi. What is the value of cos(0), cos(2π), cos(4π), cos(6π), etc.?
cospi(0:2:10)
ans = 1×6
1 1 1 1 1 1
Let's double-check your actual data. What's the cosines of pi times the values in A? How much do those values differ from 1?
max(abs(cos(pi*A) - 1))
ans = 0
In essence you're only computing the values at the top of each of the peaks of the cosine curve.

Image Analyst
Image Analyst 2022-11-16
What does CT mean? To me it means Computed Tomography. What does DT mean? What do you expect or want the period (peak to peak x-distance) to be? Perhaps you meant this?
%% CT signal
t = -2:0.01:2; % sample points from 0 to 2 in steps of 0.01
period = 1.4; % Whatever you want.
xt = cos(2*pi*t / period); %
subplot(2,1,1); % Two rows, one column, first plot
plot(t,xt,'b'); % Create plot with blue line
% Label axis
xlabel('t in sec');
ylabel('x(t)');
grid on;
caption = sprintf('Plot of cos(2 * pi * t / %.1f)', period);
title(caption); % Title plot
%% DT signal
n = -40:1:40;% sample index from 0 to 40
% Define frequency of the cosine wave (which is NOT the sampling frequency).
f = 2000;
xn = cos(2*pi*f*n); % Evaluate
subplot(2,1,2); % Two rows, one column, second plot
Hs = stem(n,xn,'r','filled','markersize',4); % Stem-plot
% Label axis
xlabel('n');
ylabel('x(n)'); % Label axis
title('Stem Plot of cos(2\pi0.5n)'); % Title plot

类别

Help CenterFile Exchange 中查找有关 Measurements and Spatial Audio 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by