I need help combining two sine waves
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (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 Commenti
Image Analyst
il 17 Giu 2024
You can also add a phase to shift the sine wave, if you'd rather do it that way.
Blake
il 17 Giu 2024
Image Analyst
il 17 Giu 2024
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;
Categorie
Scopri di più su Signal Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



