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

조회 수: 13 (최근 30일)
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

채택된 답변

Wayne King
Wayne King 2011년 9월 22일
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

추가 답변 (1개)

thangam
thangam 2011년 11월 18일
% 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.

카테고리

Help CenterFile Exchange에서 Measurements and Feature Extraction에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by