Friday, 21 November 2014

How to stop Matlab at the point of error for debugging?

1. There is an useful command 'dbstop'. Check help for more details.

2. To stop the control at the point of error in part of the function or the script use

dbstop if error

3. This has to be only once in the file. It gets applied to all the files.

4. Quite useful. Avoids rerunning the script to look for the reasons for the errors. It stops the control at the line where error is encountered and retains the work-space variables that belong to that function.


Thursday, 13 November 2014

How to design a simple low pass filter (LPF) in Matlab?

%% LPF filter specifications

fSamp = 45e6;

Fpass = 1.25e6/(fSamp/2);          % Passband Frequency
Fstop = 2.5e6/(fSamp/2);        % Stopband Frequency
Apass = 1;           % Passband Ripple (dB)
Astop = 80;          % Stopband Attenuation (dB)
match = 'passband';  % Band to match exactly

% Construct an FDESIGN object and call its BUTTER method.
%d  = fdesign.lowpass(Fpass, Fstop, Apass, Astop, fSamp);
d=fdesign.lowpass('Fp,Fst,Ap,Ast',Fpass,Fstop,Apass,Astop);
designmethods(d)
Hd = design(d,'equiripple');
fvtool(Hd); %shows the response

%Using filter

inpSignalFiltered = filter(Hd, inpSignal);