I need help plotting points with * symbol at intervals equal to Ts = 1/fs = 1/7s (Here is my code)?
    조회 수: 6 (최근 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에서 Title에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






