PDA

Click to See Complete Forum and Search --> : [RESOLVED] plotting a wav file


jumpjack
Jun 11th, 2008, 06:42 AM
I have a simple uncompressed (PCM 32 bit 48000 Hz) WAV file and I want to plot its waveform.
The waveform actually represents a digital signal a few ms long, so I just need to know when the waveform is high and when it is low.
I parse the DATA chunk word by word and I just plot values on the screen: it works pretty well... but in several points of the resulting graph I see "peaks", which, when compared to the WAV file, correspond to values over 65000. But the file displayed in Audacity shows no peeks, just kind of a square wave (zeroes and ones).

What am I doing wrong?

jumpjack
Jun 12th, 2008, 03:50 AM
By the way, this is the WAV signal I am analyzing (raw format):
http://www.planetmobile.it/jumpjack/sample.raw

My source:

$typecheck on
$INCLUDE <Rapidq2.inc>

declare sub move(x as integer,y as integer)
declare sub start(bt as integer,x as integer,y as integer)


dim TypeDraw as integer
TypeDraw=1
dim flag as integer
dim orx as integer
dim ory as integer
dim ox as integer
dim oy as integer
dim pencolor as long
dim backcolor as long
dim Dial as QColorDialog

CREATE Form AS QFORM
Width = 1200
Height=503
Center

CREATE ScrollBox1 AS QSCROLLBOX
Align=alClient
color=&hffffff
CREATE image AS QCanvasEx
Align=alClient
OnMouseDown=start
END CREATE
END CREATE
END CREATE

Form.ShowModal




sub Start(bt as integer,x as integer,y as integer)
dim i as long
dim in as qfilestream
dim data as word
dim letti as long
dim factor as long
dim skip as integer
dim toskip as integer
dim prev as long
dim highplot as long
dim lowplot as long
dim high as long

highplot = 100
lowplot = 0
high= 10000
factor = 1000
toskip = 2
skip = 0
in.open("F:\documenti\testo\geocities\p800sito\altervista\LedRem\sample.raw",fmOpenRead)
letti = 0
while in.eof=0
letti = letti+1
in.read(data)
skip = skip + 1
if skip<toskip then ' Salta alcuni dati per fare piu' stretta l'immagine
letti= letti-1
else
' if data>high then
' image.line(letti,0,letti,highplot,PenColor)
' else
' image.line(letti,0,letti,lowplot,PenColor)
' end if
image.line(letti-1,200,letti,200-data/factor,PenColor)
skip = 0
end if
print letti, " ", hex$(data), " ", int(data/factor)
wend
end sub

The original signal looks like this (it's not exactly this, I don't have its plotting here right now...).
http://www.planetmobile.it/jumpjack/LedRem/remote-justled.jpg

The more I get toward the end of the file, the more "spurious" values appear, which results in vertical stright lines in the graph!
(I'll post a screenshot later)

jumpjack
Jun 12th, 2008, 04:25 AM
well, I rewrote from scratch the program in Excel VBA and it works fine, so I guess it's some sort of strange bug in RapidQ basic (or in my understanding of how RapidQ works...)

jumpjack
Jun 16th, 2008, 03:29 AM
I eventually found out a bug.. in my head! ;-)
I was considering RAW data as unsigned....