Sign in

username:

password:



Not a member?

Search Comp.Arch.FPGA



Search tips

fpga by Keywords

Altera | ASIC | CPLD | Cyclone | DCM | DDR | DSP | Ethernet | ISE | JTAG | Linux | LVDS | Microblaze | ML310 | Modelsim | NIOS | OPB | PCI | Quartus | RocketIO | SDRAM | Spartan | Spartan3 | SRAM | Stratix | Verilog | VHDL | Virtex | Virtex-4 | Virtex-II | Xilinx | XST

Ads

See Also

DSPEmbedded SystemsElectronics

Comp.Arch.FPGA | Plotting sampled data in Matlab

There are 12 messages in this thread.

You are currently looking at messages 0 to 10.

Plotting sampled data in Matlab - Pete Fraser - 2010-08-27 20:40:00

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 


______________________________
Join the blogging team on FPGARelated.com and earn rewards! Details Here.



Re: Plotting sampled data in Matlab - Randy Yates - 2010-08-27 21:59:00

"Pete Fraser" <p...@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://y...@ieee.org          %                            all too clear."
http://www.digitalsignallabs.com %        'Yours Truly, 2095', *Time*, ELO  
______________________________
Join the blogging team on FPGARelated.com and earn rewards! Details Here.

Re: Plotting sampled data in Matlab - Pete Fraser - 2010-08-27 23:45:00

"Randy Yates" <y...@ieee.org>
wrote in message 
news:m...@ieee.org...
> "Pete Fraser" <p...@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


______________________________
Join the blogging team on FPGARelated.com and earn rewards! Details Here.

Re: Plotting sampled data in Matlab - kadhiem_ayob - 2010-08-28 06:22:00

>"Randy Yates"
<y...@ieee.org> wrote in message 
>news:m...@ieee.org...
>> "Pete Fraser" <p...@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

Re: Plotting sampled data in Matlab - Fred Marshall - 2010-08-28 16:39:00

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
______________________________
Join the blogging team on FPGARelated.com and earn rewards! Details Here.

Re: Plotting sampled data in Matlab - Manny - 2010-08-28 21:39:00

On Aug 28, 1:40=A0am, "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

Re: Plotting sampled data in Matlab - Pete Fraser - 2010-08-28 22:20:00

"Fred Marshall"
<f...@xacm.org> wrote in message 
news:queeo.81896$P...@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 


______________________________
Join the blogging team on FPGARelated.com and earn rewards! Details Here.

Re: Plotting sampled data in Matlab - Pete Fraser - 2010-08-28 22:22:00

"kadhiem_ayob"
<kadhiem_ayob@n_o_s_p_a_m.n_o_s_p_a_m.yahoo.co.uk> wrote in 
message news:s...@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




Re: Plotting sampled data in Matlab - Pete Fraser - 2010-08-28 22:28:00

"Manny" <m...@hotmail.com>
wrote in message 
news:7...@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 



Re: Plotting sampled data in Matlab - Manny - 2010-08-29 01:06:00

On Aug 29, 3:28=A0am, "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



| 1 | 2 | next