I need help combining two sine waves
이전 댓글 표시
Hello. I am trying to learn how to end an ascending sine wave at the start of a signal and end a descending sine wave at the end of a signal. Here is what I have so far:
f=1000;
n=10;
T=1/f;
t=(0:T/100:n*T);
s = sin(2*pi*t*f);
e = (-expm1(-t*250));
e2 = (exp(-t*250));
n = s .* e;
m = e2 .* s;
fix = n + s + m;
plot(t,fix);
I am still doing research on how to properly add them but any help from others would be appreciated.
채택된 답변
추가 답변 (2개)
How about using cos() instead of sin() and adjusting your ending time:
f=1000;
n=10;
T=1/f;
t=(0:T/100:n*T - T/2);
s = cos(2*pi*t*f);
e = (-expm1(-t*250));
e2 = (exp(-t*250));
n = s .* e;
m = e2 .* s;
y = n + s + m;
plot(t, y, 'LineWidth', 3);
grid on;
If this is not what you want then supply a screenshot of what you want the plot to look like.
댓글 수: 3
Image Analyst
2024년 6월 17일
You can also add a phase to shift the sine wave, if you'd rather do it that way.
Blake
2024년 6월 17일
Image Analyst
2024년 6월 17일
If it does what you want, I'm not going to mess with it. It's only a few lines of code. the only thing I would do it to add comments and make your variable names long and descriptive. Right now it's looks like an alphabet soup of code and might be hard for some one else, or you later, to figure out what's going on.
f = 1000; % Frequency of sine wave in Hz
n = 10; % Number of periods to generate
T = 1 / f; % Period of sine wave in seconds
t = (0:T/100:n*T); % Time vector
% Generate sine wave
s = sin(2 * pi * f * t);
% Define envelope functions
riseTime = n / 10; % Time in seconds over which sine wave rises
fallTime = n / 10; % Time in seconds over which sine wave falls
% Envelope for rising part
riseEnvelope = min(1, t / riseTime);
% Envelope for falling part
fallEnvelope = min(1, (n * T - t) / fallTime);
% Combined envelope
envelope = min(riseEnvelope, fallEnvelope);
% Modulated sine wave
modulatedSine = s .* envelope;
% Plot the result
figure;
plot(t, modulatedSine);
xlabel('Time (s)');
ylabel('Amplitude');
title('Combined Ascending and Descending Sine Wave');
grid on;
카테고리
도움말 센터 및 File Exchange에서 Signal Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



