# Why is my fundamental frequency at the 15th harmonic order

조회 수: 2 (최근 30일)
Jmv 2020년 5월 4일
댓글: Rena Berman 2020년 5월 14일
Dear Matlab Community.
I am trying to implement a code to show harmonic content and order in Matlab. my fundamental is supposed to be at harmonic order 1, however the ouput plot I am getting is wrong and I am having difficulies proceeding.
I would really apreciate any help. Thanks
v = D(:,2);
Signal = D(:,2);
Ts = 0.00005; % Sampling Interval (seconds)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2;
%PERFOM FFT
N = length(Signal);
meanSignal = mean(Signal); % ‘Signal’ Mean
FTSignal = fft(Signal-meanSignal)/N;
Fv = linspace(0, 1, fix(numel(FTSignal)/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
%Plotting Harmonics (THD)
har_mag = abs(FTSignal(Iv))*2;
figure;
bar(har_mag(1:20),0.4)
xlabel('Harmonic Order','fontsize',10);
ylabel('Voltage (V)','fontsize',10)
hold off
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Rik 2020년 5월 5일
Why did you edit away important parts of your question and delete several comments? That is extremely rude.
Rena Berman 2020년 5월 14일

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

### 채택된 답변

Star Strider 2020년 5월 4일
I am not certain what you are doing, or what result you want.
One problem is that you also need to specify the x-values of the bars in your bar call:
bar(Fv(1:20), har_mag(1:20),0.4)
If you want to find all the relevant peaks and their frequencies, add these lines after your existing (posted) code:
[pks,locs] = findpeaks(har_mag, 'MinPeakProminence',0.5);
FreqPeaks = table(Fv(locs)', pks, 20*log10(pks), 'VariableNames',{'Freq', 'Amp', 'dB'})
figure
plot(Fv, 20*log10(har_mag))
hold on
plot(Fv(locs), 20*log10(har_mag(locs)), '+r')
hold off
grid
axis([0 1200 -15 60])
The ‘FreqPeaks’ table has all the identified peaks (linear and dB) and their associated frequencies.
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Star Strider 2020년 5월 4일
As always, my pleasure!
The ‘FreqPeaks’ table changes again so the fourth column is now the percentage of the fundamental amplitude:
FreqPeaks = table(Fv(locs)', Fv(locs)'/Fv(locs(1))', pks, pks/pks(1)*100, 'VariableNames',{'Freq', 'HarmNr', 'Amp', 'PctFund'})
and the bar plot becomes:
figure
bar(FreqPeaks{:,2}, FreqPeaks{:,4})
xlabel('Harmonic Number')
ylabel('Percent of Fundamental Amplitude')
xlim([0 20])
Setting the y-scale to logarithmic makes them a bit easier to see:
figure
bar(FreqPeaks{:,2}, FreqPeaks{:,4})
set(gca, 'YScale','log')
xlabel('Harmonic Number')
ylabel('Percent of Fundamental Amplitude')
xlim([0 20])
Choose the one that works best in your application.
Star Strider 2020년 5월 4일
As always, my pleasure!
I wasn’t initially certain what you want to do. I’m glad we got this sorted!

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

### 추가 답변 (1개)

Rafael Hernandez-Walls 2020년 5월 4일
why don't use the FTTSHIFT, this function Shift zero-frequency component to center of spectrum.

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

### 카테고리

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