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!



