+ Post New Thread
Results 1 to 7 of 7

13th November 2016, 19:09 #1
 Join Date
 Nov 2005
 Location
 Switzerland
 Posts
 68
 Helped
 0 / 0
 Points
 2,320
 Level
 11
How to simulate in Simulink the FFT of "SampleandHold"
Hello,
I've met difficulties while trying to simulate sinusoidal waveform passed through "SampleandHold" module.
On the snapshot below my model. When I run simulation, the error occurs:
Error in 'Sample_and_Hold_test/Buffer': All sample times must be discrete. No continuous or constant sample times are allowed
"SampleandHold" block outputs continuous signal, but "Buffer" requires discrete one.
How to proceed ?
Thanks in advance.
P.S. Model is in attachment.

13th November 2016, 19:09

13th November 2016, 20:06 #2
 Join Date
 Nov 2006
 Location
 Portugal
 Posts
 7,066
 Helped
 864 / 864
 Points
 23,288
 Level
 37
 Blog Entries
 5
Re: How to simulate in Simulink the FFT of "SampleandHold"
I had a similar issue some time ago, and I solved by replacing all the blocks before S/H ( including itself ) by a discrete input, more precisely an array of discrete values. The reason behind this error seems like the DSP blocks are generating discrete outputs, but in the continuous domain.

Part of the world that you live in, You are the part that you're giving ( Renaissance )

13th November 2016, 20:06

13th November 2016, 20:41 #3
 Join Date
 Nov 2005
 Location
 Switzerland
 Posts
 68
 Helped
 0 / 0
 Points
 2,320
 Level
 11
Re: How to simulate in Simulink the FFT of "SampleandHold"
Can you, please, attach some screenshot ... frankly speaking I didn't properly understood what you mean.
Thanks.

13th November 2016, 20:41

13th November 2016, 21:42 #4
 Join Date
 Nov 2006
 Location
 Portugal
 Posts
 7,066
 Helped
 864 / 864
 Points
 23,288
 Level
 37
 Blog Entries
 5
Re: How to simulate in Simulink the FFT of "SampleandHold"
There should be better alternatives to fix that issue, but the only one I see based on my previous experiments, could be by replacing all the stuffs before S/H blocks by an 1D vector, in you case with the length of 4096 values. Don't know exactly what function could do that, but discretizer is the first one which come to mind.

Part of the world that you live in, You are the part that you're giving ( Renaissance )

14th November 2016, 12:53 #5
 Join Date
 Nov 2005
 Location
 Switzerland
 Posts
 68
 Helped
 0 / 0
 Points
 2,320
 Level
 11
Re: How to simulate in Simulink the FFT of "SampleandHold"
Yes, it would be a solution ... i.e. transform the train of continuous values into 1D vector in order to apply it to FFT, but unfortunately I didn't find any Simulink block capable to do it.
I turned my attention to "ZeroOrder Hold" from Simulink "Discrete" library and also modified sinusoidal waveform output type from Discrete to Continuous.
This way "ZeroOrder Hold" can be considered as "sampler".
Indeed it is the case  after "ZeroOrder Hold" I can place "Buffer" and simulation runs, i.e. no error is generated.
Then I returned to my original task  simulate "SampleandHold" behavior and its impact on incoming signal.
According to textbook (please see screenshot below), the "SampleandHold" acts as filter having a characteristic sinc(x).
So if I apply, let say, 3 sinusoidal waveforms to such "SampleandHold", it should filter out frequencies that close to Nyquist frequency.
But in my setup it doesn't ... all 3 sinusoidal waveforms manifest the same levels at the output of "SampleandHold".
In correct simulation output of Sin_f3 < output of Sin_f2 < output of Sin_f1.
So, the conclusion is: "ZeroOrder Hold" cant transform continuous signal into discrete , but can't "emulate" real "SampleandHold"
So, the problem apparently quite simple ... persists.

14th November 2016, 12:53

14th November 2016, 13:20 #6
 Join Date
 Nov 2006
 Location
 Portugal
 Posts
 7,066
 Helped
 864 / 864
 Points
 23,288
 Level
 37
 Blog Entries
 5
Re: How to simulate in Simulink the FFT of "SampleandHold"
Perhaps the Lookup Tables Block Library could make the job. There is already a 1D Sin generator function there. According to the initial picture, this is exactly what you want to sample.

Part of the world that you live in, You are the part that you're giving ( Renaissance )

14th November 2016, 14:37 #7
 Join Date
 Nov 2005
 Location
 Switzerland
 Posts
 68
 Helped
 0 / 0
 Points
 2,320
 Level
 11
Re: How to simulate in Simulink the FFT of "SampleandHold"
I've just tried your suggestion (at least as I understood it).
Unfortunately doesn't work ... well it works, but as in previous case "SampleandHold" block doesn't manifest any filtering action ... i.e. the power level upon FFT doesn't change when input frequency changes.
Here below the results of 2 simulations:
 f1 = 233Hz
 f1 = 27133Hz
As you can see both have the same level, whereas the FFT output of 27133Hz must be much lower than 233Hz.
Fig.1 Model
Fig.2 Simulation with f1 = 233Hz
Fig.3 Simulation with f1 = 27133Hz
+ Post New Thread
Please login