generate a sine wave that ends at 0
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ali Albaidhani
el 5 de Abr. de 2022
Comentada: Sam Chak
el 5 de Abr. de 2022
Hello everyone,
As the title says, i'm trying to generate a sine wave that ends at 0. I have this problem when i try to generate a signal with a frquency higher than 1, the signal does not stop at 0.
I use the following code for the sine wave:-
%---------------------
Fs=5000;
f=159.2;
t1=1;
t = 0 : 1/Fs : t1-1/Fs;
A=0.1;
sine=A*sin(2*pi*f*t);
%---------------------
is there any way to make the signal stops at 0? even if that means that the signal moves past the 5000 points.
Regards
Ali
2 comentarios
Sam Chak
el 5 de Abr. de 2022
Wow, I don't know the existence of this function (Introduced in R2018b).
Respuesta aceptada
Sam Chak
el 5 de Abr. de 2022
Editada: Sam Chak
el 5 de Abr. de 2022
Are you trying to make the Sine wave to hit 0 at the end of the simulation?
f = 159.2; % frequency
Fs = 35*f;
desired_Tend = 1;
n = round(f*desired_Tend);
T = 1/f; % period
t = 0:1/Fs:n*T;
A = 0.1; % amplitude
x = A*sin(2*pi*f*t);
plot(t, x, 'linewidth', 1.5)
axis([0.99 1 min(x) max(x)])
grid on
xlabel('t')
ylabel('x(t)')
title('Sine Wave')
x(length(t))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/953324/image.png)
6 comentarios
Sam Chak
el 5 de Abr. de 2022
I have edited the script in the Answer. This allows you to compute the nearest integer.
desired_Tend = 2;
n = round(f*desired_Tend); % calculate the nearest integer
Más respuestas (0)
Ver también
Categorías
Más información sobre Multirate Signal Processing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!