plotting fundamental wave from a square wave

1 visualización (últimos 30 días)
Rashmil Dahanayake
Rashmil Dahanayake el 11 de Dic. de 2013
Respondida: Wayne King el 11 de Dic. de 2013
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);

Respuestas (1)

Wayne King
Wayne King el 11 de Dic. de 2013
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?

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by