Discretization and FFT in Simulink

5 Ansichten (letzte 30 Tage)
Mark
Mark am 25 Jul. 2019
Kommentiert: Mark am 5 Aug. 2019
Hello,
I'm trying to do a discretization and FFT on a continous signal in Simulink. Result seems to be pretty good for a simple example (sinus) but I would like to hear the opinion of some experts if my way is right.
What I'm trying to do is the following:
I have a continious signal and want do discret it with a sample rate of 5kHz.
To make it easier for the example I will post here, I use a sinus with a frequency of 100 Hz and an amplitude of 5. I know that in this case the signal itself is discret. I entered as sample time of 10 kHZ to simulate a "continous" signal (see picture).
For the discretization I used:
Quantizer block (quantizer interval: 1/5000)
Zero Order Hold block (sample time 1/5000)
buffer (output buffer size per channel 5000
For the FFT I used:
Magnitude FFT Block (checked divide output by FFT lenght in the submodel)
two matlab functions (see pictures)
and an array plot.
All parameters are in the attachment.
Could someone check if the FFT and especially the discretization was done correctly?
Thanks in advance!

Antworten (1)

Jyothis Gireesh
Jyothis Gireesh am 5 Aug. 2019
Bearbeitet: Jyothis Gireesh am 5 Aug. 2019
Here are a few suggestions about discretizing a continuous signal and taking the FFT. The following pointers may be of help to you.
  • A continuous signal can be generated in Simulink only by setting the sample time equal to 0.
  • And the quantizer block performs discretization in amplitude and not on the time axis. Performing quantization prior to taking the FFT can also lead to information loss.
  • To discretize a continous signal you may use the zero order hold block with the appropriate sample time.
  • In order to discretize the sine wave you may right click on the block and set the sample time appropriately. In the above case it can be set to 1/5000.
You may also improve the second matlab function matlabfunction2 using the following code snippet.
function y = fcn(u)
length = size(u,1);
p1 = 2*u(ceil(length/2):end,:);
p1(1,1) = p1(1,1)/2;
y = p1;
  1 Kommentar
Mark
Mark am 5 Aug. 2019
Thank you so much for your reply.
I have some additional questions regarding the matlabfunction2 code.
First, from my point of view, the new code is basically the same, but better expressed in less lines and the half length is rounded, right? One main thing I noticed that the shifting may not be right because the frequency at 0 Hz is being used in the vector? As a result the FFT is shiftet +1 Hz. Is the code from you still correct? In my code I have fixed this (see picture). Is this also applying for your code?
Do I need the ceil function?
Second, I thought about using a low pass filter to avoid an alias effect. I used the block 'Varying Lowpass Filter' before the zero order hold. Is this method valid?
Thanks for your help

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by