A program to generate an amplitude modulated wave modulated frequency 2000HZ and carrier frequency 108000HZ and study of its characteristics

fm=2000;
fc=1080000;
time=0:2.3148e-7:8e-4;%Sampling frequency 320000
amp=1;
ac=2;
k=amp/ac;

modwave=amp*cos(2*pi*fm*time);
figure(1);
plot(time,modwave);
title(' Waveform of modulating signal');
xlabel('Time (sec)');
ylabel('Amplitude');
grid on;

carwave=ac*cos(2*pi*fc*time);
figure(2);
plot(time(1:500),carwave(1:500));
title(' Waveform of carrier signal');
xlabel('Time (sec)');
ylabel('Amplitude');
grid on;

figure(3);
mt=k*cos(2*pi*fm*time);
sam=ac*(1+mt).*cos(2*pi*fc*time);
plot(time(1:2000),sam(1:2000));
title(' Waveform of modulated signal');
xlabel('Time (sec)');
ylabel('Amplitude');
grid on;

n=length(time);
figure(4)   
spectrum=abs(fftshift(fft(modwave,n)))/n;   
 fw=-2160000:1250:2160000;   
plot(fw(1326:2304),spectrum(1326:2304))   
title('Frequency Domain analysis of modulating wave')   
xlabel('Frequency (Hz)')   
ylabel('Magnitude')

figure(5)   
spectrum1=abs(fftshift(fft(carwave,n)))/n;   
 fw=-2160000:1250:2160000;
plot(fw,spectrum1)   
title('Frequency Domain analysis of carrier wave')   
xlabel('Frequency (Hz)')   
ylabel('Magnitude')

figure(6)   
spectrum2=abs(fftshift(fft(sam,n)))/n;   
 fw=-2160000:1250:2160000;
plot(fw,spectrum2)   
title('Frequency Domain analysis of modulated wave')   
xlabel('Frequency (Hz)')   
ylabel('Magnitude')   

A program to generate an amplitude modulated wave with modulated frequency 5000HZ and carriar frequency 1080000HZ and study of its characteristics

fm=5000;
fc=1080000;
time=0:2.3148e-7:8e-4;
amp=1;
ac=2;
k=amp/ac;

modwave=amp*cos(2*pi*fm*time);
figure(1);
plot(time,modwave);
title(' Waveform of modulating signal');
xlabel('Time (sec)');
ylabel('Amplitude');
grid on;

carwave=ac*cos(2*pi*fc*time);
figure(2);
plot(time(1:500),carwave(1:500));
title(' Waveform of carrier signal');
xlabel('Time (sec)');
ylabel('Amplitude');
grid on;

figure(3);
mt=k*cos(2*pi*fm*time);
sam=ac*(1+mt).*cos(2*pi*fc*time);
plot(time(1:1500),sam(1:1500));
title(' Waveform of modulated signal');
xlabel('Time (sec)');
ylabel('Amplitude');
grid on;

n=length(time);
figure(4)   
spectrum=abs(fftshift(fft(modwave,n)))/n;   
 fw=-2160000:1250:2160000;   
plot(fw(1152:2304),spectrum(1152:2304))   
title('Frequency Domain analysis of modulating wave')   
xlabel('Frequency (Hz)')   
ylabel('Magnitude')

figure(5)   
spectrum1=abs(fftshift(fft(carwave,n)))/n;   
 fw=-2160000:1250:2160000;
plot(fw,spectrum1)   
title('Frequency Domain analysis of carrier wave')   
xlabel('Frequency (Hz)')   
ylabel('Magnitude')

figure(6)   
spectrum2=abs(fftshift(fft(sam,n)))/n;   
 fw=-2160000:1250:2160000;
plot(fw,spectrum2)   
title('Frequency Domain analysis of modulated wave')   
xlabel('Frequency (Hz)')   
ylabel('Magnitude')   
clear all;
close all;
% Test with synthetically generated sinusoidal wave
f=1000;% Frequency of the audio signal
Fs =64000; % Sampling rate is 4000 samples per second.
t = [1/Fs:1/Fs:1];% total time for simulation=0.05 second.
% Number of samples=4000
Am=1.0;
signal = Am*sin(2*pi*1000*t); % Original signal
figure(1);
plot(t(1:256),signal(1:256))
set(gca,'ytick',[ -1.0   0 1.0 ])
title('A segment of synthetically generated sinusiodal wavform')
grid on
xlabel( 'time(sec)');
ylabel( 'Amplitude(volt)');


% Quantization Part
maximumvalue=max(signal);
minimumvalue=min(signal);
interval=(maximumvalue-minimumvalue)/255; % interval:
partition = [minimumvalue:interval:maximumvalue]; % -1:0.0078:1
codebook = [(minimumvalue-interval):interval:maximumvalue]; % -1.0078:0.0078:1, Total number of
%codebook's valu must exceed by 1 from partition.So minimumvalue-interval is used.
[index,quants,distor] = quantiz(signal,partition,codebook);


% Convertion of deci  into binary from least  to most significant
indxtrn=index';
for i=1:64000
matrix(i,1:1:8)=bitget(uint8(indxtrn(i)),1:1:8);
end,


% The part of producing baseband signal
% matrix is of  4000 rows X 8 columns
matrixtps=matrix';% matrixtps is a matrix of 8 rows X4000 columns
% Baseband is produced, it has 32000 bits
baseband=reshape(matrixtps,64000*8,1);
Tb=1/512000;
% bit rate 32 kbps
time=[0:Tb:1];
figure(2);
stairs(time(1:500),baseband(1:500))
title(' A segment of baseband signal')
xlabel('Time(sec)')
ylabel('Binary value')
set(gca,'ytick',[0  1 ])
axis([0,time(500),0,1])


%Quadrature phase shift keying modulation and demodulation
M=16;
k=log2(M);
baseband=double(baseband);
% bit to symbol mapping
symbol=bi2de(reshape(baseband,k,length(baseband)/k).','left-msb');
Quadrature_amplitude_modulated_data = qammod(symbol,M);
% demodulation of Quadrature phase shift keying data
Quadrature_amplitude_demodulated_data = qamdemod(Quadrature_amplitude_modulated_data,M);


%The part of retrieving orginal signal from Binary_phase_shift_keying_demodulated_data.
% symbol to  bit mapping
% 2-bit symbol to Binary bit mapping
Retrieved_bit = de2bi(Quadrature_amplitude_demodulated_data,'left-msb');
Retrieved_bit=Retrieved_bit';
Retrieved_bit=reshape(Retrieved_bit, 512000,1);
convert=reshape(Retrieved_bit,8,64000); % First reshaping and then transposing
matrixtps=double(matrixtps);
convert=convert' ; % 4000 rows X 8 columns
% binary to decimally converted value
intconv=bi2de(convert); % converted into interger values(0-255) of 4000 samples
% intconv is 4000 rows X 1 column
sample_value=minimumvalue +intconv.*interval;


% The part of Comparison display of orginal signal and retrieved signal
figure(3)
subplot(2,1,1)
plot(t(1:256),signal(1:256));
set(gca,'ytick',[ -1.0   0 1.0 ])
axis([0,t(257),-1,1])
title('Graph for a segment of recoded Audio signal')
xlabel('Time(sec)')
ylabel('Amplitude')
grid on
subplot(2,1,2)
plot(time(1:256),sample_value(1:256));
axis([0,time(257),-1,1])
set(gca,'ytick',[ -1.0   0 1.0 ])
title('Graph for a segment of retrieved Audio signal')
xlabel('Time(sec)')
ylabel('Amplitude')
grid on

%error mapping and display
[number1,ratio]= symerr(symbol,Quadrature_amplitude_demodulated_data ) % symbol error
[number2,ratio]= biterr(Retrieved_bit,baseband)
[number3,ratio]= biterr(convert',matrixtps)
[number4,ratio]= biterr(intconv',index);


clear all;
close all;
% Test with synthetically generated sinusoidal wave
f=1000;% Frequency of the audio signal
Fs =16000; % Sampling rate is 4000 samples per second.
t = [1/Fs:1/Fs:1];% total time for simulation=0.05 second.
% Number of samples=4000
Am=1.0;
signal = Am*sin(2*pi*1000*t); % Original signal
figure(1);
plot(t(1:64),signal(1:64))
set(gca,'ytick',[ -1.0   0 1.0 ])
title('A segment of synthetically generated sinusiodal wavform')
grid on
xlabel( 'time(sec)');
ylabel( 'Amplitude(volt)');

% Quantization Part
maximumvalue=max(signal);
minimumvalue=min(signal);
interval=(maximumvalue-minimumvalue)/255; % interval:
partition = [minimumvalue:interval:maximumvalue]; % -1:0.0078:1
codebook = [(minimumvalue-interval):interval:maximumvalue]; % -1.0078:0.0078:1, Total number of
%codebook's valu must exceed by 1 from partition.So minimumvalue-interval is used.
[index,quants,distor] = quantiz(signal,partition,codebook);

% Convertion of deci  into binary from least  to most significant
indxtrn=index';
for i=1:16000
matrix(i,1:1:8)=bitget(uint8(indxtrn(i)),1:1:8);
end,

% The part of producing baseband signal
% matrix is of  4000 rows X 8 columns
matrixtps=matrix';% matrixtps is a matrix of 8 rows X4000 columns
% Baseband is produced, it has 32000 bits
baseband=reshape(matrixtps,16000*8,1);
Tb=1/128000;
% bit rate 32 kbps
time=[0:Tb:1];
figure(2);
stairs(time(1:500),baseband(1:500))
title(' A segment of baseband signal')
xlabel('Time(sec)')
ylabel('Binary value')
set(gca,'ytick',[0  1 ])
axis([0,time(500),0,1])

%Quadrature phase shift keying modulation and demodulation
M=4;
k=log2(M);
baseband=double(baseband);
% bit to symbol mapping
symbol=bi2de(reshape(baseband,k,length(baseband)/k).','left-msb');
Quadrature_amplitude_modulated_data = qammod(symbol,M);
% demodulation of Quadrature phase shift keying data
Quadrature_amplitude_demodulated_data = qamdemod(Quadrature_amplitude_modulated_data,M);

%The part of retrieving orginal signal from Binary_phase_shift_keying_demodulated_data.
% symbol to  bit mapping
% 2-bit symbol to Binary bit mapping
Retrieved_bit = de2bi(Quadrature_amplitude_demodulated_data,'left-msb');
Retrieved_bit=Retrieved_bit';
Retrieved_bit=reshape(Retrieved_bit, 128000,1);
convert=reshape(Retrieved_bit,8,16000); % First reshaping and then transposing
matrixtps=double(matrixtps);
convert=convert' ; % 4000 rows X 8 columns
% binary to decimally converted value
intconv=bi2de(convert); % converted into interger values(0-255) of 4000 samples
% intconv is 4000 rows X 1 column
sample_value=minimumvalue +intconv.*interval;

% The part of Comparison display of orginal signal and retrieved signal
figure(3)
subplot(2,1,1)
plot(t(1:80),signal(1:80));
set(gca,'ytick',[ -1.0   0 1.0 ])
axis([0,t(81),-1,1])
title('Graph for a segment of recoded Audio signal')
xlabel('Time(sec)')
ylabel('Amplitude')
grid on
subplot(2,1,2)
plot(t(1:80),sample_value(1:80));
axis([0,t(81),-1,1])
set(gca,'ytick',[ -1.0   0 1.0 ])
title('Graph for a segment of retrieved Audio signal')
xlabel('Time(sec)')
ylabel('Amplitude')
grid on

%error mapping and display
[number,ratio]= symerr(symbol,Quadrature_amplitude_demodulated_data ) % symbol error
[number,ratio]= biterr(Retrieved_bit,baseband)
[number,ratio]= biterr(convert',matrixtps)
[number,ratio]= biterr(intconv',index);

clear all;
close all;
% Test with synthetically generated sinusoidal wave
f=1000;% Frequency of the audio signal
Fs =4000; % Sampling rate is 4000 samples per second.
t = [1/Fs:1/Fs:1];% total time for simulation=0.05 second.
% Number of samples=4000
Am=1.0;
signal = Am*sin(2*pi*1000*t); % Original signal
figure(1);
plot(t(1:200),signal(1:200))
set(gca,'ytick',[ -1.0   0 1.0 ])
title('A segment of synthetically generated sinusiodal wavform')
grid on
xlabel( 'time(sec)');
ylabel( 'Amplitude(volt)');
maximumvalue=max(signal);
minimumvalue=min(signal);


% Quantization Part
interval=(maximumvalue-minimumvalue)/255; % interval:
partition = [minimumvalue:interval:maximumvalue]; % -1:0.0078:1
codebook = [(minimumvalue-interval):interval:maximumvalue]; % -1.0078:0.0078:1, Total number of
%codebook's valu must exceed by 1 from partition.So minimumvalue-interval is used.
[index,quants,distor] = quantiz(signal,partition,codebook);


% Convertion of deci  into binary from least  to most significant
indxtrn=index';
for i=1:4000
matrix(i,1:1:8)=bitget(uint8(indxtrn(i)),1:1:8);
end,

% The part of producing baseband signal
% matrix is of  4000 rows X 8 columns
matrixtps=matrix';% matrixtps is a matrix of 8 rows X4000 columns
% Baseband is produced, it has 32000 bits
baseband=reshape(matrixtps,4000*8,1);
Tb=1/32000;
% bit rate 32 kbps
time=[0:Tb:1];
figure(2);
stairs(time(1:500),baseband(1:500))
title(' A segment of baseband signal')
xlabel('Time(sec)')
ylabel('Binary value')
set(gca,'ytick',[0  1 ])
axis([0,time(500),0,1])


% The part of quadrature phase shift keying modulation and demodulation
M=4;
k=log2(M);
baseband=double(baseband);
% bit to symbol mapping
symbol=bi2de(reshape(baseband,k,length(baseband)/k).','left-msb');
Quadrature_phase_shift_keying_modulated_data = pskmod(symbol,M);
% demodulation of Quadrature phase shift keying data
Quadrature_phase_shift_keying_demodulated_data = pskdemod(Quadrature_phase_shift_keying_modulated_data,M);


%The part of retrieving orginal signal from Binary_phase_shift_keying_demodulated_data.
% symbol to  bit mapping
% 2-bit symbol to Binary bit mapping
Retrieved_bit = de2bi(Quadrature_phase_shift_keying_demodulated_data,'left-msb');
Retrieved_bit=Retrieved_bit';
Retrieved_bit=reshape(Retrieved_bit, 32000,1);
convert=reshape(Retrieved_bit,8,4000); % First reshaping and then transposing
matrixtps=double(matrixtps);
convert=convert' ; % 4000 rows X 8 columns
% binary to decimally converted value
intconv=bi2de(convert); % converted into interger values(0-255) of 4000 samples
% intconv is 4000 rows X 1 column
sample_value=minimumvalue +intconv.*interval;


% The part of Comparison display of orginal signal and retrieved signal
figure(3)
subplot(2,1,1)
plot(time(1:500),signal(1:500));
set(gca,'ytick',[ -1.0   0 1.0 ])
axis([0,time(100),-1,1])
title('Graph for a segment of recoded Audio signal')
xlabel('Time(sec)')
ylabel('Amplitude')
grid on
subplot(2,1,2)
plot(time(1:100),sample_value(1:100));
axis([0,time(100),-1,1])
set(gca,'ytick',[ -1.0   0 1.0 ])
title('Graph for a segment of retrieved Audio signal')
xlabel('Time(sec)')
ylabel('Amplitude')
grid on

%error mapping and display
[number1,ratio]= symerr(symbol,Quadrature_phase_shift_keying_demodulated_data) % symbol error
[number2,ratio]= biterr(Retrieved_bit,baseband)
[number3,ratio]= biterr(convert',matrixtps)
[number4,ratio]= biterr(intconv',index)











  Home
 clear all;
close all;
% Test with synthetically generated sinusoidal wave
f=1000;% Frequency of the audio signal
Fs =4000; % Sampling rate is 4000 samples per second.
t = [1/Fs:1/Fs:1];% total time for simulation=0.05 second.
% Number of samples=4000
Am=1.0;

signal = Am*sin(2*pi*1000*t); % Original signal
figure(1);
plot(t(1:200),signal(1:200))
set(gca,'ytick',[ -1.0   0 1.0 ])
title('A segment of synthetically generated sinusiodal wavform')
grid on
xlabel( 'time(sec)');
ylabel( 'Amplitude(volt)');

maximumvalue=max(signal);
minimumvalue=min(signal);
interval=(maximumvalue-minimumvalue)/255; % interval:

% Quantization Part
partition = [minimumvalue:interval:maximumvalue]; % -1:0.0078:1
codebook = [(minimumvalue-interval):interval:maximumvalue]; % -1.0078:0.0078:1,Total number of
%codebook's valu must exceed by 1 from partition.So minimumvalue-interval is tsed.
[index,quants,distor] = quantiz(signal,partition,codebook);

% Convertion of deci  into binary from least  to most significant
indxtrn=index';
for i=1:4000
matrix(i,1:1:8)=bitget(uint8(indxtrn(i)),1:1:8);
end,

% The part of producing baseband signal
% matrix is of  4000 rows X 8 columns
matrixtps=matrix';% matrixtps is a matrix of 8 rows X4000 columns
% Baseband is produced, it has 32000 bits
baseband=reshape(matrixtps,4000*8,1);
Tb=1/32000;
% bit rate 32 kbps
time=[0:Tb:1];
figure(2);
stairs(time(1:500),baseband(1:500))
title(' A segment of baseband signal')
xlabel('Time(sec)')
ylabel('Binary value')
set(gca,'ytick',[0  1 ])
axis([0,time(500),0,1])

%The part of Binary phase shift keying modulation and demodulation
M=2;
k=log2(M);
% bit to symbol mapping
symbol=bi2de(reshape(baseband,k,length(baseband)/k).','left-msb');
symbol=double(symbol);
Binary_phase_shift_keying_modulated_data = pskmod(symbol,M);
% demodulation of  Binary phase shift keying data
Binary_phase_shift_keying_demodulated_data = pskdemod(Binary_phase_shift_keying_modulated_data,M);

%The part of retrieving orginal signal from Binary_phase_shift_keying_demodulated_data.
% 1-bit symbol to Binary bit mapping
Retrieved_bit = de2bi(Binary_phase_shift_keying_demodulated_data,'left-msb');
baseband=double(baseband);
convert=reshape(Retrieved_bit,8,4000); % First reshaping and then transposing
matrixtps=double(matrixtps);
convert=convert' ; % 4000 rows X 8 columns
% binary to decimally converted value
intconv=bi2de(convert); % converted into interger values(0-255) of 4000 samples
% intconv is 4000 rows X 1 column
sample_value=minimumvalue +intconv.*interval;

% The part of Comparison display of orginal signal and retrieved signal
figure(3)
subplot(2,1,1)
plot(time(1:100),signal(1:100));
set(gca,'ytick',[ -1.0   0 1.0 ])
axis([0,time(100),-1,1])
title('Graph for a segment of recoded Audio signal')
xlabel('Time(sec)')
ylabel('Amplitude')
grid on
subplot(2,1,2)
plot(time(1:100),sample_value(1:100));
axis([0,time(100),-1,1])
set(gca,'ytick',[ -1.0   0 1.0 ])
title('Graph for a segment of retrieved Audio signal')
xlabel('Time(sec)')
ylabel('Amplitude')
grid on

%error mapping and disply
[number1,ratio]= symerr(symbol,Binary_phase_shift_keying_demodulated_data) % symbol error
[number2,ratio]= biterr(Retrieved_bit,baseband)
[number3,ratio]= biterr(convert,matrixtps)
[number4,ratio]= biterr(intconv,index)

  Home





  Home
fm=1000;
fc=50000;
time=0:7.8e-6:9e-3;
amp=.5;
ac=1;
k=amp/ac;

modwave=amp*cos(2*pi*fm*time);
figure(1);
plot(time(1:256),modwave(1:256));
title(' Waveform of modulating signal');
xlabel('Time (sec)');
ylabel('Amplitude');
grid on;

carwave=ac*cos(2*pi*fc*time);
figure(2);
plot(time(1:256),carwave(1:256));
title(' Waveform of carrier signal');
xlabel('Time (sec)');
ylabel('Amplitude');
grid on;

figure(3);
mt=k*cos(2*pi*fm*time);
sam=ac*(1+mt).*cos(2*pi*fc*time);
plot(time(1:256),sam(1:256));
title(' Waveform of modulated signal');
xlabel('Time (sec)');
ylabel('Amplitude');
grid on;