comedilib/demo/antialias.c

96 lines
2.3 KiB
C
Raw Permalink Normal View History

2000-06-02 21:37:40 +00:00
/*
2000-10-19 06:28:27 +00:00
* Antialiasing Analog Output Demo
* Part of Comedilib
*
* Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
*
* This file may be freely modified, distributed, and combined with
* other software, as long as proper attribution is given in the
* source code.
*/
/* Not functional */
/*
* Requirements: an analog output subdevice that is capable
* of ansynchronous output.
*
* Normally, the resolution of analog output channels is limited by
* the resolution of the D/A converter. However, if you limit the
* bandwith of the D/A converter by using a low-pass filter, you
* can trade some of the bandwidth for additional resolution. This
* is done by changing the output rapidly between two adjacent
* values: a signal of an alternating 0,1,0,1,0,1 sequence will
* look like 0.5 after an appropriate low-pass filter.
*
* The disadvantage, of course, is that you lose bandwidth. Worse,
* the simple technique demonstrated here will cause predictable
* noise in the stop band. More complicated techniques will allow
* you to tune the spectrum of the noise in the stop band.
2000-06-02 21:37:40 +00:00
*/
#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
2000-06-02 21:37:40 +00:00
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
2000-10-19 06:28:27 +00:00
#include "examples.h"
2000-06-02 21:37:40 +00:00
void ao_antialias(unsigned int data);
comedi_t *device;
2000-06-02 21:37:40 +00:00
int main(int argc, char *argv[])
{
lsampl_t data;
int ret;
struct parsed_options options;
2000-06-02 21:37:40 +00:00
init_parsed_options(&options);
parse_options(&options, argc, argv);
2000-06-02 21:37:40 +00:00
device = comedi_open(options.filename);
2000-06-02 21:37:40 +00:00
if(!device){
comedi_perror(options.filename);
2000-06-02 21:37:40 +00:00
exit(0);
}
data = options.value;
if(options.verbose){
2000-06-02 21:37:40 +00:00
printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
data, options.filename, options.subdevice, options.channel, options.range, options.aref);
2000-06-02 21:37:40 +00:00
}
ret = comedi_data_write(device, options.subdevice, options.channel, options.range, options.aref, data);
2000-06-02 21:37:40 +00:00
if(ret<0){
comedi_perror(options.filename);
2000-06-02 21:37:40 +00:00
exit(0);
}
printf("%d\n", data);
2000-06-02 21:37:40 +00:00
ao_antialias((1000<<16)+1000);
return 0;
}
void ao_antialias(unsigned int data)
{
unsigned int hibits=data>>16;
unsigned int lobits=data&0xffff;
int i;
unsigned int acc;
acc=0;
for(i=0;i<100;i++){
acc+=lobits;
printf("%d\n",hibits+(acc>>16));
acc&=0xffff;
}
}