Matrix dimensions must agree error

2 views (last 30 days)
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 Comment
KSSV
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.

Sign in to comment.

Accepted Answer

Prudhvi Peddagoni
Prudhvi Peddagoni on 12 Mar 2021
Hi,
You can keep breakpoints in the code and check the values in different variables.
Hope this helps.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!