MATLAB: How to add harmonics to a sine wave harmonics 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 Best Answer Mmm, actually is very easy. Just add them to the original signal:% Samplingfs = 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 vectornoSamples = length(t); % Number of samples% Original signalx = 220.*sin(2 .* pi .* 50 .* t);% Harmonicsx1 = 100.*sin(2 .* pi .* 100 .* t);x2 = 100.*sin(2 .* pi .* 200 .* t);x3 = 100.*sin(2 .* pi .* 300 .* t);% Contaminated signalxn = x + x1 + x2 + x3;% Frequency analysisf = 0 : fs/noSamples : fs - fs/noSamples; % Frequency vector% FFTx_fft = abs(fft(x));xn_fft = abs(fft(xn));% Plotfigure(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! Related SolutionsMATLAB: How to perform FFT on this signal and frequency domain Try this:[pxx1,f1] = pwelch(y1,512,66.7,[],1000);[pxx2,f2] = pwelch(y2,512,66.7,[],1000);figure(1);semilogx(f1,pxx1);xlabel('Frequency(Hz)');title('2*pi*50*t');figure(2);semilogx(f2,pxx2);xlabel('Frequency(Hz)');title('2*pi*250*t');You will see each signal's frequency domain plot, which has peaks at 50 and 250 Hz respectively. MATLAB: Function inside function using lsqcurvefit clear all;clc;Okay, so this is a script, not a function.x=[ ];Ln1=x(1);Ln2=x(2); % necks lengthS1=x(3); S2=x(4); % necks areaV1=x(5); V2=x(6); % Cavities volumeYou initialize x to empty, and then try to use 6 values out of it. Related QuestionHow to plot the spectrum of a high frequency sine wave of above 1GHzHow do i calculate THD for m- file waveforms(waveforms in sampling) with and suppression of harmonics for comparison
Best Answer