Plotting sampled data in Matlab

P

Pete Fraser

Guest
I'm simulating some filter hardware in Modelsim, and need
a way to display the output with a virtual anti-alias filter.

Is there a Matlab facility for this?
plot doesn't seem to have any good option for this.
I tried interp1, and it's better than nothing, but the
highest order interpolator seems to be 4-tap ('spline').
I could do a higher order filter myself, but feel that Matlab
probably has the ideal functionality already, if I only
knew how to invoke it.

Any thoughts.

Example:

Generate a DC to Nyquist sweep
t = 0:0.001:1;
y = chirp(t, 0, 1, 500);
plot(y)
Looks crunchy as hell.

ti = 0:0.0001:1;
yi = interp1(t, y, ti, 'spline');
plot(yi)
Now looks much better, but still quite aliased towards
Nyquist (as you'd expect from a 4-tap lpf).

Thanks

Pete
 
"Pete Fraser" <pfraser@covad.net> writes:

I'm simulating some filter hardware in Modelsim, and need
a way to display the output with a virtual anti-alias filter.

Is there a Matlab facility for this?
plot doesn't seem to have any good option for this.
I tried interp1, and it's better than nothing, but the
highest order interpolator seems to be 4-tap ('spline').
I could do a higher order filter myself, but feel that Matlab
probably has the ideal functionality already, if I only
knew how to invoke it.
interp
--
Randy Yates % "She tells me that she likes me very much,
Digital Signal Labs % but when I try to touch, she makes it
mailto://yates@ieee.org % all too clear."
http://www.digitalsignallabs.com % 'Yours Truly, 2095', *Time*, ELO
 
"Randy Yates" <yates@ieee.org> wrote in message
news:m3wrrbfqf5.fsf@ieee.org...
"Pete Fraser" <pfraser@covad.net> writes:
I'm simulating some filter hardware in Modelsim, and need
a way to display the output with a virtual anti-alias filter.
Is there a Matlab facility for this?

interp
Thanks. That seems better than interp1, but still seems weird.
I can't understand their description of alpha. The width of the
filter function remains the same for different values of alpha, but the
severity of windowing changes.The size of the filter kernel also
seems to be restricted to about 20 or under (still better than
four for interp1).

The worst thing about it is the DC gain seems to vary with phase.

interp(y, 10, 10, 1.0) gives me unity DC gain at the original
sample sites, but a gain of 0.968 at a point in the middle.
Am I missing something, or is Matlab just being dumb?

Thanks

Pete
 
"Randy Yates" <yates@ieee.org> wrote in message
news:m3wrrbfqf5.fsf@ieee.org...
"Pete Fraser" <pfraser@covad.net> writes:
I'm simulating some filter hardware in Modelsim, and need
a way to display the output with a virtual anti-alias filter.
Is there a Matlab facility for this?

interp

Thanks. That seems better than interp1, but still seems weird.
I can't understand their description of alpha. The width of the
filter function remains the same for different values of alpha, but the
severity of windowing changes.The size of the filter kernel also
seems to be restricted to about 20 or under (still better than
four for interp1).

The worst thing about it is the DC gain seems to vary with phase.

interp(y, 10, 10, 1.0) gives me unity DC gain at the original
sample sites, but a gain of 0.968 at a point in the middle.

Am I missing something, or is Matlab just being dumb?

Thanks

Pete
Try "resample" or "upfirdn". Resample calls upfirdn using internal filter
upfirdn allows using your own filter.

Kadhiem

---------------------------------------
Posted through http://www.FPGARelated.com
 
Pete Fraser wrote:
I'm simulating some filter hardware in Modelsim, and need
a way to display the output with a virtual anti-alias filter.

Is there a Matlab facility for this?
plot doesn't seem to have any good option for this.
I tried interp1, and it's better than nothing, but the
highest order interpolator seems to be 4-tap ('spline').
I could do a higher order filter myself, but feel that Matlab
probably has the ideal functionality already, if I only
knew how to invoke it.

Any thoughts.

Example:

Generate a DC to Nyquist sweep
t = 0:0.001:1;
y = chirp(t, 0, 1, 500);
plot(y)
Looks crunchy as hell.

ti = 0:0.0001:1;
yi = interp1(t, y, ti, 'spline');
plot(yi)
Now looks much better, but still quite aliased towards
Nyquist (as you'd expect from a 4-tap lpf).

Thanks

Pete
Pete,

I'm not clear on all that but if you change to this:
t = 0:0.001:1;
y = chirp(t, 0, 1, 50);
plot(y)

Then the plot looks fine if it meets your definition of "fine".
The only problem I see is the the higher frequencies are undersampled
(in a "plotting" sense) - and you did mention aliasing so I expect
that's what you meant.

Just to check:
The sample rate appears to be 1000Hz and the interval is 1msec of course.
The highest frequency is 500Hz so there would be 2 samples per cycle at
the highest frequency which meets the Nyquist criterion except at 500Hz.
But, for practical purposes, it doesn't reach 500Hz anyway.
That would all be OK except that the bandwidth is higher than 500Hz due
to the frequency modulation. So, I'm not entirely sure just what
"Nyquist" is here. One could figure it out easily enough but I'm lazy
so I did this:

fy=fft(y)
mfy=abs(fy)
plot(1:1001,mfy)

The result is pretty revealing and suggests that the waveform is quite
undersampled as there are very high values around fs/2.


x axis from 900 to 1000 you can see the "intermodulation" effects of
the sampling - which is what makes the original plot look weird.

I'm not sure that helps because I've not addressed the lpf questions.
Were you intending to LPF and then plot? You're still going to get the
intermodulation effects up around 500Hz. I tried it with a simple [1 1]
filter with a zero at 500Hz and it was still evident.

I hope this helps some....

Fred
 
"Fred Marshall" <fmarshall_xremove_the_xs@xacm.org> wrote in message
news:queeo.81896$PY3.39434@en-nntp-05.dc1.easynews.com...

I'm not clear on all that but if you change to this:
t = 0:0.001:1;
y = chirp(t, 0, 1, 50);
plot(y)

Then the plot looks fine if it meets your definition of "fine".
It does.

The only problem I see is the the higher frequencies are undersampled (in
a "plotting" sense) - and you did mention aliasing so I expect that's
what you meant.
Correct. I can't just look at a waveform and tell
if my simulated filter hardware is behaving correctly.

Just to check:
The sample rate appears to be 1000Hz and the interval is 1msec of course.
The highest frequency is 500Hz so there would be 2 samples per cycle at
the highest frequency which meets the Nyquist criterion except at 500Hz.
Correct (although I don't care about units). It's just sample inputs
to Modelsim.

But, for practical purposes, it doesn't reach 500Hz anyway.
Close enough.

That would all be OK except that the bandwidth is higher than 500Hz due to
the frequency modulation. So, I'm not entirely sure just what "Nyquist"
is here. One could figure it out easily enough but I'm lazy so I did
this:

fy=fft(y)
mfy=abs(fy)
plot(1:1001,mfy)

The result is pretty revealing and suggests that the waveform is quite
undersampled as there are very high values around fs/2.


x axis from 900 to 1000 you can see the "intermodulation" effects of the
sampling - which is what makes the original plot look weird.
Could be. I was being sloppy and ignoring the FM aspect.

I'm not sure that helps because I've not addressed the lpf questions. Were
you intending to LPF and then plot? You're still going to get the
intermodulation effects up around 500Hz. I tried it with a simple [1 1]
filter with a zero at 500Hz and it was still evident.
I was intending to do a filtered upconversion, then plot.
I first hoped that plot would have an option for this, but no luck.

I then tried interp1, which does some of what I was looking for,
but is restricted to a 4-tap filter ('spline' method), and so is still
visually aliased.

I then tried interp, which allows higher order filters, but has some
very weird behaviour. The various polyphase coefficient sets have DC
gains that are not unity, so if you up-convert DC you get a weird scallop
effect. Either I or Mathworks is suffering from a serious absence of grasp.

Then I discovered resample and upfirdn (thanks Kadhiem).
They seem to do pretty much what I was hoping for.

I hope this helps some....
Thanks Fred.

Pete
 
"kadhiem_ayob" <kadhiem_ayob@n_o_s_p_a_m.n_o_s_p_a_m.yahoo.co.uk> wrote in
message news:sv2dndPiufvWfuXRnZ2dnUVZ_jidnZ2d@giganews.com...

Try "resample" or "upfirdn". Resample calls upfirdn using internal filter.
upfirdn allows using your own filter.
Thanks. That's pretty much what I was hoping for.

Pete
 
"Manny" <mloulah@hotmail.com> wrote in message
news:7b13d9e3-7c30-4ca1-ab02-5d994c77b24c@i13g2000yqe.googlegroups.com...


- as far as I remember, you can define an 'analog' signal to plot in
modelsim and it comes with an interpolation option
That's where this whole thing started.
The Modelsim interpolation option is not good, and you can't
really use it to evaluate analog waveforms that are above fs/4.

Matlab's 'resample' followed by 'plot' does a much better job.

Thanks

Pete
 
On Aug 28, 1:40 am, "Pete Fraser" <pfra...@covad.net> wrote:
I'm simulating some filter hardware in Modelsim, and need
a way to display the output with a virtual anti-alias filter.

Is there a Matlab facility for this?
plot doesn't seem to have any good option for this.
I tried interp1, and it's better than nothing, but the
highest order interpolator seems to be 4-tap ('spline').
I could do a higher order filter myself, but feel that Matlab
probably has the ideal functionality already, if I only
knew how to invoke it.

Any thoughts.
Last time I needed to do this, I remember having had modelsim doing
the whole thing there. I used to do this:
- define an output real signal in VHDL
- write a conversion function from two's complement to floating point
in VHDL, this would give you a real signal in modelsim
- as far as I remember, you can define an 'analog' signal to plot in
modelsim and it comes with an interpolation option

Hope this helps.

-Momo
 
On Aug 29, 3:28 am, "Pete Fraser" <pfra...@covad.net> wrote:
That's where this whole thing started.
The Modelsim interpolation option is not good, and you can't
really use it to evaluate analog waveforms that are above fs/4.
Never needed more than this as my signals are usually well
oversampled.

Alternatively, you can write your own custom interpolation function in
VHDL. Since it's purely for simulation, it's as easy as writing in any
procedural language.

Matlab's 'resample' followed by 'plot' does a much better job.
Again not sure, but if your signal is bandpass, resample may be
useless here, or not?

-Momo
 
On Aug 29, 6:06 am, Manny <mlou...@hotmail.com> wrote:
Again not sure, but if your signal is bandpass, resample may be
useless here, or not?
That is, bandpass and *broadband*.

-Momo
 
resample works irrespective of signal bandwidth(0~.5Fs).it's only
limitation is that it does not support very large vectors.
Incidentally I also use it for fractional delay modelling e.g. for ADC clk
edge variation; upsample by 100 for example then manually downsample from a
chosen sample:


y1 = resample(x,100,1);
y2 = y1(26:100:end); % 0.26 fractional delay

Kadhiem

---------------------------------------
Posted through http://www.FPGARelated.com
 

Welcome to EDABoard.com

Sponsor

Back
Top