How to plot group delay and phase delay for a continuous time transfer function in MATLAB? - matlab

I have created a continuous time transfer function (s-domain) with the "tf" command. Now I can use the command "bodeplot" to plot magnitude and phase characteristics.
Now I would like to plot group delay and phase delay as well (both as a function of frequency). I stumbled upon the commands "grpdelay" and "phasedelay" but they seem to work with discrete time filters only. What are the continuous time equivalents?
I have searched all over the internet with no luck so far :-(

I dont think there is a straight forward function to do this. You're probably better off by extracting the phase information for many points and then finding the derivative (multiplied by -1),

Related

Lowpass filter Phase Error

As the graph shows, I have slightly over 0.01 milliseconds delay introduced by transfer function for a simple low-pass ASK filter at the demodulation part.
I need to get rid of this delay by any means.
Scope Results
I tried to increase the frequency at the denominator coefficient of the transfer function, but still with the same delay.
In the last attempts, I tried to create a subsystem that outputs binary 1 at interval or 0.5 milliseconds if it is bigger than 0.5e-6 as threshold, and hold the value until the coming 1.5 millisecond where it should outputs 0 if it is less than 0.05e-6 and so on. I tried to follow this here, but it didn't work on my scenario. I also tried this here, but my attempts failed.
Here is an overall implementation for the demodulation part using simulink.
And the following is the transfer function for a simple low-pass ASK filter:
Help here is much appreciated.
It is impossible for a linear filter to filter a signal (for any finite bandwidth above DC) without a delay. It takes some time (usually related to the period of the center frequency of a bandpass filter), for the filter to gather enough information from the signal to differentiate between a waveform to pass and a waveform to attenuate.
You might be able to pass a sharper rise time or fall time by using a matched filter with the expected transient(s) as the template(s), but that would have an even greater delay.
Usually this delay is accounted for by using a matching delay in other parts of the system to synchronize timing as needed.

Determine intervals from kernel density estimation

I have a 1-dimensional data which is (t) where users spend time to complete a task. I applied kernel density estimation from http://www.mathworks.com/matlabcentral/fileexchange/14034-kernel-density-estimator to remove the outliers who spent unreasonable time. I used the following lines:
[bandwidth,density,xmesh]=kde(dur1);
plot(xmesh,density);
After applying KDE, I have a problem of defining the local minima to split the data. The following link shows how the curve looks like:
http://s23.postimg.org/6aa1748jf/kde.jpg
I expect to see three clusters, where the middle one contains the reasonable spent time. However, the curve I have got has only one peak.
I am wondering if the steps I am following are correct?

Get the envelope of a signal in Matlab

I don't know how to compute the envelope of a signal. I've already seen the mathwork solutions firstSolution secondSolution but they does not work in the signal I'm working with.
This signal provides from a pressure sensor and it's sampled at a frequency of 1kHz and it has 100000 samples.
I've read that with the hilbert transform I could get the envelope by doing abs(hilbert(data)) being data the values of the signal2.txt but it has not work. I've also tried with taking the absolute value of the analytic signal but it has not work either.
The solution I've tried is to find the peaks and put them together linearly but it does not work properly because I want a continuous and derivable function as result so as I need to derivate it.
I hope you knew the solution to my problem. :)

Notch or Bandstop filter and preparing data for it

I am new to matlab and signal processing methods, but i am trying to use its filter properties over a set of data I have. I have a collection of amplitude values obtained at different timestamps. When this is plotted, I get a waveform with several peaks that I can identify. I then perform calculations to derive the time between each consecutive peak and I want to eliminate the rates that are around the range of 48-52peaks per second.
What would be the correct way to go about processing this data step by step? Would a bandstop or notch filter be better if I want to eliminate those frequencies and not attenuate it simply? I am completely lost in the parameters required to feed into the filters for this. Please help...
periodogram is OK, but I would suggest using pwelch instead. It makes a more reasonable PSD estimate and the default parameters are well thought out (Hann windows, 50% overlap of segments, etc.)
If what you want is to remove signals in a wide band (e.g. 48-52 Hz) equally, rather than a single and unchanging frequency, than a bandstop filter is ideal. For example:
fs = 2048;
y = rand(fs*8, 1);
[b,a] = ellip(4, 2, 40, [46 54]/(fs/2));
yy = filter(b,a,y);
This will use a 4th order elliptic bandstop filter to filter the random data variable 'y'. filtfilt.m is also a nice function; it applies the filter forwards and backwards so you get twice the filter action and none of the phase lag or dispersion.
I am currently doing something similar to what you are doing.
I am processing a lot of signals from the Inertial Measurement Unit and motor drives. They all are asynchronously obtained, i.e. they all have very different timestamp and also very different acquisition frequency.
First thing I did was to interpolate all signals data in order to have all signals with same timestamp. You can use the matlab function interp to do this.
After this, you will have all signals with same sample frequency and also timestamp, which will be good in further analysis.
Ok, another thing you can do to analyse the frequency of the peaks is to perform the fourier transform. For beginners i advice the use of periodogram function and not the fft function.
Imagine you signal is x and your sample frequency (after interpolation) is Fs.
You can now use the function periodogram available in matlab like this:
[P,f] = periodogram(x,[],[length(t)],Fs);
This will give the power vs frequency of your signal. After that you will be able to plot and take a look at the frequencies of your signal. In other words, you be able to see the frequencies of the signals that make your acquired signal.
Plot the data this way:
plot(f,P); or semilogy(f,P);
The second is the same thing as the first, but with a logarithmic scale.
After this analysis you can use the Filter Desing and Analysis Tool to design you filter. Just type fdatool in matlab and it will open the design window. Choose the filter type, the cut and pass frequencies and click in design. This tool is very intuitive.
After designing you can export the filter to workspace.
Finally you can use the filter you designed in your signal to see if its what you wanted.
Use the functions filter os filtfilt for this.
Search in the web of the matlab help for the functions I wrote to get more details.
There are a lot of examples availables too.
I hope I could help you.
Good luck.

Instantaneous Phase in Matlab

I have a signal in matlab and what to calculate the instantaneous phase for a specific band. I want to filter the signal into this range (using a bandpass filter) and then get the instantaneous phase. I know that there are problems using some filters with non-linear phase responses, is there any way to get around this? I have found some information online about back filtering the signal but it's still a little unclear. I'd like to avoid using wavelets (they're probably overkill here). Thanks.
Unless you resort to noncasual techniques (like the filtfilt suggested in the comment by nibot), you will always have some phase distortion. Linear phase FIRs with a delay D will add a phase of 2*pi*f*D, while nonlinear phase IIRs will add phase that is not linearly dependent on f.
In both cases, it is easy to compute the phase distortion (for example, use freqz(num, den) for IIRs) and account for that distortion when interpreting the resulting measurement. Of course, you'll have meaningless results when the phase changes significantly over the frequency range you are interested in - but that's a different issue.