Matrix dimensions must agree error

조회 수: 1 (최근 30일)
Jordan Reece Duggan
Jordan Reece Duggan 2021년 3월 9일
댓글: Jordan Reece Duggan 2021년 3월 12일
Hi all,
Ive got some code from my tutor thats meant to be filtering a medical signal (ecc) by multiplication in the frequency domain, all goes well till Y5=X5.*HBR; , there it says matrix dimensions must agree, been rattling my head about this for a while but cant figure out where the conflict is, tutor wont help either.
fs=500;
n=2;
Wn=40/250;
[B, A] = butter(n,Wn);
printsys(B, A, 'z' );
x1=eye(1,1000); % create an impulse
plot(x1)
pause
hb=filter(B, A, x1); % calculate the impulse response of the Butterworth filter
plot(hb)
pause
freqz(B, A, 1024, fs)% create frequency response plots
set(gca, 'XScale', 'log')
pause
medical = 'medical signal.dat'; %this needs to be the location of the waveform
xmed = load(medical);
plot(xmed) % display the noisy waveform
pause
X5=fft(xmed)/length(xmed); % calculate the FFT of the signal
f=fs/length(X5)*(0:length(X5)-1);
plot(f, abs(X5)); % display the signal spectrum
pause
HBC = fft(hb)/length(hb); % calculate the FFT of the filter impulse response
HBR = HBC.' ; % convert the result to a row vector
f=fs/length(HBR)*(0:length(HBR)-1);
plot(f, abs(HBR)); % display the magnitude of the filter frequency response
pause
Y5 = X5.'HBR; % multiply the signal fft by the filter frequency response
plot(f,Y5) % display the frequency response of the result
pause
y5=ifft(Y5)*(length(Y5))^2; % convert the result back into the time domain
plot(y5) % display the filtered waveform
pause
Any suggestions on whats causing the matrixes to conflict?
Cheers
  댓글 수: 1
KSSV
KSSV 2021년 3월 10일
This lineL
Y5 = X5.'HBR; % multiply the signal fft by the filter frequency response
is not correct. You need to change it.
Learn about debugging and check the dimensions where you are getting error.

댓글을 달려면 로그인하십시오.

채택된 답변

Prudhvi Peddagoni
Prudhvi Peddagoni 2021년 3월 12일
Hi,
You can keep breakpoints in the code and check the values in different variables.
Hope this helps.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by