Confusion in matrix multiplication
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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.

채택된 답변
Voss
2024년 11월 25일
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
Sergei
2024년 11월 25일
Thank you, thant helped! I am so glad because i was trying to find the mistake for a lot of time<3
Could you please tell, why so or where to find this information? Thank you again!
also if i create a vector one_sided_spectrum = spectrum_normalized(1:N/2) how then to plot this signal?
plot(frequency_domain(1:N/2), abs(one_sided_spectrum(1:end,:))); does not work
Voss
2024년 11월 25일
"why so or where to find this information?"
The following page has information about array indexing. The section "Linear Indexing" explains what happens when you index a matrix with only one subscript (as in the expression spectrum_normalized(1:N/2)).
"if i create a vector one_sided_spectrum = spectrum_normalized(1:N/2)"
spectrum_normalized(1:N/2) is a vector consisting of the first N/2 elements of spectrum_normalized.
Now, I don't know how or whether that vector corresponds to frequency_domain because I don't know whether the spectra are stored as rows or columns of spectrum_normalized.
If each column of spectrum_normalized is a spectrum (i.e., each row corresponds to one frequency value in frequency_domain), then spectrum_normalized(1:N/2) is the first half of the first spectrum (i.e., it's the same as spectrum_normalized(1:N/2,1). If this were the case, the plot command you showed would work and produce something meaningful.
However, if each row of spectrum_normalized is a spectrum (i.e., each column corresponds to one frequency value in frequency_domain), then spectrum_normalized(1:N/2) is the first value (i.e., the value corresponding to the first frequency) of each of the first N/2 spectra (assuming spectrum_normalized has at least N/2 rows - and if not, then it includes samples from the second and possibly subsequent values of each spectra). If this were the case, the plot command you showed would run but produce incoherent nonsense. Since you say the plot command didn't work, I guess this is the situation you have. So in that case, to plot the first half of all spectra:
plot(frequency_domain(1:N/2), abs(one_sided_spectrum(:,1:N/2)))
or to plot the first half of some particular spectra:
to_plot = [1 3 10]; % select the spectra to plot
plot(frequency_domain(1:N/2), abs(one_sided_spectrum(to_plot,1:N/2)))
The thing is spectrum_normalized is not a matrix, it is a vector that obtained by a line spectrum_normalized = fft(signal)/N, where "signal" is a vector of size N.
The lines you provided in the first answer solved the problem: the difference in order in values dissappeared and it looks beautiful now. But for me it does not make sence as spectrum_normalized is a vector, not a matrix, as I understand. Could you please explain how you came up with the lines in your first answer
If spectrum_normalized is a vector and not a matrix, then
plot(frequency_domain, abs(spectrum_normalized));
would've produced one plotted line in subplot(2,4,2).
But in fact multiple lines exist in that subplot, which indicates either (1) spectrum_normalized is a matrix in which case the plot command creates multiple lines, or (2) you've done some plotting into that subplot axes using code not shown in the question.
You can check the size of spectrum_normalized in right before you plot it in your code, by running
whos spectrum_normalized
or
size(spectrum_normalized)
immediately before subplot(2,4,2).
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
2024년 12월 4일
You're welcome! Good to know it's sorted out.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
