PID working with sine wave as reference in simulink - simulink

I have seen example of controlling output dc voltage of DC to DC buck converter using PID controller.
I want to implement DC to AC converter.
I tried using PID controller.
Since i am comparing output AC signal(continuously varying) with reference sinusoidal signal, PID controller is not providing expected output.
In case of DC to DC, both reference signal was constant.
In my case, it is continuously varying sine wave.
Can anyone suggest any way to get accurate DC to AC conversion?
P.S. Can PID controller work with continuously varying reference signal with high frequency(100Hz)?

If you want to have zero error for a sine wave reference you have two alternatives:
DQ0 Controller
You need to transform (using the dq0 transform also known as Park transform) your reference signal and controlled (measured) values to a rotating frame with the same frequency of your sine wave (in this case 100Hz).
When doing that, your reference signal and measured values will become constant values at 100 Hz and you can use a regular PID controller (actually you will need two - one for the d frame and other for the q frame).
Then you use the inverse transform of the PID controller output that will drive the duty cycle of your converter modulator.
Just notice that if your system is single-phase, there will be 2nd order harmonics in the result of the dq0 transform that have to be filtered out.
Resonant Controller
In the PID controller, the integral action is responsible for zero error constant reference tracking, because it is effectively a infinite gain at zero frequency (i.e. constant). In the transfer function using Laplace form the integral part corresponds to 1/s in the controller function.
To track sine waves, you need a controller in the form of (1/w²+s²), that will guarantee a infinite gain at the frequency of the reference sine wave, where w=2*pi*f.
In fact, we can proof mathematically that a DQ0 PID Controller is equivalent to the Resonant Controller.

Related

PID control action for AC reference of variable amplitude and frequency

i have seen example of controlling output dc voltage of DC to DC buck converter using PID controller. I want to implement DC to AC converter. I tried using PID controller. Since i am comparing output AC signal(continuously varying) with reference sinusoidal signal, PID controller is not providing expected output. In case of DC to DC, both reference signal was constant. In my case, it is continuously varying sine wave. Can anyone suggest any way to get accurate DC to AC conversion? i changed kp and ki parameters to get needed response. it is working well. but, when i change frequency of input reference signal, output signal amplitude drops and again i have to change PID parameters.
P.S. when i change frequency of input reference signal, again i have to change PID gain parameters. Can PID controller work with continuously varying reference signal(in terms of amplitude and frequency both) ?
Check the answer I gave to your other question:
PID working with sine wave as reference in simulink
If you need varying frequence for your reference, you can use a dq0 controller where the dq0 transform angle comes from a frequency reference (that you can change) passing through an integrator. Then set your d reference to the amplitude you wish.

wave phase adjustment between several signals

Can anyone help me on this?
I have a file with 8 wave signals that belong to the same wave gauge S1:
The idea is to adjust the phase of the signals so that they start with the same wave phase and height.
If I do this manually (as I did in the figure) I have to shift each signal in time until I find a proper overlap for the 8 signals.
Is there any function/routine available for this purpose?
Many thanks!
I would like to use Matlab. The plot was made in Tecplot.
The idea is to overlap the signals and then do the average wave of the 8 signals.
Here is the file:
https://www.dropbox.com/s/bc9imi5frhakgxz/time_phases1.csv
to align the signals you can use a zero crossing method, basically you find the zero crossings point of each signal then shift the signals until the zero crossing position is the same.
if you have a noisy signal, pass the signals through a low pass filter first,
and if you have a dc component pass the signals through a high pass filter.
for similar height you can factor the waveform peak or the rms-which will be more accurate,
example: divide factor = rms1/rms2 and then multiply factor by signal 2.

Matlab inverse fast fourier tansform for frequency-wavenumber field, do I need make conjugation and flip?

First I describe the physics, it is in a axisymmetric space, one sound source was placed at the original point, one sensor was placed on the axis under the source. Giving the source wave form, I try to get the sensor's waveform. all materiel parameter were known, for instance, sound speed, density.
I write the Matlab script to calculate it, by solving the sound propagation equation I can get
one function, say, A(w,k), w is frequency and k is wavenumber, this is so called frequency-wavenumber field. My matlab code like this,
discrete w and k, get a A array. first use FFT to k, get space and frequency information
then, FFT to w, get space and time information, that is the waveform at different point.
the fake code
for i_w=...
w=...
for i_k=...
k=...
M=A(w,k)
end
wave_space_freq=ifft(M)
end % here can specify the only point of the sensor
wave_space_freq=ifft(wave_space_freq)
My question is do I need to make conjugation and flip when I use IFFT,like ifft(M,0,fliplr(conj(M))) . because I saw some-others use them, but I don't understand why?
If you want a strictly real-valued result waveform (not complex with significant imaginary components), then the input to an IFFT has to be conjugate symmetric, such as:
ifft(dc_term,M,0,fliplr(conj(M))).

How to get coefficients for sine/cosine function from complex FFT in Matlab?

