The case of a brain signal that wouldn’t tell the truth. התיק של אות מוחי שסירב לספר את האמת — ומה קרה כשלימדנו אותו להתוודות.
Same investigation, two ways in. Follow the story, or go straight to the science — you can jump between them any time. אותה חקירה, שתי דרכי כניסה. עוקבים אחרי הסיפור, או קופצים ישר למדע — אפשר לעבור ביניהם בכל רגע.
A noir investigation, ten episodes. Every clue is real signal processing wearing a trench coat. חקירה בלשית, עשרה פרקים. כל ראיה — עיבוד אותות אמיתי, לבוש במעיל טרנץ'.
Skip the story. Straight to the biology, the 9 statistics, the analysis tools, and the full correction pipeline. בלי הסיפור — ישר לביולוגיה, 9 המדדים, כלי הניתוח, וצינור התיקון המלא.
Every clue in the S1 case, pinned and connected. The red string is the theory. כל ראיה בתיק S1 — נעוצה ומחוברת. החוט האדום הוא התיאוריה. רחפו עם העכבר על ראיה.
We record the living brain of mice — some carry Alzheimer’s (5xFAD), some are healthy (WT, like our subject S1). The signal is called LFP, and it should reveal how the brain fires. But there’s a problem: every time the mouse moves, the signal lies — it jumps, it saturates, it drifts. Is what we see real brain activity, or motion wearing a disguise? המשימה: להפריד פעילות מוחית אמיתית מטביעות-האצבע של התנועה — ורק אז לשאול אם המוח החולה (5xFAD) באמת שונה מהבריא. כל פרק, השניים חוקרים שכבה נוספת של התעלומה.
7 mice (E12–E18). Five engineered mutations across two genes push the brain toward early β-amyloid buildup — a genetic model of Alzheimer’s. 7 עכברים (E12–E18). חמש מוטציות מהונדסות בשני גנים דוחפות את המוח להצטברות מוקדמת של β-amyloid — מודל גנטי לאלצהיימר.
7 mice (S1, S2, S6, S7, S9, S10, S11). Genetically normal — no engineered mutations. The baseline everything else is measured against. 7 עכברים (S1, S2, S6, S7, S9, S10, S11). תקינים גנטית — בלי מוטציות מהונדסות. קו הבסיס שמולו נמדד הכל.
Not every subject makes it to the next round. Some simply aren’t recorded again. Three are dropped mid-investigation — not because they’re innocent, but because their signal can’t testify. לא כל נבדק מגיע לסיבוב הבא. חלקם פשוט לא מוקלטים שוב. שלושה מודחים באמצע החקירה — לא כי הם חפים מפשע, אלא כי האות שלהם לא מסוגל להעיד.
Ten episodes. Each one, Lumina & Eliaz crack another layer of the signal. עשרה פרקים — ובכל אחד לומדים יחד איתי שלב נוסף בפרויקט. לחצו על פרק כדי לפתוח את התיק.
Half case-file, half real signal processing — every result on this page is genuine. Each week, another file opens. חצי תיק-חקירה, חצי עיבוד-אותות אמיתי. כל תוצאה כאן — אמיתית. עוקבים ולומדים את הפרויקט יחד, פרק אחר פרק.
Open the full Lab · המעבדה המלאה ↗Also building: a free 30-Day Engineering Mastery Challenge — control systems to signal processing, 30+ live simulations. גם בונה: 30-Day Engineering Mastery Challenge — חינם, 30 שיעורים ו-30+ סימולציות חיות.
The math behind every clue — biology, the 9 statistics, the analysis tools, the correction pipeline, and the three competing suspects (CAR, Kalman, Khorasani) put on trial in the final verdict. המתמטיקה מאחורי כל ראיה — ביולוגיה, 9 המדדים, כלי הניתוח, צינור התיקון, ושלושת החשודים המתחרים (CAR, קלמן, קורשאני) שהועמדו למשפט בפסק הדין הסופי.
Alzheimer’s disease is driven, in large part, by the amyloid cascade: a peptide called Amyloid-β (Aβ) accumulates, clumps into plaques, and disrupts neural function. To study this in the lab, we need a mouse whose brain reliably produces that pathology. That mouse is 5xFAD.
מחלת אלצהיימר מונעת במידה רבה ממפל העמילואיד: פפטיד בשם Aβ מצטבר, יוצר רבדים (plaques) ומשבש את תפקוד הנוירונים. כדי לחקור זאת דרושה חיה שהמוח שלה מייצר את הפתולוגיה באופן אמין — זהו מודל 5xFAD.
The name says it: 5×FAD = five Familial Alzheimer’s Disease mutations, engineered into two human genes and expressed in the mouse brain under the neuronal Thy1 promoter (Oakley et al., 2006).
The parent protein that Aβ is cut out of. These mutations sit right around the cut sites and push production toward Aβ:
The catalytic core of γ-secretase, the enzyme that makes the final cut. These mutations shift the cut toward the stickier Aβ42:
APP is cut by two enzymes in sequence — β-secretase then γ-secretase — releasing the Aβ peptide. There are two main lengths: Aβ40 (more soluble) and Aβ42 (aggregation-prone, the troublemaker). The five mutations conspire to (1) make more Aβ overall, and (2) tilt the ratio toward Aβ42:
| Age | Pathology |
|---|---|
| ~1.5–2 mo | Amyloid plaques appear (aggressive, early onset) |
| ~4–5 mo | Spatial memory deficits |
| ~6–12 mo | Neuronal loss, gliosis, motor/cognitive decline |
Caveat (worth knowing): 5xFAD reproduces amyloid pathology but not neurofibrillary tau tangles — a real difference from human AD.
Four channels, one brain, two different wiring schemes. Click a channel to see exactly what it measures. ארבעה ערוצים, מוח אחד, שתי שיטות חיווט שונות. לחצו על ערוץ כדי לראות מה בדיוק הוא מודד.
CH1/CH2 הם יוניפולריים — מול אלקטרודת ייחוס משותפת מעל קורטקס ויזואלי. CH3/CH4 ביפולריים — הפרש בין שני אתרים, בלי ייחוס משותף.
Stage 0 (see The 9 Stats) only characterizes the raw signal — it changes nothing. Stage 1 is the first stage that actually touches the data: three housekeeping steps, none of which decide what counts as an artifact and none of which touch the raw HDF5 files — each works on a copy. שלב 0 (ראו 9 המדדים) רק מאפיין את האות הגולמי — לא משנה כלום. שלב 1 הוא השלב הראשון שבאמת נוגע בנתונים: שלושה צעדי הכנה, אף אחד מהם לא מחליט מה נחשב ארטיפקט ואף אחד לא נוגע בקובצי ה-HDF5 הגולמיים — כל אחד עובד על עותק.
Several standard normalization schemes were compared side by side early on. None of them changed the downstream picture in a meaningful way — so normalization choice is not a sensitive design decision in this pipeline, and the simplest option was kept. כמה שיטות נרמול נבדקו זו מול זו בשלב מוקדם. אף אחת לא שינתה את התמונה בהמשך באופן משמעותי — כך שבחירת הנרמול אינה החלטת עיצוב רגישה כאן, ונשמרה האפשרות הפשוטה ביותר.
Every channel is shifted so its own global median sits at zero — purely for PSD stability, not a scientific claim about baseline. The median is used (not the mean) because it’s robust to the saturation spikes already known to exist in some channels. כל ערוץ מוזז כך שהחציון הגלובלי שלו יושב באפס — למען יציבות ה-PSD בלבד, לא כטענה מדעית על הבסיס. נבחר חציון (לא ממוצע) כי הוא עמיד מול קפיצות רוויה שכבר ידוע שקיימות בחלק מהערוצים.
Israel’s electrical grid runs at 50 Hz, with its first harmonic at 100 Hz. Both leak into the recordings as sharp spectral lines that have nothing to do with the brain. רשת החשמל בישראל היא 50Hz, וההרמוניה הראשונה יושבת ב-100Hz. שתיהן מדליפות להקלטה כקווים ספקטרליים חדים שאין להם קשר למוח.
Two things were tried first, and rejected: a standard IIR notch filter carved deep spectral holes at exactly 50/100 Hz (over-correction), and fully zeroing the sinusoid did the same. Both distort the natural shape of the PSD right around the line frequency — exactly where a later biological-rhythm search could be misled. שני דברים נוסו ונפסלו: notch filter רגיל יצר "בורות" ספקטרליים עמוקים בדיוק ב-50/100Hz (תיקון-יתר), ואיפוס מלא של הסינוס עשה אותו הדבר. שניהם מעוותים את צורת ה-PSD הטבעית סביב תדר הרשת — בדיוק שם שחיפוש קצב ביולוגי עלול להיטעות בהמשך.
Instead of a fixed filter, the correction runs per 6-second epoch (\(N=6000\) samples) and only caps a peak that’s actually too loud — it never forces the frequency to zero:
The correction only runs where a locked, manually-reviewed policy says a specific channel of a specific recording actually shows the line-noise problem — e.g. E12_6m channels 1&2, or S9_9m channels 1&2. Most recordings need no correction at all. התיקון מופעל רק היכן שמדיניות נעולה, שנבדקה ידנית, קובעת שערוץ ספציפי בהקלטה ספציפית באמת מציג את בעיית רעש הרשת. רוב ההקלטות לא זקוקות לתיקון בכלל.
Each recording runs about 17 minutes at \(f_s=1000\,\text{Hz}\) — nearly all files hold exactly 1,048,575 samples. Three recordings are shorter, for reasons unrelated to the correction above:
| Recording | Samples | ≈ Duration |
|---|---|---|
| E12 · 4m | 903,573 | ~15.1 min |
| E17 · 4m | 701,572 | ~11.7 min |
| S6 · 6m | 725,891 | ~12.1 min |
For every channel of every recording (\(N\) samples at \(f_s=1000\,\text{Hz}\)) we compute nine metrics. Each targets one failure mode of an LFP signal. Let \(x[n]\) be the signal and \(\Delta x[n]=x[n]-x[n-1]\) its sample-to-sample difference.
The signal’s effective amplitude. Abnormally high RMS flags a noisy or artifact-dominated channel. אמפליטודה אפקטיבית — ערך גבוה מסמן ערוץ רועש.
A robust noise scale is estimated from the differences using the Median Absolute Deviation:
Percentage of samples that jump more than 8 robust-sigmas — the fingerprint of movement. The \(1.4826\) makes MAD a consistent estimator of \(\sigma\) for Gaussian noise. אחוז הדגימות שקופצות מעל 8 סיגמות רובוסטיות — טביעת האצבע של תנועה.
The 4th standardized moment. A Gaussian sits at \(3\); higher values mean heavy tails — rare, sharp spikes riding on the signal. מומנט רביעי — ערך גבוה = פסגות חדות וחריגות.
Magnitude of the single largest step — the size of the worst movement event.
Slow baseline shift across the recording. Medians (not means) make it robust to spikes. סחף בסיס איטי לאורך ההקלטה — חציונים עמידים לחריגים.
Fraction of total power sitting in the slow delta band. Motion and drift dump energy low; a high ratio is a technical red flag (not a biological claim at this stage). שבר האנרגיה בפס האיטי — תנועה/סחף שופכים אנרגיה נמוך.
How many samples are stuck at the exact minimum / maximum — the signature of ADC clipping at the \(\pm427\,\mu V\) rail. (We subtract 1 because every signal has one natural min and max.) כמה דגימות תקועות בדיוק על המינימום/מקסימום — חתימת רוויית ADC.
The 1st-to-99th percentile span — the amplitude range while ignoring the most extreme 1% on each side (outlier-proof).
Each channel gets labelled Failure / High / Moderate / Clean by running its nine numbers against a locked set of thresholds — no single metric decides alone.
Sampling at \(f_s=1000\,\text{Hz}\) means the highest representable frequency is the Nyquist limit:
We read the signal’s energy across biological bands via its power spectral density \(P(f)\):
| Band | Range | Meaning |
|---|---|---|
| Delta | 0.5–4 Hz | slow / drift — technical red flag here |
| Theta | 4–8 Hz | navigation, memory, hippocampus — key biomarker |
| Alpha | 8–13 Hz | rest |
| Beta | 13–30 Hz | cognition, motor |
| Gamma | 30–100 Hz | encoding / processing — key biomarker |
A raw trace shows voltage over time; an FFT shows frequency but loses when. Motion artifacts are not always sharp spikes — they can be slow baseline shifts, decays, recoveries. To catch them we need both axes at once. The Continuous Wavelet Transform slides a scaled/shifted wavelet \(\psi\) across the signal:
where \(a\) is scale (∝ 1/frequency) and \(b\) is time. The result — a scalogram — is an energy map: time on X, frequency on Y, colour = energy. This is exactly what Stage 2 actually runs on: a Morlet scalogram across 2–250Hz, Z-scored per frequency row. A brain rhythm lives in one narrow frequency lane; a real artifact lights up many adjacent lanes at once.
The Tunable-Q Wavelet Transform (Selesnick) sorts signal by resonance, not just frequency: sustained oscillations (brain rhythms) are high-Q, abrupt transients are low-Q. This project uses that selectivity for construction, not classification — per channel, per 6-second window, it rebuilds the signal from only the sub-bands that fall in one range:
X_ref never decides what's an artifact — Stage 2's rule-based detector already did that; X_ref is just the "clean" stand-in, ready to go there.
I wrote about this (EEG + TQWT) · LinkedIn ↗A comparison between 5xFAD and WT only means something if the same mouse, recorded again at a later age, is still comparable to its earlier self — not a different recording setup wearing the same mouse ID. Each mouse gets a spectral fingerprint (its own PSD shape) computed independently at 4, 6, and 9 months, and the fingerprints are correlated pairwise across ages.
29 of 32 recordings make it into the analysis. The 3 that don’t (see Prep for the exact list) are excluded because they failed a quality threshold derived from Stage 0’s statistics — decided before any group comparison was run, not after looking at results. That ordering is the entire point: a pass/fail rule fixed in advance and documented is reproducible quality control. The same exclusion made after seeing which recordings are inconvenient for the hypothesis is no longer quality control — it’s selecting the answer.
A continuous wavelet transform (Morlet, 2–250Hz) turns each 60-second block into a scalogram, Z-scored per frequency row against its own median/MAD. Two severity tiers, plus an amplitude check merged into the milder one:
| Category | Rule | Threshold |
|---|---|---|
| RED | saturation (flat/hard rail), or a strict broadband wavelet burst | Z ≥ 6.0 · 380/405µV |
| BLUE | a relaxed wavelet burst, or a jump ≥2 of 4 channels agree on | Z ≥ 4.5 · Z ≥ 5.0 |
Whatever RED already claims is carved out of BLUE first — the two never overlap in the final mask. An amplitude jump only counts toward BLUE if at least 2 of the 4 channels register it in the same window — one twitchy wire alone doesn’t qualify. כל מה ש-RED תופס נגזר מ-BLUE מראש — השניים לעולם לא חופפים במסכה הסופית. קפיצת עוצמה נספרת רק אם לפחות 2 מתוך 4 הערוצים מזהים אותה באותו חלון.
A fully independent, per-channel reference signal — no cross-channel averaging at all. Every 6-second window, TQWT rebuilds the signal from only the sub-bands whose center frequency lands in one range:
In practice the toolbox’s actual sub-band centers resolve to 4.105–95.627Hz, not a clean 4–105. This reference doesn’t decide what’s an artifact — Stage 2 already did that. X_ref is the "clean" stand-in, ready to be substituted wherever a method needs it.
The pure TQWT reference has a gap: it starts at ~4Hz, so it says nothing about the slow delta band. Stage 3.5 fills that gap with a Butterworth bandpass and adds it in:
The result covers 0.5–95.627Hz — the full biologically relevant range, not just 4Hz and up. From here on, every correction stage runs twice: once fed the pure TQWT reference, once fed this wider Unified one — two alibis, compared side by side. מכאן ואילך כל שלב תיקון רץ פעמיים: פעם עם האזין הטהור של TQWT, פעם עם ה-Unified הרחב יותר — שני אליבים, בהשוואה זה לצד זה.
Before settling on CAR/Kalman/Khorasani, the most promising lead was SSA (Singular Spectrum Analysis): decompose the pre-artifact context, forecast forward into the damaged window, decompose the post-artifact context, forecast backward, then blend the two gradually across it — nicknamed Kalman Blend even though it isn’t a Kalman filter at all. The flaw: a forecast is a plausible statistical continuation, not a recovered measurement. LFP is non-stationary, so “the pre-artifact dynamics keep going through the gap” is a fragile assumption — and inside saturation windows the original information doesn’t exist to forecast toward in the first place. Forecasts were sometimes noisier than the raw signal, especially in short windows, and had to fall back to source.
| Candidate | Verdict | Why |
|---|---|---|
| SSA (“Kalman Blend”) | Rejected | forecast treated as ground truth in a region with no ground truth to check against |
| ICA | Rejected | only 3 independent channels — not enough for real spatial separation |
| Deep learning | Rejected | no ground-truth clean signal exists to train against |
| Template subtraction | Rejected | assumes periodic noise; free-moving motion artifacts are one-off, not periodic |
| ANC | Rejected | needs an external reference channel that doesn’t exist in this setup |
Stages 4, 5 and 6 all answer the same question with a different amount of freedom. Model each channel as x(t) = s(t) + w(t)·n(t) — measured = brain signal + weight × shared noise. The whole design space is what you let \(w\) be:
| Stage | w is… | Causal? |
|---|---|---|
| 4 — CAR | one constant per channel, for the whole recording | n/a (static) |
| 5 — Kalman | a scalar state that moves every sample (forward + RTS backward) | No |
| 6 — Khorasani | a length-5 vector — magnitude and delay/phase | Yes |
The classic idea behind CAR (Common Average Reference): assume each channel’s genuine noise is independent, so subtracting the average across enough channels cancels the noise while leaving the shared signal alone:
With N=16 independent channels (the textbook case) that suppresses buried noise by \(10\log_{10}(1/N)\approx-12\)dB. This project has only 3 independent channels (CH1, CH2, CH4) — the same trick buys just -4.8dB, a real ~7dB gap. Flat averaging isn’t enough, so every channel gets its own weight instead of a blind \(1/N\) — computed once per recording, then applied to every sample:
| Method | Formula | Meaning |
|---|---|---|
| A | X_pre − w·mean(X_pre) | common-mode from the raw signal |
| B | X_pre − w·mean(X_ref) | common-mode from the reference |
| C | X_ref − w·mean(X_ref) | CAR on the Stage-3 reference |
Weight per channel: \(\displaystyle w_i = \frac{\text{rms}(X_{\text{pre}}-X_{\text{ref}})_i}{\sum_i \text{rms}(X_{\text{pre}}-X_{\text{ref}})_i}\) — one number per channel, for the whole recording. משקל לכל ערוץ לפי rms ההפרש בינו לבין הייחוס — מספר אחד לכל ערוץ, לכל ההקלטה.
Stage 4’s CAR weight is one static number per channel. Stage 5 lets that same weight drift over time — a real Kalman filter, not a metaphor. Model per channel \(i\): the residual \(d_i[k]=X_{\text{pre},i}[k]-X_{\text{ref},i}[k]\) is explained by a time-varying weight on the common mode \(c[k]=\text{mean}_j(X_{\text{pre}}[k,:])\):
Forward pass, then an RTS backward smoother refines the whole weight trajectory using future samples too — not just causal, the full recording is known in advance:
Correction: \(X_{\text{corrected},i}[k] = X_{\text{pre},i}[k] - w_i^{\text{RTS}}[k]\cdot c[k]\). התיקון: מחסרים מכל דגימה את המשקל המוחלק (RTS) כפול המצב המשותף.
Khorasani (2019) estimates a dynamic AR(5) weight for the common mode instead of one static number — five taps of memory, not one:
where \(h(t)=[n(t),\,n(t{-}1),\,\dots,\,n(t{-}4)]\) is the common mode’s own recent history, \(\alpha=0.99\), and the Kalman update is standard (predict, gain, correct). Run in 3 input modes — fed raw X_pre, the TQWT reference, or the Unified one:
This is a methods verdict, not the biological one. It answers which correction technique to trust — not whether 5xFAD differs from WT in theta/gamma. That question is still open.
| Rank | Method | Artifact Reduction | Baseline Distance |
|---|---|---|---|
| 1 | Khorasani, fed TQWT ref | +6.31 dB | 13.52 µV |
| 2 | CAR·C (on TQWT ref) | +4.51 dB | 13.08 µV |
| 3 | Khorasani, fed Unified ref | +4.24 dB | 9.59 µV |
| 6 | Kalman (Stage 5, on TQWT ref) | +3.02 dB | 7.32 µV |
| Priority | Method | Trade-off |
|---|---|---|
| Conservative | Kalman, Unified ref | almost no distortion, almost no cleanup |
| Balanced | Khorasani, raw X_pre | solid reduction, moderate distortion |
| Aggressive | Khorasani, TQWT ref | best reduction, most distortion |
Genotype check (descriptive only, small cohort, no causal claim): 5xFAD and WT show near-identical correction behavior (+1.14dB vs +1.25dB) — the pipeline treats sick and healthy brains the same way. Whether their underlying theta/gamma actually differ is a separate analysis, not yet run.
Nine self-contained stages, each reading the previous one’s output from disk and writing its own — no shared memory between stages, so any one of them can be re-run and re-verified in isolation. 29 recordings clear the entire chain in about 25 minutes: 52.6 seconds per recording, all on a MacBook M3 with 8GB — no cluster, no GPU, no cloud.
| Stage | Share of runtime |
|---|---|
| Stage 3 — building the reference | 43% |
| Stage 6 — Khorasani correction | 17.6% |
| Stage 2 — detection | 15% |
| Everything else combined | <25% |
What got built here isn’t an answer — it’s a laboratory: a documented, re-runnable, arguable chain. The question that started the investigation — does an Alzheimer’s-model brain really look different from a healthy one, once motion is properly removed — is still open. What exists now is the instrument that can finally ask it honestly. מה שנבנה כאן הוא לא תשובה — זו מעבדה: שרשרת מתועדת, ניתנת להרצה חוזרת ולערעור. השאלה שבגללה התחילה החקירה עדיין פתוחה. מה שיש עכשיו הוא המכשיר שסוף-סוף יכול לשאול אותה ביושר.