I need help plotting points with * symbol at intervals equal to Ts = 1/fs = 1/7s (Here is my code)?
1 次查看(过去 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:
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!