Combine a waveform from a set of sine waves which are linearly increasing in frequency

10 views (last 30 days)
Hi,
I generate and plot multiple waveforms which have increasing frequency. I want to combine them at each time interval of t, but how? Please share if you know how...
for f = 1:1:200 % Upto 200 Hz
t=[0 : 0.01 : 1]
y=sin (2 * pi .* f .* t);
hold on
plot (t,y)
end
thanks

Accepted Answer

Star Strider
Star Strider on 2 Nov 2017
Try this:
t = 0 : 0.01 : 1;
for f = 1:1:200 % Upto 200 Hz
y(f,:) = sin (2 * pi .* f .* t);
end
plot (t,y)
hold on
plot(t, sum(y), ':r', 'LineWidth',2.5)
hold off
The sum is essentially zero for all columns.
  9 Comments
Star Strider
Star Strider on 3 Nov 2017
You will find this documentation for the fft (link) function helpful.
Example
t = 0 : 0.01 : 1;
for f = 1 : 2 % Upto 2 Hz
y(f,:) = sin (2 * pi .* f .* t);
end
figure(1)
plot(t,y)
hold on
plot(t, sum(y), ':r', 'LineWidth',2.5)
hold off
L = length(t); % Signal Length
Ts = t(2) - t(1); % Sampling Time Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
Fourier = fft(y, [], 2)/L; % Fourier Transform (Along Rows Of Matrix)
figure(2)
subplot(2,1,1)
plot(Fv, abs(Fourier(:,Iv))*2)
title('Amplitude')
grid
subplot(2,1,2)
plot(Fv, angle(Fourier(:,Iv)))
title('Phase')
xlabel('Frequency')
grid
The time-domain plots are in figure(1) and the frequency-domain plots are in figure(2).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!