plotting fundamental wave from a square wave

1 visualizzazione (ultimi 30 giorni)
Rashmil Dahanayake
Rashmil Dahanayake il 11 Dic 2013
Risposto: Wayne King il 11 Dic 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);

Risposte (1)

Wayne King
Wayne King il 11 Dic 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?

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by