I need help plotting points with * symbol at intervals equal to Ts = 1/fs = 1/7s (Here is my code)?
2 ビュー (過去 30 日間)
古いコメントを表示
Question: Simulate the sampling of this waveform at fs = 7 Hz by plotting a * symbol at intervals
equal to Ts = 1/fs = 1/7 s.
Hint: Could use a for-loop to generate the sample time, Ts, insert it into the equation
for the 5-Hz sine wave, and plot the resulting point.
Code:
clear all;
close all;
clc;
%hwk1_NotLab_Problem1.8.m
f = 5; % Fundamental Frequency in Hz
N = 1000; % Length of array
T_T = 1; % Total Time
Ts = T_T/N;
t = 0:Ts:T_T; % Time vector
x = sin(2*pi*f*t); % 1s of 5-Hz sine wave in 1000 point array
figure;
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('1s of 5-Hz sine wave in 1000 point array');
grid on
0 件のコメント
採用された回答
Sarvesh Kale
2023 年 2 月 9 日
Does the following code help ?
t=0:0.001:1 ;
f=5;
x=sin(2*pi*f*t);
plot(t,x,'Color',[1 0 0 ],'LineWidth',2);
grid on
hold on
impulse_time = [0:1/7:1];
x_sample=sin(2*pi*f*impulse_time);
stem(impulse_time,x_sample,'*','LineStyle','none','LineWidth',2,'Color',[0 0 1]);
If you change the LineStyle property to '-' then it will have a stem like output, more information on step can be found at the following link https://in.mathworks.com/help/matlab/ref/stem.html
I hope this answers you queries, please accept answer if it does
Thank you
0 件のコメント
その他の回答 (2 件)
Jonas
2023 年 2 月 9 日
to plot with * symbol, add it to the plot command, e.g.
plot(1:10,rand(10,1),'*')
if you still need a line, add a line style:
plot(1:10,rand(10,1),'-*')
0 件のコメント
Meet
2023 年 2 月 9 日
Hi,
Based on the code that you have provided, the sampling rate can be set by changing the value of f to 7. You can add * markers in the plot by passing an additional argument for ‘Marker’ in the plot function.
Please refer the below modified code:
clear all;
close all;
clc;
%hwk1_NotLab_Problem1.8.m
%%
f = 7; % Fundamental Frequency in Hz
N = 1000; % Length of array
T_T = 1; % Total Time
Ts = T_T/N;
t = 0:Ts:T_T; % Time vector
x = sin(2*pi*f*t); % 1s of 7-Hz sine wave in 1000 point array
%%
figure;
plot(t,x,Color="r",Marker="*",MarkerEdgeColor="blue");
xlabel('Time');
ylabel('Amplitude');
title('1s of 7-Hz sine wave in 1000 point array');
grid on;
The generated plot will be as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1290180/image.jpeg)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!