# Matrix dimensions must agree error

3 views (last 30 days)
Jordan Reece Duggan on 9 Mar 2021
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
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
KSSV on 10 Mar 2021
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 on 12 Mar 2021
Hi,
You can keep breakpoints in the code and check the values in different variables.
Hope this helps.
Jordan Reece Duggan on 12 Mar 2021
It did thanks!

### Categories

Find more on Spectral Analysis in Help Center and File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!