필터 지우기
필터 지우기

how to add harmonics to a sine wave ?

조회 수: 45 (최근 30일)
yuvi
yuvi 2011년 5월 17일
댓글: Pham Duy Phuoc 2015년 10월 27일
hi to all
i want to add to a sine wave (220volt and 50hz ) harmonics and to see them in a spectrum ( 50hz , 150hz ,250hz ....)
any suggestions ?
thanks
  댓글 수: 1
Pham Duy Phuoc
Pham Duy Phuoc 2015년 10월 27일
function y = harmonic(x,k)
% assumes that x is a column vector
assert(size(x,1) > 0);
assert(size(x,2) == 1);
% Interpolate by k and add k-th harmonic:
y = interp(x,k) + repmat(x,k,1);
end

댓글을 달려면 로그인하십시오.

채택된 답변

Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 5월 17일
Mmm, actually is very easy. Just add them to the original signal:
% Sampling
fs = 1000; % Sampling rate [Hz]
Ts = 1/fs; % Sampling period [s]
fNy = fs / 2; % Nyquist frequency [Hz]
duration = 10; % Duration [s]
t = 0 : Ts : duration-Ts; % Time vector
noSamples = length(t); % Number of samples
% Original signal
x = 220.*sin(2 .* pi .* 50 .* t);
% Harmonics
x1 = 100.*sin(2 .* pi .* 100 .* t);
x2 = 100.*sin(2 .* pi .* 200 .* t);
x3 = 100.*sin(2 .* pi .* 300 .* t);
% Contaminated signal
xn = x + x1 + x2 + x3;
% Frequency analysis
f = 0 : fs/noSamples : fs - fs/noSamples; % Frequency vector
% FFT
x_fft = abs(fft(x));
xn_fft = abs(fft(xn));
% Plot
figure(1);
subplot(2,2,1);
plot(t, x);
subplot(2,2,2);
plot(t, xn);
subplot(2,2,3);
plot(f,x_fft);
xlim([0 fNy]);
subplot(2,2,4);
plot(f,xn_fft);
xlim([0 fNy]);
Just some quick code. I tested it and it works.
Hope it helps ;-) . Keep coding!
  댓글 수: 2
Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 5월 17일
Notice how the harmonics have an amplitude of 100 in order to be visualized in the spectrum plot. Otherwise, the original signal's magnitude (220) would be too big compared to the harmonics one.
yuvi
yuvi 2011년 5월 17일
THANKS A LOT !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by