Confusion in matrix multiplication

2 views (last 30 days)
Sergei
Sergei on 25 Nov 2024
Commented: Voss on 4 Dec 2024
Dear all, the magnitude of the second graph does not make any sence: why is it so low?
These are absolutely same vectors, but the second graph is just truncated to half of the first one.The vector "frequency_domain" is real-valued, the vector "spectrum_normalized" is complex-valued.
Could you please help me to fix it?
Thank you in advance!
UPD: spectrum_normalized was just a matrix, not a vector, due to a typo.... Check dimensions first.

Accepted Answer

Voss
Voss on 25 Nov 2024
spectrum_normalized is a matrix (I know that because subplot(2,4,2) contains many lines). Thus, to plot the one-sided spectrum, you'd plot the first N/2 rows or the first N/2 columns, not the first N/2 elements, i.e.:
plot(frequency_domain(1:N/2), abs(spectrum_normalized(1:N/2,:)));
% or
plot(frequency_domain(1:N/2), abs(spectrum_normalized(:,1:N/2)));
% but not
plot(frequency_domain(1:N/2), abs(spectrum_normalized(1:N/2)));
depending on whether each row or each column of spectrum_normalized corresponds to an element of the vector frequency_domain.
  7 Comments
Sergei
Sergei on 4 Dec 2024
Edited: Sergei on 4 Dec 2024
I figured it out! the problem was that spectrum_normalized was a matrix, not a vector, as you have said. It was due to a transposed by mistake matrix in multiplication by which spectrum_normalized is obtained.
Thank you for your time and attention to my question! Sorry for the confusion. Checking the dimensions matters, I consider it as a lesson...
Voss
Voss on 4 Dec 2024
You're welcome! Good to know it's sorted out.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!