Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Matlab algorithm and power spectrum

Status
Not open for further replies.

kgl_13gr

Member level 5
Joined
May 11, 2004
Messages
84
Helped
13
Reputation
26
Reaction score
12
Trophy points
1,288
Activity points
745
Hello. I have some problem here and either my knowledge is not enough or something I cant figure out is wrong. Its pretty simple I suppose.
I enter in Matlab the signal x=sin(2*pi*1000*t)+0.05*sin(2*pi*1e5*t)
where t=1:1e-8:0.002; and try to estimate the power spectrum with the following m-file (which is not mine).
The question is: This signal isnt supposed to have a PSD with two peaks one at 1kHz and one at 100kHz? The algorithm's output gives only the 100kHz peak. Thats basically the question. If you have time to look at the m file too that would be great! Thanks a lot.

I use the syntax: spektrumfromdata(x,1e3,1e8,1000,1)
 

Try with a wider time window, for example t = 0 : 1e-8: 0.01.

Regards,

Berraco.
 

Hello kgl_13gr

Put t=1e-8:1e-8:0.002;
Observe the figure: You do have a peak at 1 KHz, but it is a bit spread to the adjacent bins. Take into account that the space between bins of the spectrum (resolution) is 500 Hz, and that both axis are in log scale.
Look at the two peaks at 1K and 100 KHz: their ratio is 26 dB, that is the ratio of their amplitudes (20 times). Both peaks have a spread of 4.5 dB to the adjacent bins.

The peak at 1 KHz looks bad because of the log scale in frequency.
Plot the frequency axis in linear scale replacing semilogx() by plot() at the end of the file. The two peaks appear at the left of the figure (you have to zoom it in order to see the peaks). You will see that they don’t look very different.

Now remove the Blackman window replacing W1=blackman(Np1); by W1=ones(size(amp)); Now the peaks are extremely sharp because there is an exact number of cycles of both frequencies in the data vector. If this were not the case, the peaks without windowing the data would be spread and the windowing would make them sharper.

Let’s continue if there is any doubt.
Regards

Z
 

Thanks a lot Z! You are completely right! Now some more...
I simulate a system with SIMULINK (its a transfer function which approximates an integrator). You can find the system and the parameters in the jpg. So, the input signal is 10kHz and the output if you see the transient output in the scope is a 10KHz signal but distorted.
Two questions:
1) No matter what sample time I use in Simulink the output vector tout has a step of 1e-7.Why?
2)(and important). When I take the power spectrum with the Spektrufromdata algorithm I sent above I get no peak at 10kHz but somewhere between 100-1000 Hz.WHY? And there is no problem with the windowing now I think. I use 10 periods of the signal (End simulation time 0.001) so the windowed signal includes at least two full amplitude periods of the signal.

That was basic my initial problem that made me search about the previous problem. Sorry if the questions are stupid for you but I havent had any DSP courses yet and I need to do some FFT for a project in a practical training. Any help would be greatly appreciated.
 

Hello kgl_13gr,

For your first question, as I don’t use Simulink I don’t know how the time step is chosen.
For your second question: the integrator has a higher pole at a very high frequency (65.8 MHz) compared with the sampling frequency of the sine wave (3.2 MHz). In practice this pole would not have any appreciable effect on your 10 KHz signal, but I don’t know how this is managed by Simulink; maybe this is related with the time step. It would be useful to see the output signal and the spectrum you obtain. Can you upload them?
Regards

Z
 

Simulink outputs two vectors: yout which is the output vector and tout which is the time vector. tout has a step of 1e-7.
I included you the transient response the spectrum that i get if I use as sampling requency in the spektrumfromdata function 3.2e6 (spectrum1) and the spectrum if i use 1e7 (spectrum 2). Syntax:
spektrumfromdata(yout,1e4,3.2e6,100,1)
The input signal is 0.5*sin(20000*pi*t) as before.

And one more remark. If I use a sample frequency of 1e9 in Simulink the output signal is undistorted. But I suppose thats reasonable since then the exponential caused by the pole has no effect.
Thank you in advance for your time! You are really helpful!

Kostas
 

Hi Kostas,

In the two spectra I see two superimposed plots. Why? Nevertheless, the spectrum is clear.

1) The distorsion is probably an artifact due to the high pole. This spourious signal should not be there. Why dont’you use an ideal integrator K/s?

2) Note that the two spectra are identical except for scale factors. The factor in frequency is the ratio of the sampling frequencies 1e7/3.2e6=3.125. The difference in vertical scale is 4.945 dB, that is 10*log10(1e7/3.2e6). I think that this is because you used two different sampling frequencies but the same call: spektrumfromdata(yout,1e4,3.2e6,100,1). The third parameter is the sampling frequency, and it should be 1e7 for the other case.
Anyway, there is still something wrong (the peak doesn’t appear at 10 KHz in neither case).

3) The spectrum should have two spectral lineas: a peak at DC (frequency=0) and another one at the frequency of the signal. Both are present. The other lines at higher frequencies correspond to the high-frequency spourious seen in the data: there are a fundamental frequency and its harmonics. You should try the ideal integrator as said in 1).

Let me know.
Regards,

Z
 

The algorithm removes initially the signal peak in order to calculate the in-band noise and then it adds it back. Thats why there are two spectra.
Regarding the ideal integrator, of course with an ideal integrator everything is fine. The spectrum is ideal! But I want to simulate THIS transfer fucntion! (This is the transfer function of an op-amp integrator that we use in a sigma delta modulator and I am trying to simulate the whole system). So I see no satisfactory explanation for the problem... So it stays as is.. Your opinion is that I should use 3.2e6 or 1e7 as a samlping frequency? For the ideal integrator it works with 3.2e6. The 1e7 gives just a frequency scaling as u said.

Kostas
 

Hi Kostas,

In order that the simulation be accurate, the sampling frequency has to be high enough in relation with the pole frequency. How much? It depends of the simulation method. Maybe the Simulink documentation gives the answer.

you said:
If I use a sample frequency of 1e9 in Simulink the output signal is undistorted. But I suppose thats reasonable since then the exponential caused by the pole has no effect.

True. Maybe you can get some insight trying other sampling frequencies and/or pole locations in order to see the effect of their ratio on the distortion.
Regards,

Z
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top