Octave, MATLAB, Simulink and Gnu Radio
Octave and MATLAB are high-level programming languages and environments designed for numerical computing, data analysis, and algorithm development. They are widely used in engineering, scientific research, and academia for tasks that involve matrix operations, signal processing, and data visualization. Below are examples of simple MATLAB code snippets that demonstrate basic functionality in these languages. You can run these code snippets in either Octave or MATLAB to see how they work.
% This file is titled: AudioFileOutput.m
fs = 44100; % Sample rate
t = 0:1/fs:1; % 1 second time vector
f = 440; % A4 note
signal = 0.5 * sin(2*pi*f*t); % Sine wave at half volume
% Attempt playback
try
player = audioplayer(signal, fs);
playblocking(player); % This hangs Octave until the sound finishes
fprintf('Output Test: Success! You should have heard a tone.\n');
catch
fprintf('Output Test: Failed. Octave cannot access your output device.\n');
end
Simulink (Dynamic System Modeling)
Simulink is a graphical programming environment for modeling, simulating, and analyzing dynamic systems. It is widely used in engineering fields such as control systems, signal processing, and communications. Simulink allows users to create models using a block diagram approach, where blocks represent different components of the system.
% Simulink example: Create a simple model
model = 'simple_model';
open_system(new_system(model));
add_block('simulink/Sources/Sine Wave', [model '/Sine Wave']);
add_block('simulink/Sinks/Scope', [model '/Scope']);
add_line(model, 'Sine Wave/1', 'Scope/1');
save_system(model);
Image Processing & Computer Vision
% Example MATLAB code for image processing
img = imread('example.jpg');
grayImg = rgb2gray(img);
edges = edge(grayImg, 'Canny');
imshow(edges);
Audio Programming & DSP
% Example MATLAB code for audio processing
[audioIn, fs] = audioread('example.wav');
audioOut = lowpass(audioIn, 1000, fs);
audiowrite('example_out.wav', audioOut, fs);
Artificial Intelligence (Neural Networks)
% Example MATLAB code for a simple AI model
X = [0 0; 0 1; 1 0; 1 1];
Y = [0; 1; 1; 0]; % XOR problem
net = feedforwardnet(2);
net = train(net, X', Y');
output = net(X');
disp('Output of the AI model:');
disp(output);