3
\$\begingroup\$

I have a time-based signal (Raw signal) sampled at 6 MHz and need to analyze it in freq. domain. I'm learning DSP and this is very first time I work with DSP. Could you please help to check if this code is correct or not. And I have couple of questions needed to be clarify:

  1. I've heard about linear scale and logarithm scale in order to observe the amplitude easier. Could you please explain to me, in this case, how can I get the logarithm scale?

  2. for some function in Matlab (for example fft, spectrogram, etc), how can I get the code (just in case I want to change something to adapt my need)?

input=V5k_a100; 
N=2048; L=4096; Fs=6e6; 
spectrumTemp=[];
for index=1:length(input)/L 
 slice = input(1+(index-1)*L:index*L); 
 abcd = hann(L) .* slice; 
 NFFT = 2^nextpow2(N); 
 spectrumTemp(index, :) = fft(abcd, NFFT)/L; 
end
f = [0:NFFT-1]*Fs/NFFT; 
freq = f(1:length(f)/2); 
time = [0:length(input)/L-1]*L/Fs; 
spectrum = spectrumTemp(:, 1:length(f)/2); 
mesh(time,freq',abs(spectrum'));
200_success
145k22 gold badges190 silver badges478 bronze badges
asked Aug 30, 2012 at 13:49
\$\endgroup\$
1
  • \$\begingroup\$ If you want verification that the code is correct more information will be required. In particular encountered problems. \$\endgroup\$ Commented Dec 27, 2012 at 15:44

1 Answer 1

2
\$\begingroup\$
  1. The easy way to plot something with a logarithmic scale would be to just take the logarithm of the variable.

    logspectrum = log(spectrum);

  2. The source of some files is available when you type edit function name, example:

    edit unique

However, not all Matlab source is available, so unfortunately you cannot customize everything this easily.

answered Dec 27, 2012 at 15:42
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.