how do i calculate THD for m- file waveforms(waveforms in sampling) with and suppression of harmonics for comparison

10 visualizzazioni (ultimi 30 giorni)
i am doing the project: Analysis of harmonics using wavelet packet transform Actually i am doing the project in MATLAB coding and my project objective is to analyse the signal with disturbance and have to suppress those harmonics which present in that disturbance signal.
so, in order to show the difference by comparing, i need to find Total Harmonic Distortion(THD) for the signal with disturbance and after suppressing those disturbance.
I tried to find THD in MATLAB coding, but yet i did not get any clear result for THD measurement in coding sir. so please give me an idea to measure THD for signal waveform in M-File sir.
thank you sir

Risposta accettata

Wayne King
Wayne King il 22 Set 2011
Hi, You can certainly calculate THD using a spectrum object and the msspectrum method from the Signal Processing Toolbox.
For example:
% Creating a signal
t = linspace(0,1,1e3);
x = cos(2*pi*60*t)+0.05*sin(2*pi*120*t)+0.01*cos(2*pi*180*t);
% Constructing the spectral analysis object
hper = spectrum.periodogram;
% Getting the mean-square spectrum. These are square magnitudes
mspec = msspectrum(hper,x,'Fs',1e3,'NFFT',length(x));
% Creating a data vector with the fundamental and two harmonics
datavec = mspec.Data(61:60:181);
% Calculating the THD
THD = sqrt(sum(datavec(2:end)))/sqrt(datavec(1))
Multiply by 100 to express as a percentage.
%Using fft
xdft = fft(x);
datavec = xdft(61:60:181);
THD = norm(datavec(2:end),2)/norm(datavec(1),2)
The trick is for you to correctly identify the DFT bins that contain your fundamental and harmonics, but that should not be difficult. You can manipulate the NFFT input to fft() or msspectrum() so that your fundamental and harmonics fall on a DFT bin.
Hope that helps,
Wayne

Più risposte (1)

thangam
thangam il 18 Nov 2011
% Sampling (harmonic injection)
fs = 1600; % Sampling rate [Hz]
Ts = 1/fs; % Sampling period [s]
duration = 0.5; % Duration [s]
t = 0 : Ts : duration-Ts; % Time vector
% Original signal
x = sin(2 .* pi .* 50 .* t);
figure, plot(x)
% Harmonics
x1 = sin(2 .* pi .* 150 .* t);
y=x+x1;
figure, plot(y)
in the above program i want to compare x (sine signal) and y (sine with harmonics signal) by finding Total harmonic distortion(THD), RMS value of fundamental harmonic component.
so how to find above factors for those signals (signals in samples).
thank u in advance sir.

Categorie

Scopri di più su Measurements and Feature Extraction in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by