plotting fundamental wave from a square wave

조회 수: 6 (최근 30일)
Rashmil Dahanayake
Rashmil Dahanayake 2013년 12월 11일
답변: Wayne King 2013년 12월 11일
Hi,I have a simulink file and have exported the scopedata into workspace.
Now the output of the scope is a square. The objective is to plot the fundamental wave.
What I have done a) Export scope data b) fft using the following code C) The fundamental is 50hz . Either to look up the element where 50hz occur from array or find the maximum. However the maximum method doesn't produce accurate results.
Any suggestions to the code?. Also interested to know if there a direct method to achieve this from simulink itself
%fft from scope
data=ScopeData2.signals.values;
L=numel(data);
Fs=L; % sampling frequncy
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(data,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
plot(f,2*abs(Y(1:NFFT/2+1)));axis([-.01 750 0 450]);grid on;
title('Single-Sided Amplitude Spectrum of Line to Line Voltage')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
% plotting fundamental freuency (in 50hZ)
amplitude=2*abs(Y(1:NFFT/2+1));
fundamental=max(amplitude);

답변 (1개)

Wayne King
Wayne King 2013년 12월 11일
I get simulation errors trying to run your model, but if I look at the ScopesData2 struct array -- I replaced your scope block with a "To Workspace" block.
Are you sure that you don't have some sample time error somehwere, I'm getting a peak at 40-Hz in your data.
Do you have the DSP System Toolbox by any chance?

카테고리

Help CenterFile Exchange에서 Scopes and Data Logging에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by