equation for the sum of sinusoids

조회 수: 16 (최근 30일)
Maddison Wagner
Maddison Wagner 2018년 11월 20일
편집: Adam Danz 2018년 11월 20일
Hello,
I am attempting to create a sum of sines waveform using 4 different frequencies, with the same amplitude of 1, and all with a phase of 0. Sampling rate of 60 with a duration of 30 seconds. Through reading different forums I came up with the code below, however I'm not sure I understand the pi/3, pi/4, etc. used in the x1-x4 equations below. Can anyone explain why this is included? or if there is a better more simple formula than what I have below.
Fs = 60;
Ts = 1/60;
t = 0:Ts:30
x1 = 1*cos(2*pi*.73*t+pi/3);
x2 = 1*cos(2*pi*1.33*t-pi/4);
x3 = 1*cos(2*pi*1.93*t+pi/5);
x4 = 1*cos(2*pi*2.93*t-pi/6);
x = x1 + x2 + x3 + x4;
u = numel(x);
M = zeros(u,6);
M(:,3) = x;
M(:,(1:6)~=3);
M
figure(2)
subplot(5,1,1)
h = plot(t,x1); box off; grid off
xlabel('Time(s)');
ylabel('Amplitude');
subplot(5,1,2)
h = plot(t,x2); box off; grid off
xlabel('Time(s)');
ylabel('Amplitude');
subplot(5,1,3)
h = plot(t,x3); box off; grid off
xlabel('Time(s)');
ylabel('Amplitude');
subplot(5,1,4)
h = plot(t,x4); box off; grid off
xlabel('Time(s)');
ylabel('Amplitude');
subplot(5,1,5)
h = plot(t,x); box off; grid off
xlabel('Time(s)');
ylabel('Amplitude');

채택된 답변

Adam Danz
Adam Danz 2018년 11월 20일
편집: Adam Danz 2018년 11월 20일
"I'm not sure I understand the pi/3, pi/4, etc. used in the x1-x4 equations below. Can anyone explain why this is included?"
A quick tutorial
figure;
t = 0 : 1/60 : 30;
plot(cos(t), 'k-')
hold on
The plot produced above is your base sinusoid. To change the frequency, multiply t by a value greater than one to increase the frequency or a value less than one to decrease the frequency.
plot(cos(t * 1.2), 'b-') %increase the freq.
To change the phase, add or subtract values from t. Adding values to t will shift the sinusoid leftward; subtractive values will shift if rightward. Try the block below.
figure
plot(cos(t), 'k-')
hold on
plot(cos(t + pi/6), 'b:') %shift leftward
You're working in radians so pi/6 is 30 degrees. If you shift it 360 degrees (2*pi in radians) the black and blue curves will overlap.
In your code (below), t is multiplied by 2*pi*.73 for whatever reason which changes the frequency of your sinusoid. The result is then added to pi/3 which shifts the phase. The reason the values are in fractions of pi is because you're working in radians.
x1 = 1*cos(2*pi*.73*t+pi/3);
"is a better more simple formula than what I have below"
That entirely depends on what you're doing. If you're just trying to create some sinusoids and their parameters don't matter, you could replace the 2*pi*.73 with whatever value that equals.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by