The plot of cosine is not shown
5 ビュー (過去 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
0 件のコメント
採用された回答
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
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)))
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)
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)
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))
In essence you're only computing the values at the top of each of the peaks of the cosine curve.
0 件のコメント
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

0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Measurements and Spatial Audio についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!