discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] working example gnuradio TV receiver for NTSC and PAL


From: Martin Dvh
Subject: [Discuss-gnuradio] working example gnuradio TV receiver for NTSC and PAL (black and white)
Date: Thu, 06 Jan 2005 06:26:49 +0100
User-agent: Mozilla Thunderbird 0.9 (X11/20041124)

Hi all,
The discussion about the NTSC reception inspired me to write an example and it 
works.
http://www.olifantasia.com/projects/gnuradio/mdvh/examples/mdvh14_ntsc_demod.py

It get recognisable pictures in my setup.
http://www.olifantasia.com/projects/gnuradio/ntsc_out_raw_short1.jpg
http://www.olifantasia.com/projects/gnuradio/ntsc_out_raw_short.gray

I used the following commandline to get these pictures:
./mdvh14_ntsc_demod.py 11.0625 -20.0 -22 708.25
and used the following to show the results:
display -depth 16 -size 400x625  ntsc_out_raw_short.gray


My rf frontend has a much too wide bandwidth (no saw filter yet) but I do get a 
picture.
my setup: 38.9 Mhz IF
          50 Msps 8 bit ADC
The IF of 38.9 Mhz folds back to 11.0625 Mhz

You get black and white only.

Greetings,
Martin


#!/usr/bin/env python
#
# Copyright 2004 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#

from gnuradio import gr
from gnuradio import audio
#from gnuradio import ssrp
from gnuradio import mc4020
import sys


def build_graph (freq,rffreq,sfactor,black_level):
        #sampling_freq = 35468950
        sampling_freq = 50000000.0
        demod_rate=6e6
        video_rate=6e6

        flags=mc4020.BTTV_INPUT_1 |mc4020.BTTV_EXTEND_RAW_LINES 
|mc4020.BTTV_NOGAP
        # | mc4020.BTTV_DEC3 |mc4020.BTTV_DO_NOT_EMULATE_AC_COUPLING 
|mc4020.BTTV_OUTPUT_MULTIPLE
        if((flags & mc4020.BTTV_DEC3)==mc4020.BTTV_DEC3):
           sampling_freq=sampling_freq/3 #sampling_freq=11822983.0

        #src0 = ssrp.source_f(0)
        #src0 = gr.file_source(gr.sizeof_short, "input_signal.raw")
        #My own driver for my own hacked bttv card to have functionality 
similar to mc4020
        src0 = mc4020.source (sampling_freq,flags, "/dev/video0");

        cfir_decimation=int(sampling_freq/(8*demod_rate))*8 # = 368
        demod_rate=sampling_freq/cfir_decimation
        pixels_in_line_pal=demod_rate/(25*625)
        pixels_in_line_ntsc=demod_rate/(30*525)
        fg = gr.flow_graph ()



        if rffreq>0.0:
            actualtunerfreq=src0.set_RF_freq(rffreq)
            freq=freq+(rffreq - actualtunerfreq)

adj_in = gr.add_const_ss(0) #dummy adj_in does nothing (add 0 to the signal) but has a big effect on the minimal bandwith of the fir filter I can use
        # compute FIR filter taps
        channel_coeffs = \
                gr.firdes.low_pass (
                  1.0,                  # gain
                  sampling_freq,
                  1e6,                 # low pass cutoff
                  3e6,                 # width of transition band

                  gr.firdes.WIN_HAMMING )

        # input: short; output: complex
        chan_filter1 = \
                gr.freq_xlating_fir_filter_scf (
                  cfir_decimation,
                  channel_coeffs,
                  freq,
                  sampling_freq )

        am_demod = gr.complex_to_mag ()

        dc_restore = gr.add_const_ff(black_level)
        #dc_restore = gr.add_const_ss(black_level)

        scale = gr.multiply_const_ff (sfactor)

        #video_lp_coeffs = gr.firdes.low_pass (
        #        1, video_rate, 1e6, 6e6,
        #        gr.firdes.WIN_HAMMING )
        #
        #video_lp = gr.fir_filter_fff (int(video_rate/demod_rate), 
video_lp_coeffs )

        float_to_short=gr.float_to_short()

        dst = gr.file_sink (gr.sizeof_short, "ntsc_out_raw_short.gray")#raw 
file with short image data, not synchronized yet

        fg.connect ( src0, adj_in )
        fg.connect(adj_in,chan_filter1)
        fg.connect ( chan_filter1, am_demod )
        fg.connect(am_demod,scale)
        fg.connect(scale,dc_restore)
        fg.connect(dc_restore,float_to_short)
        fg.connect(float_to_short,dst)

        print "You can use the imagemagick display tool to show the resulting 
imagesequence"
        print "use the following line to show a PAL signal:"
        print "display -depth 16 -size " +str(int(pixels_in_line_pal))+ "x625  
gray:ntsc_out_raw_short.gray"
        print "use the following line to show a NTSC signal:"
        print "display -depth 16 -size " +str(int(pixels_in_line_ntsc))+ "x525  
gray:ntsc_out_raw_short.gray"

        return fg

def main (args):

        nargs = len (args)
        rffreq=0.0
        if nargs == 4:
                rffreq=float (args[3])* 1e6
        if ((nargs == 3) | (nargs==4)):
                freq=float (args[0])* 1e6
                sfactor=float (args[1])
                black_level=float(args[2])
        else:
                sys.stderr.write ('usage: ntsc_demod.py iffreq  scale 
black_levelcorrection [rffreq]\n')
                sys.stderr.write ('frequencies in Mhz\n')
sys.stderr.write ('Using an 8 bit ADC and an iffreq of 38.9 Mhz (folded back to 11.0625 when using 50 Mhz sampling_freq), a scale factor of -20.0 and a blacklevelcorrection of -22 gave me a reasonable picture for a PAL signal\n')
                sys.stderr.write ('For NTSC I think you need to use a positive 
scale factor\n')
                sys.exit (1)
        fg = build_graph(freq,rffreq,sfactor,black_level)
        fg.start()
        raw_input ('Press Enter to quit')
        fg.stop()

if __name__ == '__main__':
        main (sys.argv[1:])






reply via email to

[Prev in Thread] Current Thread [Next in Thread]