Python echo

This adds a echo to a wav file. The file also gets louder, because the result is not normalized. (sample + 0.8*Othersample v.s. sample+0.8*Othersample/1.8). This is my first real experiment with DSP.  Maybe More Later(tm). Comments are welcome. (no registration necessary / pre-moderated by me)

Echo. Usage: python_Echo InpuFile.wav OutputFile.wav Delay_in_Seconds
0.15 seconds gives a believable echo. Pass a file multiple times trough it or modify source for multiple echo's

Only works with 1ch WAV files. To be improved Later(tm).
import sys
import numpy as np
import wave
import struct

if len(sys.argv) != 4:
        print "Usage: python_Echo InpuFile.wav OutputFile.wav Delay_in_Seconds"
delay = float(sys.argv[3])

if delay > 2:
        print "weirdly long delay. Try < 2"
framerate = w.getframerate()
frames = w.getnframes()
channels = w.getnchannels()
width = w.getsampwidth()
print("sampling rate:", framerate, "Hz, length:", frames, "samples,",
"channels:", channels, "sample width:", width, "bytes")
data = w.readframes(frames)
sig = np.frombuffer(data, dtype='<i2').reshape(-1, channels)

echo_output =[2], 'w')
echo_output.setparams((channels, width, framerate, 0, 'NONE', 'not compressed')) #output file matches input file params

values = []

for i in range(0, frames):
        if i > delay*framerate:
                value = sig[i] + 0.8*sig[i-delay*framerate] #add echo
                value = sig[i]
        packed_value = struct.pack('h', value) #this failes for 2 channel files.

value_str = ''.join(values)

outsig = np.frombuffer(value_str, dtype='<i2').reshape(-1, channels)

print "done"

Used sources:

And something about DSP from a dead-tree book.

Continued “data transmission whistle” experiment, more successful this time

Okay, what’s this about?
Oona Räisänen challenged her readers to construct a whistle that could transmit data using FSK.

And if one reads her challenge carefully it says “whistle”. Not “pea whistle“. Now THAT simplifies things a lot!

A whistle design like this can be modified by inserting a magnet and wrapping a coil around it to act as an electromagnet. That way the length of the channel can be varied by moving the magnet, and with it the wavelength of the sound.

Then, by controlling the electromagnet with the bitstream – to – be – transmitted, one can transmit data by whistling.

So, I built such a whistle (Dutch). With a simple arduino sketch and a mosfet it is indeed possible to transmit data by whistling.

Datatransmission by whistle

It sounds like this. (that ticking/clicking noise when I’m not whistling is the magnet moving.)

I do not have the skill level that Oona has when it comes to decoding mystery signals, so I can’t decode the data out of that. I just hope the signal can still be decoded. But it is supposed to say “HELLO”, with leading 0xAA 0xA7. Bit time is 75ms, that is: for every “1” in the bitstream the electromagnet is powered for 75ms, and for every 0 it is left unpowered.

And because it is close to the new year, a bonus audio file for those among us that like to decode mystery signals: clicky.:)

(Failed) Pea whistle experiment

Well, not really failed, since every result is a result. I just found a way how this does not work. Two in fact.

Okay, what’s this about?
Oona Räisänen challenged her readers to construct a whistle that could transmit data using FSK.

So, I thought about replacing the pea in a pea whistle with a magnet, and then using an electromagnet outside the whistle to slow down (or stop) the pea’s movement during whistling. Since the pea modulates the whistles sound by blocking the “air exit” of the whistle when moving past it, slowing the pea down for a couple of revolutions should frequency modulate the whistle.

pea whistles Lees verder (Failed) Pea whistle experiment

ATX computer power supply current limit.

(This post is also available in Dutch)

For another project I’m tinkering with an old computer power supply. While I’m at it, why not see if I can build some crude current limiting. It does not need to regulate the current neatly, as long as it is short circuit proof.

A LED on the 12V output of a computer PSU would normally be blown to bits. Such a power supply can furnish ridiculously large amounts of current, while a LED only needs 20mA and as a diode won’t self-limit this. The PSU in the picture is an old one, the 12V line is orange instead of yellow. (The 3V3 is brown.) The 12V can deliver about 7A, 350 times more than the LED needs.


Yet, in this picture, the LED does not break, because I added some current limiting circuit. How does this work?

WARNING: Do not try this at home. Or anywhere else. Or at least don’t blame me if you do anything stupid and/or electrocute yourself. There are dangerous (potentially lethal) voltages inside a computer power supply. I won’t tell you to disconnect it from mains and discharge primary capacitors before you work on it, you should know already or else leave the cover on. Put that screwdriver down!

