Azzera filtri
Azzera filtri

vertcat error, when I run the code, at the end it tell me: Error using vertcat Dimensions of arrays being concatenated are not consistent.

1 visualizzazione (ultimi 30 giorni)
close all; clear all; clc;
%this code is created by Dr. Alaa Daher for advanced EMG signal analysis
%%import the data in the file and plot the signal
% problem11_1 =xlsread('\\tsclient\E\BIOM480A3\Hw5\p11_1.xls');
load KVGEMGPATIENT1.txt
eq1 = KVGEMGPATIENT1
%how can I make it to load all the txt files automatically or remove load
%from here and use the load from finalcode.m
%for i= 1:7
%eq1 = load ((['TBGEMGPATIENT',num2str(i),'.txt']))';
test=eq1;
fig1=figure;plot(test)
title ('original signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
% dcm_obj = datacursormode(fig1);
% set(dcm_obj,'DisplayStyle','datatip',...
% 'SnapToDataVertex','off','Enable','on')
% a1= getCursorInfo(dcm_obj)
a= input('give me the value of a: ');
b= input('give me the value of b: ');
z=cut1(test,a,b);
signal=z;
s=size(signal);
b=s(1)*s(2);
x=reshape(signal,[1,b]);
y1=x';
% y1=y1(2000:8000,:);
y1=y1-mean(y1);
% problem11_1=EMG;
% t = problem11_1(:,1);
% figure;plot(t)
% y1 = problem11_1(:, 2);
y1 = detrend(y1);
N = length(y1);% find the length of the data per second
ls = size(y1); %% size
f = 1/N;% find the sampling rate or frequency
fs = 1000;
T = 1/fs; % period between each sample
t1 = (0 : N-1) *T;%t = (0:1:length(y1)-1)/fs; % sampling period
Nyquist = fs/2;
figure;
EMG_signal=y1;
subplot (3,1,1), plot(EMG_signal,'b');
title ('EMG signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
save('EMGsignal.mat','EMG_signal')
grid on;
Y= abs(fft(y1));
Y(1) = [];
power = abs(Y(1:N/2)).^2;
nyquist = 1/(2*0.001);
freq1 = (1:N/2)/(N/2)*nyquist;
Power_spectrumen=freq1;
subplot(212), plot(Power_spectrumen,power), grid on
xlabel('Sample number (in Frequency)')
ylabel('Power spectrumen');
title({'Single-sided Power spectrum' ...
' (Frequency in shown on a log scale)'});
axis tight
%pause
% RMS=envrms2(y1,1,1000);
% figure;plot(RMS,'r');
% title('Muscle EMG RMS');
% xlabel('Points');
% ylabel('RMS(mV)');
%%% RMS of the signal
rms_y1 = sqrt(mean(y1.^2));
msgbox(strcat('RMS of EMG signal is = ',mat2str(rms_y1), ''));
rms_emg = rms (y1);
fx=fakewavelets(y1,fs);
fx=fx*fs;
fmax=max(fx);
g=find(fmax==fx);
fx1=fx(:,g:end);
EMG_fatigue=fx1;
% fx=signalpower2(y1',fs);
figure;plot(EMG_fatigue)
save('EMGfatigue.mat','EMG_fatigue')
title ('EMG fatigue');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
figure;
s=y1;
% spectrogram(s,128,120,128,1E3); % Display the spectrogram
spectrogram(s,128,120,128,1000)
title('spectrogram of the EMG signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
%%%%%AVR of the signal
arv_y1 = abs(mean(y1));
msgbox(strcat('ARV of EMG signal is = ',mat2str(arv_y1), ''));
%% remove any DC offset of the signal
% y2 = detrend(y1); %% y2 is the singal without DC offset
y2=y1;
figure;
rec_y = abs(y2);
Rectified_EMG_signal=rec_y;
plot (Rectified_EMG_signal);
save('RectifiedEMGsignal.mat','Rectified_EMG_signal')
xlabel('Sample number (in Frequency)')
ylabel('Rectified EMG signal');
title({'Rectified EMG signal' ...
' (Frequency in shown on a log scale)'});
%pause
RMS=envrms2(y1,1,100);
figure;plot(RMS,'r');
title('Muscle EMG RMS');
xlabel('Points');
ylabel('RMS(mV)');
%pause
figure;
xdft = fft(y1);
xdft = xdft(1:N/2+1);
psdx = (1/(fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:fs/length(y1):fs/2;
plot(freq,10*log10(psdx))
grid on
Power_spectrum_FFT=freq;
title(' Power spectrum FFT')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)')
%pause
%%% DFT to describe the signal in the frequency
NFFT = 2 ^ nextpow2(N);
Y = fft(y1, NFFT) / N;
f = (fs / 2 * linspace(0, 1, NFFT / 2+1))'; % Vector containing frequencies in Hz
amp = ( 2 * abs(Y(1: NFFT / 2+1))); % Vector containing corresponding amplitudes
figure;
plot (f, amp);
plot_single_sided_amplitude_spectrume_of_the_EMG_signal=f;
title ('plot single-sided amplitude spectrume of the EMG signal')
xlabel ('frequency (Hz)')
ylabel ('|y(f)|')
grid on;
%pause
% EMG features extraction
% s=s';
win_length= input('give me the length of windows: ');
% win_length=1000;
iteration_nb=(length(s)/win_length);
M=[];
a=1;
b=win_length;
Fmed=[];
P=[];
h=spectrum.welch('Hann',100,80);
Fs=1000;
sig=s;
for i=1:iteration_nb
x=sig((a:b),1);
a=a+win_length;
b=b+win_length;
m=peak2rms(x);
p=parametrage(x);
P=[P;p];
end
v=P(:,1);
variance=v;
men=P(:,2);
mean1=men;
peak2mrs=P(:,3);
RMS1=P(:,4);
% RMS1=sqrt((real(RMS1).^2)+(imag(RMS1)).^2);
RMS1=abs(RMS1);
mini=P(:,5);
maxi=P(:,6);
power=P(:,7);
mpf=P(:,8);
fmed=P(:,9);
avrfmed = mean(fmed);
msgbox(strcat('average of Fmed of EMG signal is = ',mat2str(avrfmed), ''));
pf=P(:,10);
figure;plot(v)
title ('variance of EMG signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
figure;plot(men)
title ('mean of EMG signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
figure;plot(peak2mrs)
title ('peak to RMS of EMG signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
% RMS1=RMS1';
% figure;plot(RMS1)
% title ('RMS1 of EMG signal');
% xlabel ('time (sec)');
% ylabel ('Amplitute (V)');
% grid on;
figure;plot(mini)
title ('minimum of EMG signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
figure;plot(maxi)
title ('maximum of EMG signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
figure;plot(power)
title ('power of EMG signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
figure;plot(mpf)
title ('mpf of EMG signal');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
figure;plot(fmed)
title ('median frequency "fmed" of EMG');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
%pause
% figure;plot(pf)
% title ('peak of frequency of EMG signal');
% xlabel ('time (sec)');
% ylabel ('Amplitute (V)');
% grid on;
% pause
allfeat = [freq1; rms_y1; fx1; s; arv_y1; rec_y; RMS; freq; f; avrfmed; v; men; peak2mrs; mini; maxi; power, mpf, fmed]
  2 Commenti
dpb
dpb il 14 Mag 2022
Way too much code and not even formatted...pare it down to the specific Q? related line or two.
Since the one comment can read indicates the code came from somewhere else than your own creation, support from that source might be the better choice.
Stephen23
Stephen23 il 15 Mag 2022
Modificato: Stephen23 il 15 Mag 2022
"support from that source might be the better choice."
Given the command syntax, LOAD on text files, array expansion inside the loop, brutal CLEAR ALL, flaky INPUT commands, inconsistent code formatting, lack of useful code cells or comments... that would be a surprise.
"how can I make it to load all the txt files automatically or remove load from here and use the load from finalcode.m"
Do not use LOAD. Use READMATRIX.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by