1
$\begingroup$

I need to

  • read a .wav file
  • make a 2D matrix from it using the STFT
  • generate its singular value decomposition
  • do some watermarking

but I can't build the original matrix again via matrix multiplication:

 x = audioread('0.wav');
 stft = spectrogram(x); 
 [U,S,V] = svd(stft);
 stftb=U*S*V.';

The problem is that STFT and STFTb are not the same.

$\endgroup$
  • $\begingroup$ What do you get when you type max(max(abs(stftb-stft)))? $\endgroup$ – Matt L. Jun 26 '15 at 9:59
  • $\begingroup$ @MattL.ans = 76.2564 $\endgroup$ – Narges Jun 26 '15 at 14:23
  • $\begingroup$ OK, since your matrices are complex-valued schvaba986's answer is the solution. $\endgroup$ – Matt L. Jun 26 '15 at 15:54
3
$\begingroup$

Don't have enough reputation to comment but you need to use the conjugate transpose in your formula for the result to be correct. So try stftb=U*S*V'; in the last line of code. Note that I removed the . which makes a difference since the matrices you are working with are complex.

$\endgroup$
  • $\begingroup$ Why are they complex? stft is real-valued, isn't it? $\endgroup$ – Matt L. Jun 26 '15 at 10:03
  • $\begingroup$ I think that MATLAB divides the signal in 8 segments and returns a complex value when you call the spectrogram function like that. $\endgroup$ – schvaba986 Jun 26 '15 at 10:20
  • $\begingroup$ I guess you're right, spectrogram actually computes the short-time Fourier transform, not the spectrogram (which would be real-valued because it's a squared magnitude). $\endgroup$ – Matt L. Jun 26 '15 at 10:31
  • $\begingroup$ Oh, now I understand your comment... You can use multiple outputs to get a PSD among other values but like this it's only the STFT $\endgroup$ – schvaba986 Jun 26 '15 at 11:05
  • $\begingroup$ @schvaba986 thanks, you're right. Note that now the result of max(max(abs(stftb-sftt))) is 7.6810e-14 $\endgroup$ – Narges Jun 26 '15 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.