Effacer les filtres
Effacer les filtres

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

12 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Star Strider
Star Strider le 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 commentaires
Nathan Kennedy
Nathan Kennedy le 3 Nov 2017
The comment about fft is something I would like to add in
Star Strider
Star Strider le 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).

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by