Sampling
Sampling
plot(t,x)
title('Continuous sinusoidal signal');
xlabel('Time(s)');
ylabel('Amplitude');
%%
fs1=30e3; %30kHz sampling rate
t1=0:1/fs1:nCyl*1/f; %time index
x1=cos(2*pi*f*t1);
subplot(2,1,1);
plot(t,x);
hold on;
stem(t1,x1);
subplot(2,1,2);
plot(t,x);
hold on;
stem(t2,x2);
_________
how can i sample this code at fs=10000
my code
n = 0:35; a = 1.2; K =0.0017;
x = K*a.^n;
stem(n,x);
xlabel('Time index n');ylabel('Amplitude');
------
clear all; clc; close all;
a = 1.2; K =0.0017;
Fs = 10E3; % sampling frequency 10KHz
Ts = 1/Fs; % sampling period
tsamples = Ts*(0:35); % sampling instants
x = K*a.^tsamples;
%plot versus sample number
figure;
stem(x);
xlabel('index n');ylabel('Amplitude');
%plot versus time
figure;
stem(tsamples, x);
xlabel('time (sec)'); ylabel('Amplitude');
___________________-
plot(t,x)
title('Continuous sinusoidal signal');
xlabel('Time(s)');
ylabel('Amplitude');
subplot(2,1,1);
plot(t,x);
hold on;
stem(t1,x1);
subplot(2,1,2);
plot(t,x);
hold on;
stem(t2,x2);
_________________-
Manipulating audio files in Matlab
Matlab’s standard installation comes with a set of audio files. The audio
files,that can be considered as one-dimensional vectors, can be inspected and
played using xpsound command. With this command, we can visualize the audio files
in three ways
The output of the xpsound command plotting time-series plot of a sample audio file
looks like this
We can also load and plot the time-series plot using inbuilt Matlab commands as
follows
>> load('gong') %load the variables for the 'gong' audio file, this loads the
sample frequency and the sample values
>> Fs %sampling frequency
Fs =
8192
ans =
-0.0027
-0.0045
-0.0074
-0.0110
-0.0128
-0.0173
-0.0223
-0.0223
-0.0200
-0.0092
>> t=0:1/Fs:length(y)/Fs-1/Fs; %time index
>> figure;plot(t,y);xlabel('Time (s)'),ylabel('y')
Example: DownSampling
In signal processing, downsampling is the process of throwing away samples without
applying any low-pass filtering. Mathematically, downsampling by a factor of M
implies, starting from the very first sample we throw away every $M-1$ samples
(i.e, keep every M-th sample.
https://www.gaussianwaves.com/2014/07/sampling-a-signal-in-matlab/