Voltage regulation in a atx computer PSU is done via optocouplers. The controller IC, UC3842 (or similar) is after all connected to mains power.

On the secondary side of the supply a TL431 is used to send current trough the LED of an optocoupler when the output voltage of the PSU goes too high. The TL431 is used as a comparator (it is a programmable zener / shunt regulator / voltage reference). The other side of the optocoupler is connected to the uc3842 so it lowers its duty cycle and therefore the output voltage.

At schematics of computer power supply’s can be found. Go there to see the voltage regulator circuit (And all the protection circuits I removed from my PSU)

A crude form of current limiting is actually quite easy to make.

By connecting a second optocoupler with its transistor side parallel to the transistor of the first, the output voltage will go down if the led in the second optocoupler gets activated. For the UC3842 this is the same situation as when the output voltage goes to high. So now all I need is a circuit that activates the second optocouplers LED when the output current rises to high, and I have a crude form of current limiting.

This circuit is not that hard. Every resistor has a voltage drop if there is current going trough it. Ohms law. So the output current can easily be measured by putting a resistor in series with it. A sense resistor. Then a transistor that starts conducting when the voltage over the sense resistor surpasses 0,7V. Have the transistor drive the LED from the opto, and that’s the circuit.


For this test the sense resistor is 68Ohms. This would be a current of 0,7/68R=10mA. Because the voltagedrop over the sense resistor can be annoying it’s possible to connect the voltage regulation feedback after the sense resistor so it will compensate. I have not done that for this test.

In practice I won’t limit the current to 10mA, but more likely to 10A, and the sense resistor would be much smaller (0,068R).

But for this test it’s fun to light a LED with a computer power supply.

The current limit oscillates, causing the LED to flash, see video below:

If instead of the LED I connect my ammeter, the value fluctuates between 10 and 20 mA, but probably the peak values are further apart and the meter can’t keep up with the change.

But for short circuit protection this works fine. A big disadvantage however is that the fan in the PSU is on the same 12V line and also gets tuned down / turned off when current limit kicks in.

Because all the “modified computer PSU” project i’ve so far seen on the web only mess with the output voltage and not with the current limit, I decided to post this in both Dutch and English in the hope that it will be useful to anyone, however this idea comes with NO WARRANTIES whatsoever. Please note the rectified line voltage inside those supplies is potentially lethal and capacitors might remain charged to this voltage even when the supply is disconnected from mains. Do not attempt this unless you know how to safely deal with this. If you do attempt this, you do so at your own risk.

Please let me know if you see a similar project somewhere that also deals with current limit on a modified computer powersupply.

ATX voeding stroombegrenzing.

Ik ben voor een ander project wat aan het prutsen met een oude computervoeding. Nu ik toch aan het prutsen ben, eens kijken of er een simpele stroombegrenzing te klussen valt. Het hoeft geen nette stroomregeling te zijn, als het maar kortsluitvast is.

Een LED op een uitgang van een computervoeding zal normaal gesproken onmiddellijk stuk gaan, zo’n voeding kan lomp veel stroom leveren. Het exemplaar op de foto is een oudje, de 12V lijn is oranje ipv geel (Normaal is de 3V3 oranje, maar die is hier bruin), en kan zo’n 7A leveren. De 5V (rood) zelfs 22A. De LED mag maar 20mA krijgen, dus 7/0,02=350 keer minder dan de 12V kan leveren.


Op deze foto gaat de LED niet stuk, want ik heb een stukje stroombegrenzing toegevoegd. Boven de connector is al een stukje van het circuit te zien. Maar hoe werkt het?

Waarschuwing: Niet thuis uitproberen, of waar dan ook elders, als je niet al weet hoe veilig om te gaan met de (potentieel dodelijke) gelijkgerichte netspanning in zo’n computervoeding. Als je het uitprobeert, dan doe je dat op eigen risico. Condensators kunnen nog lading bevatten ook als de voeding niet meer met het lichtnet verbonden is. De Engelse versie van deze blogpost heeft een uitgebreider disclaimer, voor de Nederlanders hoop ik op wat common sense. (Wat Engelstaligen ook moeten hebben gezien het een Engels woord is. Maar ik dwaal af)

De spanningsregulatie van een atx computervoeding gaat via optocouplers. Het regelIC, UC3842 (of variant) is immers vrijwel direct met het lichtnet verbonden.

Aan de secundaire kant van de voeding wordt een TL431 gebruikt om indien een de uitgangsspanning te hoog wordt, de LED van een opto te laten oplichten. De andere kant van de opto zit aan de uc3842, zodanig dat deze de pulsbreedte naar beneden regelt en de uitgangsspanning dus weer lager wordt.  De TL431 wordt eigenlijk als een soort comparator gebruikt, al is het een instelbare zener / voltage reference / shunt regulator.

Op zijn wat schema’s van voedingen te vinden, zie aldaar voor het spanningsregelcircuit. (En alle overvoltage/overcurrent beveiligingen die ik er bij mijn voeding uitgesloopt heb)

Een lompe vorm van stroombegrenzing blijkt veel simpeler te maken dan gedacht.

Door een 2e optocoupler met z’n transistorkant parallel te zetten aan de eerste, valt de uitgangsspanning naar beneden te regelen als er stroom door de LED van de 2e opto loopt. Vanuit de UC3842 gezien gebeurt er namelijk precies hetzelfde als wanneer de eerste opto gaan geleiden in geval van een te hoge uitgangsspanning. Nu nog een circuitje dat stroom door die optocoupler LED stuurt bij teveel uitgangsstroom, en ik heb een lompe vorm van stroombegrenzing.

Dat circuitje is niet zo moeilijk. Over elke weerstand valt spanning als er stroom door loopt, dus de uitgangsstroom laat zich makkelijk meten door een weerstand in serie te zetten. Een senseweerstand. Verder een transistor die als de spanning over de senseweerstand boven de 0,7V komt gaat geleiden. En vervolgens die transistor de LED van de 2e opto aan laten sturen.


Voor deze test is de senseweerstand 68R. Dit zou een stroombegrenzing opleveren op 0,7V/68R= ongeveer 10mA. Om de spanningsval over de senseweerstand vervelend kan zien, is het leuk de feedback van de spanningsregeling ná de senseweerstand af te tappen. Dat heb ik voor deze test niet gedaan.

In de praktijk ga ik de stroom van een voeding die zo veel stroom zou kunnen leveren als deze natuurlijk niet op 10mA begrenzen, maar eerder op rond de 10A, en de senseweerstand zou dan 0,068R worden. Maar als test is het leuk eens te proberen een LED te laten branden op een ATX voeding.

De stroombegrenzing gaat oscilleren, wat leid tot een knipperende LED. Zie het volgende filmpje.

Als ik in plaats van een LED mijn stroommeter aansluit, schommelt de waarde tussen de 10 en de 20mA, maar waarschijnlijk zijn de pieken groter en kan de multimeter het allemaal niet bijhouden.

Maar als kortsluitbeveiliging werkt dit prima. Nadeel is wel dat de ventilator van de voeding op dezelfde 12V rail zit, en dus ook naar beneden wordt geregeld/uit gaat als de stroom begrensd wordt.

Laat het me weten als je een soortgelijk project ergens tegenkomt, wat ik tot nog toe tegenkwam was alleen spanningsregeling, daarom post ik dit.

Some short notes on the Lecroy9450 repair project

Because there is no big news yet, some short updates.

– Claude Schwarz pointed me to the Yahoo user group “Lecroy Owners group”, they have design files for a HHZ406 replacement. (Made by Dieter Frieauff). So maybe the ext. trigger input can be repaired as well.

– A service manual for this ‘scope (And others) can be found there as well, or alternatively here: (Or on – but that site is full of ads)

– NoTMS was caused by a missing “Vct”, I accidentally scratched trough this trace while placing the bottom cover. Took quite some time to find, then just a little wire to fix.

9450_scratchedVCT 9450_scratchedVCTFixed

– Thanks to Claude Schwarz (Again), I now have a third ADC card. So I now have spareparts, and if I get one of the 2 broken cards working again, a working 2ch 350Mhz / 400Ms/s (10Gs/s)  DSO. (Or rather: the Leidse Makerspace then has a 2ch 350Mhz DSO). The 3 ADC cards will hereafter be named “9450_3A Claude”, “9450_3A LMS-Broken” and “9450_3A LMS-Working”. (order shown in the picture, ltr: broken, Claude, working )

9450_3A ADCs

– I measured the power supplies on “9450_3A LMS-broken”. All are present. (-5V, -12V, 5V and +12V). Next up: reference voltages and tracing the signal path.

– Some more pictures:

lecroy_patchedOn some of the ADC boards, a 5V regulator is placed where others have just a cap.


This is another original patch (-5V regulator), both on “9450_3A LMS broken”. This board has no LeCroy repair stickers (shown below), but those patches were there when I got the ‘scope so I assume they are original.

Bot these 2 regulators and the -12V and 12V ones have the correct output voltages.


Lecroy Repair stickers on the timebase board. (This board is working fine) There are more of those stickers in the scope on other boards.


And the last one for today: The calibration error log. Chan2 has “9450_3A Claude” in this picture, but “9450_3A LMS broken” gives similar results. If I exchange the cards between the channels, ch1 gets the errors and ch2 is error-free. (The error-free channel has “9450_3A LMS working” in both cases).

‘ll keep you posted!

EDIT 2-7-2014:
“Next up: reference voltages and tracing the signal path.”

Measured on HMS403, seems to be OK. Also none of the ADC’s have stuck bits (did not log what bit connected to what line of the LA, but with no input all are 0, as long as there is no selftest / calibration running.)

Please note if you connect a logic analyser to these circuits they are negative logic (“1” is – 5V, “0” = 0V). As the 0V is connected to chassis ground, and your LA’s ground might also be (through the powersuply’s both connected to earth ground), use caution!

The scope does not do a memory test on boot up. I carefully removed one of the RAM IC’s to test this, and the scope does still show “ADC/TMS state working”.

So there might be something wrong with the memory. Fortunately this is normal TTL logic again.

EDIT 8-Aug-2014:
On slower sample rates this scope only uses 1 of its 4 ADC’s (per channel). On slower sample rates, the problem stays, 1 out of 4 points on the display (Maybe 1 out of 4 samples?) is out of line. So it’s not 1 of the 4 adc’s that’s broken (because it only uses one at that sample rate), but something in the memory or further in the data pad. The memory is also divided in 4 parts/banks, so it could just be… But for now I’m going to work on other projects for a while.

Please comment if you have any questions or suggestions!

LeCroy 9450 oscilloscope repair

This was supposed to be an easy repair, and therefore not worth blogging about. But as it turns out, it might get interesting after all. (The ‘scope is not repaired yet)

The “Leidse Makerspace” owns a LeCroy 9450 350Mhz DSO. When they moved to their new location I temporarily got this oscilloscope. Not just for use or storage, but also to attempt to repair it. One of its channels was not working, sometimes it even wouldn’t display anything.

The display problem quickly turned out to be a loose connector. With this connector loose it would display nothing it al, or if it did work, it would sometimes glitch out like this:


While at other times it would display normally:


Probably just some transport damage, as after refitting this connector the problem has not been back. Now, on to the more interesting problem: channel 1 did not work: it did not respond to an input signal and it had a huge offset. After using the vertical position adjustment knob to bring it into view it would sometimes even oscillate on it’s own, showing needle-like pulses. The ‘scope also wouldn’t trigger on channel 1. Channel 2 functions fine, so it is still a usable 350Mhz DSO. However, 2 channels would be a lot nicer, and fault-finding is one of my hobbies. So… Time to remove the covers.

The easy-est way to measure in the analogue front-end of this oscilloscope is to turn it upside down, remove the bottom cover, remove the 12 screws holding the shielding, and remove the shielding.


After this, an input signal can be followed, measuring before and after each subcircuit.
(I don’t have a picture of this, but I do have a picture of the 9450_7 front end, removed from the ‘scope, and from my annotated copy of the schematic)



Close- up of the area of the board I’m looking at:


Somewhere here, the signal got lost. As you can see there is another module inserted through the pcb, this is the HHZ406. It turned out the signal entered this module (an amplifier), but nothing sensible got out.  IMG_6076_lecroy9450_HHZ406view from the other side of the board, also showing the relays. (Those metal cans)


This module does not look like it can be repaired, nothing is obviously visibly broken, and those “black blobs” don’t look promising either, because these usually cover (custom) semiconductors directly bonded to the PCB.

It also looks like it cannot be bought anywhere. Too specific, too custom… (If you know where to get these, or work for LeCroy and have spares, or if you would like to reverse-engineer them, let me know.)

But this story does not end here. This scope has 3 HHZ406 modules. One for each channel, and one for external trigger.

So I swapped the modules for external trigger and channel 1. After this, the signal got to the output of the 9450_7 board. When using the same V/Div settings on ch1 and 2, and feeding them the same input signal, the signals here would be identical.

The story does not end here either, however. Channel 1 still does not work. It does respond to an input signal and the ‘scope does trigger on this channel now, but the signal is not displayed properly. It has needle-like pulses on it. These pulses move when changing V/Div settings on the ‘scope or input signal amplitude from the signal generator. (Video:

There is another defect lurking somewhere in the 9450_3a ADC boards, because when I swap them, the problem moves to the other channel (Ch2). Measuring on these boards is harder because they are not easy to get to while the ‘scope is operating, unlike the analogue front-end (9450_7).

IMG_6036_lecroy9450_3a_adccardsTo be continued (?).