Error using stem X must be same length as Y.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
TUAN SHARIFAH NUR FATIEHA
le 10 Avr 2023
Commenté : TUAN SHARIFAH NUR FATIEHA
le 13 Avr 2023
fs = 100000; %sampling frequency
Ts = 1/fs;
Tstart = 22.7; % change to 22.6 for 2.4s time window
N = 2500001;%number of sample for fitting
T = N*Ts;
Electrical_Output_Torque = out.ScopeData12(:,2);
currenta=out.ScopeData7(:,2);
currentb=out.ScopeData7(:,3);
currentc=out.ScopeData7(:,4);
t1 = (1:length(currenta))*Ts;
figure(1)
plot(t1,currenta,'r')
title('Current Measurement in Time Domain');
xlabel('Time [s]');
ylabel('Current [A]');
grid on
currenta_sel = currenta(t1>=Tstart&t1<Tstart+T);
currenta_sel(1) = 0;
t1_sel = t1(t1>=Tstart&t1<Tstart+T);
figure(2)%selected time in current measurement (1.6s:4s)
plot(t1_sel,currenta_sel,'r')
title('Selected Time for the Current Measurement');
xlabel('Time [s]');
ylabel('Current [A]');
grid on
%%
ca_hanning = (currenta_sel .*hann(length(currenta_sel)))';
ca_hanning_fft = fftshift(fft(ca_hanning/length(ca_hanning)))';%2
caA_abs = abs(ca_hanning_fft);
caA_abs(1)= 0;
f1= (-fs/2):1/(T-Tstart):(fs/2);
figure(3);
stem(f1,caA_abs, 'r')
set(gca,'yscal','log')
grid on
title('4.6s, Hanning');
xlabel(' \it f (Hz)');
ylabel('|S(j\omega)| [A]');
xlim([0 100])
CaA_abs(1:2:end-1,:)= [];
f1(:,1:2:end-1)= [];
%%
figure(4);
stem(f1,CaA_abs, 'r')
set(gca,'yscal','log')
grid on
title('4kW motor- Hanning window');
xlabel(' \it f (Hz)');
ylabel('|S(j\omega)| (A)');
xlim([0 100])
2 commentaires
KSSV
le 10 Avr 2023
To use stem your x and y data should be of same size/ dimensions. In your case they are not. Check why the dimensions are not equal? You need check your variable f1.
Réponse acceptée
Walter Roberson
le 10 Avr 2023
currenta=out.ScopeData7(:,2);
We are not given any information about what out is or size the various ScopeData* are. We can speculate that they are probably values output by Simulink . It is most common for Simulink scope blocks to be configured to remember only the last 10000 points. It is also common in Simulink for different parts of a model to be run at different intervals, so scope blocks in different parts of a model are not expected to have synchronized times (and so are not expected to have the same number of samples.)
currenta_sel = currenta(t1>=Tstart&t1<Tstart+T);
currenta_sel(1) = 0;
t1_sel = t1(t1>=Tstart&t1<Tstart+T);
You select a subset of the scope data anyhow, and you construct time vectors of similar length.
ca_hanning = (currenta_sel .*hann(length(currenta_sel)))';
ca_hanning_fft = fftshift(fft(ca_hanning/length(ca_hanning)))';%2
caA_abs = abs(ca_hanning_fft);
so caA_abs has size according to what was selected out of the current data.
f1= (-fs/2):1/(T-Tstart):(fs/2);
f1 is going to have size according to some fixed values. The length of f1 is not dependent on what size caA_abs turned out to be -- at least not in any direct way.
Because of cumulative floating point round-off error, you should not expect the colon operator to return the number of entries that it would if you were working algebraically. It is common for a colon operator to end up with one fewer entries than would be expected algebraically.
stem(f1,caA_abs, 'r')
We have no direct reason to expect that the sizes are going to match, and we have round-off-error reason to expect they might e different even if the rest of the calculations were correct.
You should probably be taking something like
f1 = linspace(-fs/2, fs/2, size(caA_abs,1));
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!