I'm working on a control system that measures the movement of a vibrating robot arm. Because there is some deadtime, I need to look into the future of the somewhat noisy signal.
My idea was to use the frequencies in the sampled signal and produce a fourier function that could be used for extrapolation.
My question: I already have the FFT of the signal vector (containing 60-100 values e.g.) and can see the main frequencies in the amplitude spectrum. Now I want to have a function f(t) which fits to the signal, removes some noise, and can be used to predict the near future of the signal. How do I calculate the coefficients for the sine/cosine functions out of the complex FFT data?
Thank you so much!
AFAIR FFT essentially produces output as a sum of sine functions with different frequencies. The importance of each frequency is the height of each peak. So what you really want to do here is filter out some frequencies (ie. high frequencies for the arm to move gently) and then come back to the time domain.
In matlab this should be like going through the vector of what you got from fft, setting some values to 0 (or doing something more complex to it) and then use ifft to come back to time domain and make the prediction based on what you get.
There's also one thing you should consider while doing this - Nyquist frequency - this means that the highest frequency that you get on your fft is half of the sampling frequency.
If you use an FFT for data that isn't periodic within the FFT aperture length, then you may need to use a window to reduce spurious frequencies due to "spectral leakage". Frequency estimation techniques to better estimate "between bin" frequency content may also be appropriate. The phase of each cosine sinusoid, relative to the edge of the window, is usually atan2(imag[i], real[i]). The frequency depends on the sample rate and bin number versus the length of the FFT.
You might also want to look into using a Kalman filter instead of an FFT.
Added: If your signal isn't exactly integer periodic in the FFT length, then you may want to do an fftshift before the FFT to move the resulting phase measurement reference point to the center of your data vector, instead of a possibly discontinuous circular edge.

Remove unknown DC Offset from a non-periodic discrete time signal

Is there some process that can determine / remove an unknown DC offset from a non-periodic discrete time signal?
The signal in in question has a sample rate of 25Hz and has harmonics of interest between 0.25 and 3 Hz.
I have tried using highpass filters mixed results, first I used a 10th order guassian with Fc = 0Hz, this did a good job of removing the offset but it severly attenuated the AC aswell although it did leave the signal shape intact, next I used a 168th order equilripple with a stopband at 0Hz and passband at 0.25Hz, the phase shift was too severe and the signal shape too distorted, the distortion could probably be reduced if the pass-band was brought down to 0.1Hz but this would just further increase the phase shift which I need to keep to the very minimum.
Before and after applying x - LPF(x), as suggested by Paul R
I recommend using a notch filter at DC and using filtfilt to make it zero phase.
a = [1 , -0.98]; b = [1,-1];
y = filtfilt(b,a,x);
The closer the second value of a gets to -1 the narrower your notch will be.
A DC offset means that some constant value was added to the signal (the name originates from adding a DC voltage to an analog AC signal). If the DC component is really constant (and not changing really slowly), then you don't have to design some high-order (and potentially unstable) high-pass filters - you can just subtract the average of your signal from the signal - which is, of course, a high-pass filter as well (averaging is a type of a low-pass, and '1 minus the average' is high-apss) --- but a very simple one.
If, on the other hand, you have a reason to believe that the DC component is not really a DC, but rather an AC with very low frequency, then you'd better average segments of your signal and not the signal as a whole, which is the same as using a low-pass filter with impulse response which is shorter then the length of the signal. In this case you have to make some assumptions about the "DC" component.
Rather than implementing a high pass filter directly (which can be rather tricky for very low frequencies - you end up with a large number of coefficients and various issues with stability and passband ripple etc), you might instead want to consider implementing a low pass filter which will give you an estimate of the DC offset value, and then subtract this filtered offset from your signal, i.e. rather than:
y = HPF(x)
do this:
y = x - LPF(x)
The low pass filter can probably just be quite a simple filter with a relatively small number of terms. The big advantage of this implementation is that your higher frequency components should not have any unwanted artefacts due to phase, ripple, etc, since all you are doing is subtracting an almost stationary DC value from the samples.
The only potential downside is that if the DC offset is large you may have quite a long initial settling time before the estimate of the DC offset is accurate (although this is also true of any other implementation such as a direct high pass filter of course). If you have any a priori knowledge of what the offset value is likely to be (e.g. if it doesn't change very much from run to run, and you know the value from the previous run) then you can use this to optimise the settling time, by initialising the LPF state variables to a suitable value rather than 0.
As others have said, to remove a DC offset, you can simply subtract the mean. Your signal does not need to be periodic, but it does need to be long enough to get a good estimate of the DC component.
If you still wish to go with a filtering approach, you can eliminate the severe distortion due to phase lag by using filtfilt. This function filters your timeseries once in the forwards direction and then once in the reverse direction, so that phase distortions cancel out.
You can design a symmetric FIR filter as the low-pass filter that estimates the DC and then subtract the output from your input signal. This filter has constant group-delay.