MATLAB Answers

How to get spectrogram of an array in MATLAB?

조회 수: 6(최근 30일)
So.. I want to make spectrogram out of 4 signals that i need to add in array.
When I add them in array, it looks like this s=[x1 x2 x3 x4]; or with values: [1 1 0 1] But I'm not sure if it's proper adding..
Example of signal si this:
f1=1000; t1=0.2; x1=cos(2*pi*f1*t1);
so x1 is 1.
Is there a way of making spectrogram out of s?

  댓글 수: 0

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

채택된 답변

Star Strider
Star Strider 21 May 2020
The documentation states that the input signal is ‘specified as a row or column vector’, so you would need to loop through each column of ‘s’, saving the results (outputs you will need to request in your code) in appropriate cell arrays.
Example —
for k = 1:size(s,2)
[sp{k},w{k},t{k}] = spectrogram(s(:,k));
end
Add other arguments to the spectrogram call as necessary to produce the results you want.

  댓글 수: 6

표시 이전 댓글 수: 3
Star Strider
Star Strider 21 May 2020
It depends on what the ‘other way’ is. They need to be vectors.
Here’s an example:
Fs = 8192; % Sampling Frequency (Hz)
ft = @(d,sf) linspace(0, d*sf, d*sf)/sf; % Time Vector Function
f1=1000;
t1=0.2;
x1=cos(2*pi*f1*ft(t1,Fs));
f2=2000;
t2=0.3;
x2=cos(2*pi*f2*ft(t2,Fs));
f3=5/4;
t3=0.2;
x3=round(cos(2*pi*f3*ft(t3,Fs)));
f4=1000;
t4=0.2;
x4=cos(2*pi*f4*ft(t4,Fs));
s=[x1 x2 x3 x4];
figure
spectrogram(s,[],[],[],Fs)
The ‘ft’ function creates time vectors given time duration ‘d’ and sampling frequency ‘sf’. In then calculates these for each segment of the ‘x’ values that eventually create ‘s’.
I’m not certain what you’re doing or what you want as the result. This example should get you started.
Bridgit Schneider
Bridgit Schneider 21 May 2020
I think this will help a lot! Thank you very much for help :)
Star Strider
Star Strider 21 May 2020
As always, my pleasure!

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

추가 답변(0개)

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by