Sign in

Not a member? | Forgot your Password?

Search code

Search tips

Free PDF Downloads

A Quadrature Signals Tutorial: Complex, But Not Complicated

Understanding the 'Phasing Method' of Single Sideband Demodulation

Complex Digital Signal Processing in Telecommunications

Introduction to Sound Processing

C++ Tutorial

Introduction of C Programming for DSP Applications

Fixed-Point Arithmetic: An Introduction

Cascaded Integrator-Comb (CIC) Filter Introduction

IIR Filter Design Software

See Also

Embedded SystemsFPGA

DSP Code Sharing > Least-Squares silver bullets: Moore-Penrose Pseudoinverse (Example)

Least-Squares silver bullets: Moore-Penrose Pseudoinverse (Example)

Language: Matlab

Processor: Not Relevant

Submitted by Markus Nentwig on Oct 24 2010

Licensed under a Creative Commons Attribution 3.0 Unported License

Least-Squares silver bullets: Moore-Penrose Pseudoinverse (Example)


While not exactly a "silver bullet", the Moore-Penrose Pseudoinverse is a powerful tool that can be applied to many practical problems. It calculates a least-squares solution to an overdetermined equation system.

The Matlab program demonstrates one such example, where known interfering signals are removed from a measured signal. More information can be found here:

% *****************************************************************
% Using the Moore-Penrose Pseudoinverse to remove known disturbances from
% measured data
% all vectors are column vectors.
% *****************************************************************
close all; clear all;

% *****************************************************************
% Example: A measured signal has been polluted with power-line hum,
% at a fundamental frequency, 3rd and 5th harmonic, with unknown
% amplitude and phase.
% *****************************************************************
m=1000; % number of measured points
fs=22000; % sampling rate
fHum=50; % known 50 Hz power line hum frequency

% create power-line hum terms

% create actual data
idealData=0.1*randn(m, 1);

% create measured data - deteriorated by hum

% *****************************************************************
% Processing to remove the hum
% *****************************************************************
% We know frequency and number of harmonics
% We DO NOT the amplitude and phase of each term.
% note: a*sin(ometaT)+b*cos(omegaT) is equivalent to c*sin(omegaT+d)
% where either [a, b] or [c, d] are the unknown parameters.

basis=[sin(2*pi*index*1*fHum/fs), cos(2*pi*index*1*fHum/fs), ...
       sin(2*pi*index*3*fHum/fs), cos(2*pi*index*3*fHum/fs), ...
       sin(2*pi*index*5*fHum/fs), cos(2*pi*index*5*fHum/fs)];

% *****************************************************************
% Moore-Penrose Pseudoinverse: Least-squares fit between the basis
% waveforms and the measured signal.
% *****************************************************************


% *****************************************************************
% Plot measured signal and reconstructed hum
% *****************************************************************
figure(); hold on;
plot(reconstructedHum, 'r', 'LineWidth', 2);
legend({'measured data', 'reconstructed hum signal'});

% *****************************************************************
% Plot the remainder after subtracting the reconstructed hum.
% Compare with ideal result
% *****************************************************************
figure(); hold on;
plot(idealData,  'k', 'LineWidth', 2);
plot(idealData-correctedData, 'r', 'LineWidth', 3);
legend({'ideal result', 'measured and corrected', 'error'})
Rate this code snippet:
Rating: 3.5 | Votes: 2
posted by Markus Nentwig
Markus received his Dipl. Ing. degree in electrical engineering / communications in 1999. Work interests include RF transceiver system design, implementation, modeling and verification. He works as principal engineer (RF systems) for Nokia in Espoo, Finland.



michaelspencer wrote:

Markus, Great example of the practical use of the Pseudoinverse.

P.S. There is a minor typo on the 5th harmonic line. I think you intended:

mnentwig wrote:


thank you very much, it -is- a mistake. "5" is what I meant, but not what I wrote :-) I changed it to 3.

The artificially generated noise term contained only a 3rd harmonic, but the 5th was missing. Now both are there.

gilgamash wrote:

Well, I am not that flabbergasted. The example has nothing really exciting, and the pseudo-inverse itself shows up in a lot (way more) interesting applications, from PCA to Kernel Methods and discriminiative methods in pattern analysis, for instance.

mnentwig wrote:

Thanks for the comments!
The example was meant to be as down-to-earth as possible, for an audience who is not regularly using the feature.
If the verdict is "straightforward, unexciting, no surprises and obvious", I read it as: "mission accomplished" :-)

Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )