Saturday, July 16, 2016

M O D E L I N G    T H E    P E A K   D E T E C T O R

How do we account for the behavior of the peak detector the Z-transform? My idea is to inject a sinusoid at increasing amplitudes and plot the average output values against the input amplitudes.

The input frequency was 1 kHz. 
 

It's almost linear, the slop is a little less than 1.

What about its frequency response?

The input amplitude is 1 for all the sinusoids tested.

Great, I think I'm just going to assume a gain of 1, and flat frequency response.
However, it takes some time for an input sinusoid's amplitude to appear at the output. And for this, I think I will just use Z^(-D), where D is the number of samples you must wait for the sinusoid's amplitude to appear at the output, which depends on its frequency and sampling rate. [Edit] I actually just didn't bother with taking this into account. I'm just going to cross my fingers.

~M O D E L L I N G   T H E   S Y S T E M   I N   M A T L A B~

With the gain/behavior of the process in mind, lets turn our attention to the digital control system. Before we start writing code, we should use math and analyze the stability of the system. 

Using Matlab, I simulated the step response of the system that I showed earlier. It's steady state response was off by half! Which meant, that I needed an integrator.


In the following, I will show the loop responding to a unit step input. Each plot depicts a loop with a specific gain setting.
~K = 0.5~

~K = 1~

~K = 1.5~


THE IMPLEMENTATION, DIFFERENCES BETWEEN THEORETICAL BEHAVIOR AND ACTUAL SIMULATION

 I didn't expect the program to behave the way it did. But hey, that is engineering. I ended up having to iteratively tune the loop gain and peak detector time constant. Initially, with all of the values discussed above, with the loop gain equalling 0.5, 1.0, 1.5, made the loop unstable, this was due to the peak detector's delay. Above, I said I would deal with it when I got to the implementation. Well, the delay mattered in the end. I had to tune the loop gain down to 0.1, and make the peak detector's time constant smaller. (If I were to use a peak detector circuit as an analogue, I made lowered the resistor's resistance so that it can drain the capacitor faster. This way, the loop reacts faster to changes made to the input sinusoid's amplitude).

Time for pictures, and then maybe code.
Input sinusoid frequency = 1 kHz
Reference amplitude = 10








No comments:

Post a Comment